@google/adk 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/a2a/a2a_event.js +317 -0
  3. package/dist/cjs/a2a/a2a_remote_agent.js +174 -0
  4. package/dist/cjs/a2a/a2a_remote_agent_run_processor.js +198 -0
  5. package/dist/cjs/a2a/a2a_remote_agent_utils.js +165 -0
  6. package/dist/cjs/a2a/agent_card.js +380 -0
  7. package/dist/cjs/a2a/agent_executor.js +221 -0
  8. package/dist/cjs/a2a/agent_to_a2a.js +115 -0
  9. package/dist/cjs/a2a/event_converter_utils.js +201 -0
  10. package/dist/cjs/a2a/event_processor_utils.js +180 -0
  11. package/dist/cjs/a2a/executor_context.js +53 -0
  12. package/dist/cjs/a2a/metadata_converter_utils.js +126 -0
  13. package/dist/cjs/a2a/part_converter_utils.js +47 -34
  14. package/dist/cjs/agents/base_agent.js +3 -3
  15. package/dist/cjs/{tools/tool_context.js → agents/context.js} +70 -15
  16. package/dist/cjs/agents/functions.js +2 -2
  17. package/dist/cjs/agents/llm_agent.js +38 -674
  18. package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +132 -0
  19. package/dist/cjs/agents/processors/basic_llm_request_processor.js +68 -0
  20. package/dist/cjs/agents/processors/code_execution_request_processor.js +389 -0
  21. package/dist/cjs/agents/{content_processor_utils.js → processors/content_processor_utils.js} +21 -2
  22. package/dist/cjs/agents/processors/content_request_processor.js +87 -0
  23. package/dist/cjs/agents/processors/context_compactor_request_processor.js +61 -0
  24. package/dist/cjs/agents/processors/identity_llm_request_processor.js +54 -0
  25. package/dist/cjs/agents/processors/instructions_llm_request_processor.js +85 -0
  26. package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +165 -0
  27. package/dist/cjs/artifacts/file_artifact_service.js +35 -4
  28. package/dist/cjs/common.js +48 -7
  29. package/dist/cjs/context/base_context_compactor.js +27 -0
  30. package/dist/cjs/context/summarizers/base_summarizer.js +27 -0
  31. package/dist/cjs/context/summarizers/llm_summarizer.js +93 -0
  32. package/dist/cjs/context/token_based_context_compactor.js +135 -0
  33. package/dist/cjs/context/truncating_context_compactor.js +58 -0
  34. package/dist/cjs/events/compacted_event.js +53 -0
  35. package/dist/cjs/index.js +113 -53
  36. package/dist/cjs/index.js.map +7 -0
  37. package/dist/cjs/memory/in_memory_memory_service.js +1 -1
  38. package/dist/cjs/models/llm_response.js +2 -0
  39. package/dist/cjs/plugins/base_plugin.js +1 -1
  40. package/dist/cjs/runner/runner.js +20 -11
  41. package/dist/cjs/sessions/database_session_service.js +4 -1
  42. package/dist/cjs/sessions/db/operations.js +25 -23
  43. package/dist/cjs/sessions/state.js +2 -2
  44. package/dist/cjs/tools/agent_tool.js +6 -5
  45. package/dist/cjs/tools/base_tool.js +3 -0
  46. package/dist/cjs/tools/base_toolset.js +13 -3
  47. package/dist/cjs/tools/exit_loop_tool.js +63 -0
  48. package/dist/cjs/tools/load_artifacts_tool.js +188 -0
  49. package/dist/cjs/tools/load_memory_tool.js +107 -0
  50. package/dist/cjs/tools/mcp/mcp_toolset.js +9 -5
  51. package/dist/cjs/tools/preload_memory_tool.js +109 -0
  52. package/dist/cjs/utils/logger.js +62 -54
  53. package/dist/cjs/version.js +1 -1
  54. package/dist/esm/a2a/a2a_event.js +269 -0
  55. package/dist/esm/a2a/a2a_remote_agent.js +148 -0
  56. package/dist/esm/a2a/a2a_remote_agent_run_processor.js +175 -0
  57. package/dist/esm/a2a/a2a_remote_agent_utils.js +131 -0
  58. package/dist/esm/a2a/agent_card.js +340 -0
  59. package/dist/esm/a2a/agent_executor.js +202 -0
  60. package/dist/esm/a2a/agent_to_a2a.js +80 -0
  61. package/dist/esm/a2a/event_converter_utils.js +187 -0
  62. package/dist/esm/a2a/event_processor_utils.js +159 -0
  63. package/dist/esm/a2a/executor_context.js +23 -0
  64. package/dist/esm/a2a/metadata_converter_utils.js +91 -0
  65. package/dist/esm/a2a/part_converter_utils.js +49 -34
  66. package/dist/esm/agents/base_agent.js +3 -3
  67. package/dist/{web/tools/tool_context.js → esm/agents/context.js} +66 -11
  68. package/dist/esm/agents/functions.js +2 -2
  69. package/dist/esm/agents/llm_agent.js +31 -683
  70. package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +101 -0
  71. package/dist/esm/agents/processors/basic_llm_request_processor.js +37 -0
  72. package/dist/esm/agents/processors/code_execution_request_processor.js +363 -0
  73. package/dist/esm/agents/{content_processor_utils.js → processors/content_processor_utils.js} +23 -2
  74. package/dist/esm/agents/processors/content_request_processor.js +59 -0
  75. package/dist/esm/agents/processors/context_compactor_request_processor.js +31 -0
  76. package/dist/esm/agents/processors/identity_llm_request_processor.js +23 -0
  77. package/dist/esm/agents/processors/instructions_llm_request_processor.js +54 -0
  78. package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +140 -0
  79. package/dist/esm/artifacts/file_artifact_service.js +30 -3
  80. package/dist/esm/common.js +44 -10
  81. package/dist/esm/context/base_context_compactor.js +5 -0
  82. package/dist/esm/context/summarizers/base_summarizer.js +5 -0
  83. package/dist/esm/context/summarizers/llm_summarizer.js +65 -0
  84. package/dist/esm/context/token_based_context_compactor.js +105 -0
  85. package/dist/esm/context/truncating_context_compactor.js +28 -0
  86. package/dist/esm/events/compacted_event.js +22 -0
  87. package/dist/esm/index.js +119 -18
  88. package/dist/esm/index.js.map +7 -0
  89. package/dist/esm/memory/in_memory_memory_service.js +1 -1
  90. package/dist/esm/models/llm_response.js +2 -0
  91. package/dist/esm/plugins/base_plugin.js +1 -1
  92. package/dist/esm/runner/runner.js +18 -10
  93. package/dist/esm/sessions/database_session_service.js +4 -1
  94. package/dist/esm/sessions/db/operations.js +32 -18
  95. package/dist/esm/sessions/state.js +2 -2
  96. package/dist/esm/tools/agent_tool.js +6 -5
  97. package/dist/esm/tools/base_tool.js +3 -0
  98. package/dist/esm/tools/base_toolset.js +11 -2
  99. package/dist/esm/tools/exit_loop_tool.js +32 -0
  100. package/dist/esm/tools/load_artifacts_tool.js +159 -0
  101. package/dist/esm/tools/load_memory_tool.js +78 -0
  102. package/dist/esm/tools/mcp/mcp_toolset.js +9 -5
  103. package/dist/esm/tools/preload_memory_tool.js +80 -0
  104. package/dist/esm/utils/logger.js +52 -54
  105. package/dist/esm/version.js +1 -1
  106. package/dist/types/a2a/a2a_event.d.ts +139 -0
  107. package/dist/types/a2a/a2a_remote_agent.d.ts +63 -0
  108. package/dist/types/a2a/a2a_remote_agent_run_processor.d.ts +31 -0
  109. package/dist/types/a2a/a2a_remote_agent_utils.d.ts +38 -0
  110. package/dist/types/a2a/agent_card.d.ts +23 -0
  111. package/dist/types/a2a/agent_executor.d.ts +52 -0
  112. package/dist/types/a2a/agent_to_a2a.d.ts +45 -0
  113. package/dist/types/a2a/event_converter_utils.d.ts +20 -0
  114. package/dist/types/a2a/event_processor_utils.d.ts +24 -0
  115. package/dist/types/a2a/executor_context.d.ts +33 -0
  116. package/dist/types/a2a/metadata_converter_utils.d.ts +63 -0
  117. package/dist/types/a2a/part_converter_utils.d.ts +4 -3
  118. package/dist/types/agents/base_agent.d.ts +2 -2
  119. package/dist/types/{tools/tool_context.d.ts → agents/context.d.ts} +43 -8
  120. package/dist/types/agents/llm_agent.d.ts +14 -31
  121. package/dist/types/agents/loop_agent.d.ts +1 -1
  122. package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +18 -0
  123. package/dist/types/agents/{base_llm_processor.d.ts → processors/base_llm_processor.d.ts} +4 -4
  124. package/dist/types/agents/processors/basic_llm_request_processor.d.ts +13 -0
  125. package/dist/types/agents/processors/code_execution_request_processor.d.ts +34 -0
  126. package/dist/types/agents/{content_processor_utils.d.ts → processors/content_processor_utils.d.ts} +1 -1
  127. package/dist/types/agents/processors/content_request_processor.d.ts +13 -0
  128. package/dist/types/agents/processors/context_compactor_request_processor.d.ts +22 -0
  129. package/dist/types/agents/processors/identity_llm_request_processor.d.ts +13 -0
  130. package/dist/types/agents/processors/instructions_llm_request_processor.d.ts +16 -0
  131. package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +13 -0
  132. package/dist/types/artifacts/file_artifact_service.d.ts +4 -0
  133. package/dist/types/auth/credential_service/base_credential_service.d.ts +3 -3
  134. package/dist/types/auth/credential_service/in_memory_credential_service.d.ts +3 -3
  135. package/dist/types/common.d.ts +20 -5
  136. package/dist/types/context/base_context_compactor.d.ts +24 -0
  137. package/dist/types/context/summarizers/base_summarizer.d.ts +19 -0
  138. package/dist/types/context/summarizers/llm_summarizer.d.ts +23 -0
  139. package/dist/types/context/token_based_context_compactor.d.ts +33 -0
  140. package/dist/types/context/truncating_context_compactor.d.ts +24 -0
  141. package/dist/types/events/compacted_event.d.ts +33 -0
  142. package/dist/types/index.d.ts +8 -0
  143. package/dist/types/models/llm_response.d.ts +5 -1
  144. package/dist/types/plugins/base_plugin.d.ts +12 -13
  145. package/dist/types/plugins/logging_plugin.d.ts +9 -10
  146. package/dist/types/plugins/plugin_manager.d.ts +9 -10
  147. package/dist/types/plugins/security_plugin.d.ts +2 -2
  148. package/dist/types/runner/runner.d.ts +13 -0
  149. package/dist/types/sessions/database_session_service.d.ts +2 -1
  150. package/dist/types/sessions/db/operations.d.ts +3 -4
  151. package/dist/types/tools/base_tool.d.ts +3 -3
  152. package/dist/types/tools/base_toolset.d.ts +12 -3
  153. package/dist/types/tools/exit_loop_tool.d.ts +24 -0
  154. package/dist/types/tools/forwarding_artifact_service.d.ts +2 -2
  155. package/dist/types/tools/function_tool.d.ts +2 -2
  156. package/dist/types/tools/load_artifacts_tool.d.ts +21 -0
  157. package/dist/types/tools/load_memory_tool.d.ts +22 -0
  158. package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -1
  159. package/dist/types/tools/preload_memory_tool.d.ts +23 -0
  160. package/dist/types/utils/logger.d.ts +5 -9
  161. package/dist/types/version.d.ts +1 -1
  162. package/dist/web/a2a/a2a_event.js +269 -0
  163. package/dist/web/a2a/a2a_remote_agent.js +193 -0
  164. package/dist/web/a2a/a2a_remote_agent_run_processor.js +175 -0
  165. package/dist/web/a2a/a2a_remote_agent_utils.js +131 -0
  166. package/dist/web/a2a/agent_card.js +340 -0
  167. package/dist/web/a2a/agent_executor.js +216 -0
  168. package/dist/web/a2a/agent_to_a2a.js +80 -0
  169. package/dist/web/a2a/event_converter_utils.js +201 -0
  170. package/dist/web/a2a/event_processor_utils.js +168 -0
  171. package/dist/web/a2a/executor_context.js +23 -0
  172. package/dist/web/a2a/metadata_converter_utils.js +108 -0
  173. package/dist/web/a2a/part_converter_utils.js +49 -34
  174. package/dist/web/agents/base_agent.js +3 -3
  175. package/dist/{esm/tools/tool_context.js → web/agents/context.js} +66 -11
  176. package/dist/web/agents/functions.js +2 -2
  177. package/dist/web/agents/llm_agent.js +31 -661
  178. package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +100 -0
  179. package/dist/web/agents/processors/basic_llm_request_processor.js +71 -0
  180. package/dist/web/agents/processors/code_execution_request_processor.js +365 -0
  181. package/dist/web/agents/{content_processor_utils.js → processors/content_processor_utils.js} +22 -2
  182. package/dist/web/agents/processors/content_request_processor.js +77 -0
  183. package/dist/web/agents/processors/context_compactor_request_processor.js +49 -0
  184. package/dist/web/agents/processors/identity_llm_request_processor.js +41 -0
  185. package/dist/web/agents/processors/instructions_llm_request_processor.js +72 -0
  186. package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +158 -0
  187. package/dist/web/artifacts/file_artifact_service.js +30 -3
  188. package/dist/web/common.js +44 -10
  189. package/dist/web/context/base_context_compactor.js +5 -0
  190. package/dist/web/context/summarizers/base_summarizer.js +5 -0
  191. package/dist/web/context/summarizers/llm_summarizer.js +74 -0
  192. package/dist/web/context/token_based_context_compactor.js +105 -0
  193. package/dist/web/context/truncating_context_compactor.js +28 -0
  194. package/dist/web/events/compacted_event.js +40 -0
  195. package/dist/web/index.js +13 -18
  196. package/dist/web/index.js.map +7 -0
  197. package/dist/web/memory/in_memory_memory_service.js +1 -1
  198. package/dist/web/models/llm_response.js +2 -0
  199. package/dist/web/plugins/base_plugin.js +1 -1
  200. package/dist/web/runner/runner.js +18 -10
  201. package/dist/web/sessions/database_session_service.js +4 -1
  202. package/dist/web/sessions/db/operations.js +32 -18
  203. package/dist/web/sessions/state.js +2 -2
  204. package/dist/web/tools/agent_tool.js +6 -5
  205. package/dist/web/tools/base_tool.js +3 -0
  206. package/dist/web/tools/base_toolset.js +11 -2
  207. package/dist/web/tools/exit_loop_tool.js +32 -0
  208. package/dist/web/tools/load_artifacts_tool.js +150 -0
  209. package/dist/web/tools/load_memory_tool.js +77 -0
  210. package/dist/web/tools/mcp/mcp_toolset.js +27 -5
  211. package/dist/web/tools/preload_memory_tool.js +75 -0
  212. package/dist/web/utils/logger.js +52 -54
  213. package/dist/web/version.js +1 -1
  214. package/package.json +7 -4
  215. package/dist/cjs/agents/callback_context.js +0 -101
  216. package/dist/esm/agents/callback_context.js +0 -71
  217. package/dist/types/agents/callback_context.d.ts +0 -42
  218. package/dist/web/agents/callback_context.js +0 -71
  219. /package/dist/cjs/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
  220. /package/dist/esm/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
  221. /package/dist/web/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
@@ -58,7 +58,7 @@ function getUserKey(appName, userId) {
58
58
  }
59
59
  function extractWordsLower(text) {
60
60
  return new Set(
61
- [...text.matchAll(/[A-Za-z]+/)].map((match) => match[0].toLowerCase())
61
+ [...text.matchAll(/[A-Za-z]+/g)].map((match) => match[0].toLowerCase())
62
62
  );
63
63
  }
64
64
  function formatTimestamp(timestamp) {
@@ -12,6 +12,7 @@ function createLlmResponse(response) {
12
12
  return {
13
13
  content: candidate.content,
14
14
  groundingMetadata: candidate.groundingMetadata,
15
+ citationMetadata: candidate.citationMetadata,
15
16
  usageMetadata,
16
17
  finishReason: candidate.finishReason
17
18
  };
@@ -20,6 +21,7 @@ function createLlmResponse(response) {
20
21
  errorCode: candidate.finishReason,
21
22
  errorMessage: candidate.finishMessage,
22
23
  usageMetadata,
24
+ citationMetadata: candidate.citationMetadata,
23
25
  finishReason: candidate.finishReason
24
26
  };
25
27
  }
@@ -198,7 +198,7 @@ class BasePlugin {
198
198
  * Callback executed when a tool call encounters an error.
199
199
  tool: BaseTool;
200
200
  toolArgs: Record<string, unknown>;
201
- toolContext: ToolContext;
201
+ toolContext: Context;
202
202
  result: Record<string, unknown>;
203
203
  }): Promise<Record<string, unknown> | undefined> {
204
204
  return;
@@ -51,6 +51,7 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
51
51
  * Copyright 2025 Google LLC
52
52
  * SPDX-License-Identifier: Apache-2.0
53
53
  */
54
+ var _a;
54
55
  import { createPartFromText } from "@google/genai";
55
56
  import { context, trace } from "@opentelemetry/api";
56
57
  import {
@@ -72,12 +73,18 @@ import {
72
73
  } from "../telemetry/tracing.js";
73
74
  import { logger } from "../utils/logger.js";
74
75
  import { isGemini2OrAbove } from "../utils/model_name.js";
76
+ const RUNNER_SIGNATURE_SYMBOL = Symbol.for("google.adk.runner");
77
+ function isRunner(obj) {
78
+ return typeof obj === "object" && obj !== null && RUNNER_SIGNATURE_SYMBOL in obj && obj[RUNNER_SIGNATURE_SYMBOL] === true;
79
+ }
80
+ _a = RUNNER_SIGNATURE_SYMBOL;
75
81
  class Runner {
76
82
  constructor(input) {
77
- var _a;
83
+ this[_a] = true;
84
+ var _a2;
78
85
  this.appName = input.appName;
79
86
  this.agent = input.agent;
80
- this.pluginManager = new PluginManager((_a = input.plugins) != null ? _a : []);
87
+ this.pluginManager = new PluginManager((_a2 = input.plugins) != null ? _a2 : []);
81
88
  this.artifactService = input.artifactService;
82
89
  this.sessionService = input.sessionService;
83
90
  this.memoryService = input.memoryService;
@@ -141,7 +148,7 @@ class Runner {
141
148
  this,
142
149
  function() {
143
150
  return __asyncGenerator(this, null, function* () {
144
- var _a;
151
+ var _a2;
145
152
  const session = yield new __await(this.sessionService.getSession({
146
153
  appName: this.appName,
147
154
  userId,
@@ -186,7 +193,7 @@ class Runner {
186
193
  newMessage = pluginUserMessage;
187
194
  }
188
195
  if (newMessage) {
189
- if (!((_a = newMessage.parts) == null ? void 0 : _a.length)) {
196
+ if (!((_a2 = newMessage.parts) == null ? void 0 : _a2.length)) {
190
197
  throw new Error("No parts in the newMessage.");
191
198
  }
192
199
  if (runConfig.saveInputBlobsAsArtifacts) {
@@ -276,8 +283,8 @@ class Runner {
276
283
  * @param message The message containing parts to process.
277
284
  */
278
285
  async saveArtifacts(invocationId, userId, sessionId, message) {
279
- var _a;
280
- if (!this.artifactService || !((_a = message.parts) == null ? void 0 : _a.length)) {
286
+ var _a2;
287
+ if (!this.artifactService || !((_a2 = message.parts) == null ? void 0 : _a2.length)) {
281
288
  return;
282
289
  }
283
290
  for (let i = 0; i < message.parts.length; i++) {
@@ -310,7 +317,7 @@ class Runner {
310
317
  return rootAgent.findAgent(event.author) || rootAgent;
311
318
  }
312
319
  for (let i = session.events.length - 1; i >= 0; i--) {
313
- logger.info("event: ", JSON.stringify(session.events[i]));
320
+ logger.info("event:", JSON.stringify(session.events[i]));
314
321
  const event2 = session.events[i];
315
322
  if (event2.author === "user" || !event2.author) {
316
323
  continue;
@@ -358,12 +365,12 @@ class Runner {
358
365
  // TODO - b/425992518: Implement runLive and related methods.
359
366
  }
360
367
  function findEventByLastFunctionResponseId(events) {
361
- var _a, _b, _c, _d;
368
+ var _a2, _b, _c, _d;
362
369
  if (!events.length) {
363
370
  return null;
364
371
  }
365
372
  const lastEvent = events[events.length - 1];
366
- const functionCallId = (_d = (_c = (_b = (_a = lastEvent.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.find(
373
+ const functionCallId = (_d = (_c = (_b = (_a2 = lastEvent.content) == null ? void 0 : _a2.parts) == null ? void 0 : _b.find(
367
374
  (part) => part.functionResponse
368
375
  )) == null ? void 0 : _c.functionResponse) == null ? void 0 : _d.id;
369
376
  if (!functionCallId) {
@@ -384,5 +391,6 @@ function findEventByLastFunctionResponseId(events) {
384
391
  return null;
385
392
  }
386
393
  export {
387
- Runner
394
+ Runner,
395
+ isRunner
388
396
  };
@@ -57,7 +57,7 @@ class DatabaseSessionService extends BaseSessionService {
57
57
  super();
58
58
  this.initialized = false;
59
59
  if (typeof connectionStringOrOptions === "string") {
60
- this.options = getConnectionOptionsFromUri(connectionStringOrOptions);
60
+ this.connectionString = connectionStringOrOptions;
61
61
  } else {
62
62
  if (!connectionStringOrOptions.driver) {
63
63
  throw new Error("Driver is required when passing options object.");
@@ -71,6 +71,9 @@ class DatabaseSessionService extends BaseSessionService {
71
71
  if (this.initialized) {
72
72
  return;
73
73
  }
74
+ if (this.connectionString && (!this.options || !this.options.driver)) {
75
+ this.options = await getConnectionOptionsFromUri(this.connectionString);
76
+ }
74
77
  this.orm = await MikroORM.init(this.options);
75
78
  await ensureDatabaseCreated(this.orm);
76
79
  await validateDatabaseSchemaVersion(this.orm);
@@ -1,31 +1,52 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from === "object" || typeof from === "function") {
9
+ for (let key of __getOwnPropNames(from))
10
+ if (!__hasOwnProp.call(to, key) && key !== except)
11
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ }
13
+ return to;
14
+ };
15
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
+ // If the importer is in node compatibility mode or this is not an ESM
17
+ // file that has been converted to a CommonJS file using a Babel-
18
+ // compatible transform (i.e. "__esModule" has not been set), then set
19
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
1
23
  /**
2
24
  * @license
3
25
  * Copyright 2026 Google LLC
4
26
  * SPDX-License-Identifier: Apache-2.0
5
27
  */
6
- import { MikroORM } from "@mikro-orm/core";
7
- import { MariaDbDriver } from "@mikro-orm/mariadb";
8
- import { MsSqlDriver } from "@mikro-orm/mssql";
9
- import { MySqlDriver } from "@mikro-orm/mysql";
10
- import { PostgreSqlDriver } from "@mikro-orm/postgresql";
11
- import { SqliteDriver } from "@mikro-orm/sqlite";
12
28
  import {
13
29
  ENTITIES,
14
30
  SCHEMA_VERSION_1_JSON,
15
31
  SCHEMA_VERSION_KEY,
16
32
  StorageMetadata
17
33
  } from "./schema.js";
18
- function getConnectionOptionsFromUri(uri) {
34
+ async function getConnectionOptionsFromUri(uri) {
19
35
  let driver;
20
36
  if (uri.startsWith("postgres://") || uri.startsWith("postgresql://")) {
37
+ const { PostgreSqlDriver } = await Promise.resolve().then(() => __toESM(require("@mikro-orm/postgresql"), 1));
21
38
  driver = PostgreSqlDriver;
22
39
  } else if (uri.startsWith("mysql://")) {
40
+ const { MySqlDriver } = await Promise.resolve().then(() => __toESM(require("@mikro-orm/mysql"), 1));
23
41
  driver = MySqlDriver;
24
42
  } else if (uri.startsWith("mariadb://")) {
43
+ const { MariaDbDriver } = await Promise.resolve().then(() => __toESM(require("@mikro-orm/mariadb"), 1));
25
44
  driver = MariaDbDriver;
26
45
  } else if (uri.startsWith("sqlite://")) {
46
+ const { SqliteDriver } = await Promise.resolve().then(() => __toESM(require("@mikro-orm/sqlite"), 1));
27
47
  driver = SqliteDriver;
28
48
  } else if (uri.startsWith("mssql://")) {
49
+ const { MsSqlDriver } = await Promise.resolve().then(() => __toESM(require("@mikro-orm/mssql"), 1));
29
50
  driver = MsSqlDriver;
30
51
  } else {
31
52
  throw new Error("Unsupported database URI: ".concat(uri));
@@ -39,9 +60,10 @@ function getConnectionOptionsFromUri(uri) {
39
60
  }
40
61
  const { host, port, username, password, pathname } = new URL(uri);
41
62
  const hostName = host.split(":")[0];
63
+ const dbName = uri.startsWith("sqlite://") ? uri.substring("sqlite://".length) : pathname.slice(1);
42
64
  return {
43
65
  entities: ENTITIES,
44
- dbName: pathname.slice(1),
66
+ dbName,
45
67
  host: hostName,
46
68
  port: port ? parseInt(port) : void 0,
47
69
  user: username,
@@ -49,17 +71,9 @@ function getConnectionOptionsFromUri(uri) {
49
71
  driver
50
72
  };
51
73
  }
52
- async function ensureDatabaseCreated(ormOrUrlOrOptions) {
53
- let orm;
54
- if (ormOrUrlOrOptions instanceof MikroORM) {
55
- orm = ormOrUrlOrOptions;
56
- } else if (typeof ormOrUrlOrOptions === "string") {
57
- orm = await MikroORM.init(getConnectionOptionsFromUri(ormOrUrlOrOptions));
58
- } else {
59
- orm = await MikroORM.init(ormOrUrlOrOptions);
60
- }
74
+ async function ensureDatabaseCreated(orm) {
61
75
  await orm.schema.ensureDatabase();
62
- await orm.schema.updateSchema();
76
+ await orm.schema.updateSchema({ safe: true });
63
77
  }
64
78
  async function validateDatabaseSchemaVersion(orm) {
65
79
  const em = orm.em.fork();
@@ -69,8 +69,8 @@ class State {
69
69
  * @param delta The delta to update the state with.
70
70
  */
71
71
  update(delta) {
72
- this.delta = __spreadValues(__spreadValues({}, this.delta), delta);
73
- this.value = __spreadValues(__spreadValues({}, this.value), delta);
72
+ Object.assign(this.delta, delta);
73
+ Object.assign(this.value, delta);
74
74
  }
75
75
  /**
76
76
  * Returns the state as a plain JSON object.
@@ -65,7 +65,7 @@ class AgentTool extends (_b = BaseTool, _a = AGENT_TOOL_SIGNATURE_SYMBOL, _b) {
65
65
  args,
66
66
  toolContext
67
67
  }) {
68
- var _a2, _b2;
68
+ var _a2, _b2, _c, _d;
69
69
  if (this.skipSummarization) {
70
70
  toolContext.actions.skipSummarization = true;
71
71
  }
@@ -84,13 +84,14 @@ class AgentTool extends (_b = BaseTool, _a = AGENT_TOOL_SIGNATURE_SYMBOL, _b) {
84
84
  appName: this.agent.name,
85
85
  agent: this.agent,
86
86
  artifactService: new ForwardingArtifactService(toolContext),
87
- sessionService: new InMemorySessionService(),
88
- memoryService: new InMemoryMemoryService(),
87
+ sessionService: (_a2 = toolContext.invocationContext.sessionService) != null ? _a2 : new InMemorySessionService(),
88
+ memoryService: (_b2 = toolContext.invocationContext.memoryService) != null ? _b2 : new InMemoryMemoryService(),
89
89
  credentialService: toolContext.invocationContext.credentialService
90
90
  });
91
91
  const session = await runner.sessionService.createSession({
92
92
  appName: this.agent.name,
93
- userId: "tmp_user",
93
+ userId: toolContext.invocationContext.userId,
94
+ sessionId: toolContext.invocationContext.session.id,
94
95
  state: toolContext.state.toRecord()
95
96
  });
96
97
  let lastEvent;
@@ -116,7 +117,7 @@ class AgentTool extends (_b = BaseTool, _a = AGENT_TOOL_SIGNATURE_SYMBOL, _b) {
116
117
  throw error[0];
117
118
  }
118
119
  }
119
- if (!((_b2 = (_a2 = lastEvent == null ? void 0 : lastEvent.content) == null ? void 0 : _a2.parts) == null ? void 0 : _b2.length)) {
120
+ if (!((_d = (_c = lastEvent == null ? void 0 : lastEvent.content) == null ? void 0 : _c.parts) == null ? void 0 : _d.length)) {
120
121
  return "";
121
122
  }
122
123
  const hasOutputSchema = isLlmAgent(this.agent) && this.agent.outputSchema;
@@ -54,6 +54,9 @@ class BaseTool {
54
54
  if (!functionDeclaration) {
55
55
  return;
56
56
  }
57
+ if (this.name in llmRequest.toolsDict) {
58
+ throw new Error("Duplicate tool name: ".concat(this.name));
59
+ }
57
60
  llmRequest.toolsDict[this.name] = this;
58
61
  const tool = findToolWithFunctionDeclarations(llmRequest);
59
62
  if (tool) {
@@ -3,9 +3,17 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ var _a;
7
+ const BASE_TOOLSET_SIGNATURE_SYMBOL = Symbol.for("google.adk.baseToolset");
8
+ function isBaseToolset(obj) {
9
+ return typeof obj === "object" && obj !== null && BASE_TOOLSET_SIGNATURE_SYMBOL in obj && obj[BASE_TOOLSET_SIGNATURE_SYMBOL] === true;
10
+ }
11
+ _a = BASE_TOOLSET_SIGNATURE_SYMBOL;
6
12
  class BaseToolset {
7
- constructor(toolFilter) {
13
+ constructor(toolFilter, prefix) {
8
14
  this.toolFilter = toolFilter;
15
+ this.prefix = prefix;
16
+ this[_a] = true;
9
17
  }
10
18
  /**
11
19
  * Returns whether the tool should be exposed to LLM.
@@ -42,5 +50,6 @@ class BaseToolset {
42
50
  }
43
51
  }
44
52
  export {
45
- BaseToolset
53
+ BaseToolset,
54
+ isBaseToolset
46
55
  };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { BaseTool } from "./base_tool.js";
7
+ class ExitLoopTool extends BaseTool {
8
+ constructor() {
9
+ super({
10
+ name: "exit_loop",
11
+ description: "Exits the loop.\n\nCall this function only when you are instructed to do so."
12
+ });
13
+ }
14
+ _getDeclaration() {
15
+ return {
16
+ name: this.name,
17
+ description: this.description
18
+ };
19
+ }
20
+ async runAsync({
21
+ toolContext
22
+ }) {
23
+ toolContext.actions.escalate = true;
24
+ toolContext.actions.skipSummarization = true;
25
+ return "";
26
+ }
27
+ }
28
+ const EXIT_LOOP = new ExitLoopTool();
29
+ export {
30
+ EXIT_LOOP,
31
+ ExitLoopTool
32
+ };
@@ -0,0 +1,150 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Type } from "@google/genai";
7
+ import { appendInstructions } from "../models/llm_request.js";
8
+ import { getLogger } from "../utils/logger.js";
9
+ import {
10
+ BaseTool
11
+ } from "./base_tool.js";
12
+ const logger = getLogger();
13
+ const GEMINI_SUPPORTED_INLINE_MIME_PREFIXES = ["image/", "audio/", "video/"];
14
+ const GEMINI_SUPPORTED_INLINE_MIME_TYPES = /* @__PURE__ */ new Set(["application/pdf"]);
15
+ const TEXT_LIKE_MIME_TYPES = /* @__PURE__ */ new Set([
16
+ "application/csv",
17
+ "application/json",
18
+ "application/xml"
19
+ ]);
20
+ function normalizeMimeType(mimeType) {
21
+ if (!mimeType) {
22
+ return void 0;
23
+ }
24
+ return mimeType.split(";")[0].trim();
25
+ }
26
+ function isInlineMimeTypeSupported(mimeType) {
27
+ const normalized = normalizeMimeType(mimeType);
28
+ if (!normalized) {
29
+ return false;
30
+ }
31
+ return GEMINI_SUPPORTED_INLINE_MIME_PREFIXES.some(
32
+ (prefix) => normalized.startsWith(prefix)
33
+ ) || GEMINI_SUPPORTED_INLINE_MIME_TYPES.has(normalized);
34
+ }
35
+ function asSafePartForLlm(artifact, artifactName) {
36
+ const inlineData = artifact.inlineData;
37
+ if (!inlineData) {
38
+ return artifact;
39
+ }
40
+ if (isInlineMimeTypeSupported(inlineData.mimeType)) {
41
+ return artifact;
42
+ }
43
+ const mimeType = normalizeMimeType(inlineData.mimeType) || "application/octet-stream";
44
+ const data = inlineData.data;
45
+ if (!data) {
46
+ return {
47
+ text: "[Artifact: ".concat(artifactName, ", type: ").concat(mimeType, ". No inline data was provided.]")
48
+ };
49
+ }
50
+ const isTextLike = mimeType.startsWith("text/") || TEXT_LIKE_MIME_TYPES.has(mimeType);
51
+ const decodedBuffer = Buffer.from(data, "base64");
52
+ if (isTextLike) {
53
+ try {
54
+ const decoded = decodedBuffer.toString("utf8");
55
+ return { text: decoded };
56
+ } catch (e) {
57
+ }
58
+ }
59
+ const sizeKb = decodedBuffer.length / 1024;
60
+ return {
61
+ text: "[Binary artifact: ".concat(artifactName, ", type: ").concat(mimeType, ", size: ").concat(sizeKb.toFixed(1), " KB. Content cannot be displayed inline.]")
62
+ };
63
+ }
64
+ class LoadArtifactsTool extends BaseTool {
65
+ constructor() {
66
+ super({
67
+ name: "load_artifacts",
68
+ description: "Loads artifacts into the session for this request.\n\nNOTE: Call when you need access to artifacts (for example, uploads saved by the web UI)."
69
+ });
70
+ }
71
+ _getDeclaration() {
72
+ return {
73
+ name: this.name,
74
+ description: this.description,
75
+ parameters: {
76
+ type: Type.OBJECT,
77
+ properties: {
78
+ artifact_names: {
79
+ type: Type.ARRAY,
80
+ items: {
81
+ type: Type.STRING
82
+ },
83
+ description: "The names of the artifacts to load."
84
+ }
85
+ }
86
+ }
87
+ };
88
+ }
89
+ async runAsync({ args }) {
90
+ const artifactNames = args["artifact_names"] || [];
91
+ return {
92
+ artifact_names: artifactNames,
93
+ status: "artifact contents temporarily inserted and removed. to access these artifacts, call load_artifacts tool again."
94
+ };
95
+ }
96
+ async processLlmRequest(request) {
97
+ await super.processLlmRequest(request);
98
+ await this.appendArtifactsToLlmRequest(
99
+ request.toolContext,
100
+ request.llmRequest
101
+ );
102
+ }
103
+ async appendArtifactsToLlmRequest(toolContext, llmRequest) {
104
+ if (!toolContext.invocationContext.artifactService) {
105
+ return;
106
+ }
107
+ const artifactNames = await toolContext.listArtifacts();
108
+ if (!artifactNames || artifactNames.length === 0) {
109
+ return;
110
+ }
111
+ appendInstructions(llmRequest, [
112
+ "You have a list of artifacts:\n ".concat(JSON.stringify(
113
+ artifactNames
114
+ ), "\n\n When the user asks questions about any of the artifacts, you should call the\n `load_artifacts` function to load the artifact. Always call load_artifacts\n before answering questions related to the artifacts, regardless of whether the\n artifacts have been loaded before. Do not depend on prior answers about the\n artifacts.")
115
+ ]);
116
+ const contents = llmRequest.contents;
117
+ if (contents && contents.length > 0) {
118
+ const lastContent = contents[contents.length - 1];
119
+ if (lastContent.role === "user" && lastContent.parts && lastContent.parts.length > 0) {
120
+ const functionResponsePart = lastContent.parts[0];
121
+ const functionResponse = functionResponsePart.functionResponse;
122
+ if (functionResponse && functionResponse.name === "load_artifacts") {
123
+ const response = functionResponse.response || {};
124
+ const namesToLoad = response["artifact_names"] || [];
125
+ for (const artifactName of namesToLoad) {
126
+ let artifact = await toolContext.loadArtifact(artifactName);
127
+ if (!artifact && !artifactName.startsWith("user:")) {
128
+ const prefixedName = "user:".concat(artifactName);
129
+ artifact = await toolContext.loadArtifact(prefixedName);
130
+ }
131
+ if (!artifact) {
132
+ logger.warn('Artifact "'.concat(artifactName, '" not found, skipping'));
133
+ continue;
134
+ }
135
+ const artifactPart = asSafePartForLlm(artifact, artifactName);
136
+ llmRequest.contents.push({
137
+ role: "user",
138
+ parts: [{ text: "Artifact ".concat(artifactName, " is:") }, artifactPart]
139
+ });
140
+ }
141
+ }
142
+ }
143
+ }
144
+ }
145
+ }
146
+ const LOAD_ARTIFACTS = new LoadArtifactsTool();
147
+ export {
148
+ LOAD_ARTIFACTS,
149
+ LoadArtifactsTool
150
+ };
@@ -0,0 +1,77 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Type } from "@google/genai";
7
+ import { appendInstructions } from "../models/llm_request.js";
8
+ import {
9
+ BaseTool
10
+ } from "./base_tool.js";
11
+ class LoadMemoryTool extends BaseTool {
12
+ constructor() {
13
+ super({
14
+ name: "load_memory",
15
+ description: "Loads the memory for the current user.\n\nNOTE: Currently this tool only uses text part from the memory."
16
+ });
17
+ }
18
+ _getDeclaration() {
19
+ return {
20
+ name: this.name,
21
+ description: this.description,
22
+ parameters: {
23
+ type: Type.OBJECT,
24
+ properties: {
25
+ query: {
26
+ type: Type.STRING,
27
+ description: "The query to load the memory for."
28
+ }
29
+ },
30
+ required: ["query"]
31
+ }
32
+ };
33
+ }
34
+ async runAsync({
35
+ args,
36
+ toolContext
37
+ }) {
38
+ try {
39
+ const query = args["query"];
40
+ if (!toolContext.invocationContext.memoryService) {
41
+ throw new Error("Memory service is not initialized.");
42
+ }
43
+ const searchMemoryResponse = await toolContext.searchMemory(query);
44
+ return {
45
+ memories: searchMemoryResponse.memories.map((m) => {
46
+ var _a, _b;
47
+ return {
48
+ // Join all text parts by a space, or empty string if no text parts
49
+ content: (_b = (_a = m.content.parts) == null ? void 0 : _a.map((p) => {
50
+ var _a2;
51
+ return (_a2 = p.text) != null ? _a2 : "";
52
+ }).join(" ")) != null ? _b : "",
53
+ author: m.author,
54
+ timestamp: m.timestamp
55
+ };
56
+ })
57
+ };
58
+ } catch (e) {
59
+ console.error("ERROR in LoadMemoryTool runAsync:", e);
60
+ throw e;
61
+ }
62
+ }
63
+ async processLlmRequest(request) {
64
+ await super.processLlmRequest(request);
65
+ if (!request.toolContext.invocationContext.memoryService) {
66
+ return;
67
+ }
68
+ appendInstructions(request.llmRequest, [
69
+ "You have memory. You can use it to answer questions. If any questions need\nyou to look up the memory, you should call load_memory function with a query."
70
+ ]);
71
+ }
72
+ }
73
+ const LOAD_MEMORY = new LoadMemoryTool();
74
+ export {
75
+ LOAD_MEMORY,
76
+ LoadMemoryTool
77
+ };
@@ -1,3 +1,22 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
1
20
  /**
2
21
  * @license
3
22
  * Copyright 2025 Google LLC
@@ -8,8 +27,8 @@ import { BaseToolset } from "../base_toolset.js";
8
27
  import { MCPSessionManager } from "./mcp_session_manager.js";
9
28
  import { MCPTool } from "./mcp_tool.js";
10
29
  class MCPToolset extends BaseToolset {
11
- constructor(connectionParams, toolFilter = []) {
12
- super(toolFilter);
30
+ constructor(connectionParams, toolFilter = [], prefix) {
31
+ super(toolFilter, prefix);
13
32
  this.mcpSessionManager = new MCPSessionManager(connectionParams);
14
33
  }
15
34
  async getTools() {
@@ -19,9 +38,12 @@ class MCPToolset extends BaseToolset {
19
38
  for (const tool of listResult.tools) {
20
39
  logger.debug("tool: ".concat(tool.name));
21
40
  }
22
- return listResult.tools.map(
23
- (tool) => new MCPTool(tool, this.mcpSessionManager)
24
- );
41
+ return listResult.tools.map((tool) => {
42
+ const toolWithPrefix = __spreadProps(__spreadValues({}, tool), {
43
+ name: this.prefix ? "".concat(this.prefix, "_").concat(tool.name) : tool.name
44
+ });
45
+ return new MCPTool(toolWithPrefix, this.mcpSessionManager);
46
+ });
25
47
  }
26
48
  async close() {
27
49
  }