@google/adk 0.5.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 (139) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/a2a/a2a_event.js +53 -26
  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_processor_utils.js +180 -0
  10. package/dist/cjs/a2a/executor_context.js +1 -1
  11. package/dist/cjs/a2a/metadata_converter_utils.js +1 -0
  12. package/dist/cjs/a2a/part_converter_utils.js +24 -13
  13. package/dist/cjs/agents/llm_agent.js +17 -0
  14. package/dist/cjs/agents/{content_processor_utils.js → processors/content_processor_utils.js} +21 -2
  15. package/dist/cjs/agents/processors/content_request_processor.js +24 -3
  16. package/dist/cjs/agents/processors/context_compactor_request_processor.js +61 -0
  17. package/dist/cjs/agents/processors/instructions_llm_request_processor.js +1 -1
  18. package/dist/cjs/artifacts/file_artifact_service.js +35 -4
  19. package/dist/cjs/common.js +37 -0
  20. package/dist/cjs/context/base_context_compactor.js +27 -0
  21. package/dist/cjs/context/summarizers/base_summarizer.js +27 -0
  22. package/dist/cjs/context/summarizers/llm_summarizer.js +93 -0
  23. package/dist/cjs/context/token_based_context_compactor.js +135 -0
  24. package/dist/cjs/context/truncating_context_compactor.js +58 -0
  25. package/dist/cjs/events/compacted_event.js +53 -0
  26. package/dist/cjs/index.js +38 -14
  27. package/dist/cjs/index.js.map +4 -4
  28. package/dist/cjs/memory/in_memory_memory_service.js +1 -1
  29. package/dist/cjs/runner/runner.js +19 -10
  30. package/dist/cjs/sessions/db/operations.js +4 -14
  31. package/dist/cjs/sessions/state.js +2 -2
  32. package/dist/cjs/tools/agent_tool.js +6 -5
  33. package/dist/cjs/tools/load_artifacts_tool.js +188 -0
  34. package/dist/cjs/tools/load_memory_tool.js +107 -0
  35. package/dist/cjs/tools/preload_memory_tool.js +109 -0
  36. package/dist/cjs/utils/logger.js +1 -0
  37. package/dist/cjs/version.js +1 -1
  38. package/dist/esm/a2a/a2a_event.js +52 -26
  39. package/dist/esm/a2a/a2a_remote_agent.js +148 -0
  40. package/dist/esm/a2a/a2a_remote_agent_run_processor.js +175 -0
  41. package/dist/esm/a2a/a2a_remote_agent_utils.js +131 -0
  42. package/dist/esm/a2a/agent_card.js +340 -0
  43. package/dist/esm/a2a/agent_executor.js +202 -0
  44. package/dist/esm/a2a/agent_to_a2a.js +80 -0
  45. package/dist/esm/a2a/event_processor_utils.js +159 -0
  46. package/dist/esm/a2a/executor_context.js +1 -1
  47. package/dist/esm/a2a/metadata_converter_utils.js +1 -0
  48. package/dist/esm/a2a/part_converter_utils.js +24 -13
  49. package/dist/esm/agents/llm_agent.js +17 -0
  50. package/dist/esm/agents/{content_processor_utils.js → processors/content_processor_utils.js} +23 -2
  51. package/dist/esm/agents/processors/content_request_processor.js +25 -4
  52. package/dist/esm/agents/processors/context_compactor_request_processor.js +31 -0
  53. package/dist/esm/agents/processors/instructions_llm_request_processor.js +1 -1
  54. package/dist/esm/artifacts/file_artifact_service.js +30 -3
  55. package/dist/esm/common.js +33 -1
  56. package/dist/esm/context/base_context_compactor.js +5 -0
  57. package/dist/esm/context/summarizers/base_summarizer.js +5 -0
  58. package/dist/esm/context/summarizers/llm_summarizer.js +65 -0
  59. package/dist/esm/context/token_based_context_compactor.js +105 -0
  60. package/dist/esm/context/truncating_context_compactor.js +28 -0
  61. package/dist/esm/events/compacted_event.js +22 -0
  62. package/dist/esm/index.js +38 -14
  63. package/dist/esm/index.js.map +4 -4
  64. package/dist/esm/memory/in_memory_memory_service.js +1 -1
  65. package/dist/esm/runner/runner.js +17 -9
  66. package/dist/esm/sessions/db/operations.js +4 -14
  67. package/dist/esm/sessions/state.js +2 -2
  68. package/dist/esm/tools/agent_tool.js +6 -5
  69. package/dist/esm/tools/load_artifacts_tool.js +159 -0
  70. package/dist/esm/tools/load_memory_tool.js +78 -0
  71. package/dist/esm/tools/preload_memory_tool.js +80 -0
  72. package/dist/esm/utils/logger.js +1 -0
  73. package/dist/esm/version.js +1 -1
  74. package/dist/types/a2a/a2a_event.d.ts +23 -6
  75. package/dist/types/a2a/a2a_remote_agent.d.ts +63 -0
  76. package/dist/types/a2a/a2a_remote_agent_run_processor.d.ts +31 -0
  77. package/dist/types/a2a/a2a_remote_agent_utils.d.ts +38 -0
  78. package/dist/types/a2a/agent_card.d.ts +23 -0
  79. package/dist/types/a2a/agent_executor.d.ts +52 -0
  80. package/dist/types/a2a/agent_to_a2a.d.ts +45 -0
  81. package/dist/types/a2a/event_processor_utils.d.ts +24 -0
  82. package/dist/types/a2a/executor_context.d.ts +1 -1
  83. package/dist/types/a2a/metadata_converter_utils.d.ts +2 -1
  84. package/dist/types/agents/llm_agent.d.ts +6 -0
  85. package/dist/types/agents/loop_agent.d.ts +1 -1
  86. package/dist/types/agents/{content_processor_utils.d.ts → processors/content_processor_utils.d.ts} +1 -1
  87. package/dist/types/agents/processors/context_compactor_request_processor.d.ts +22 -0
  88. package/dist/types/artifacts/file_artifact_service.d.ts +4 -0
  89. package/dist/types/common.d.ts +16 -1
  90. package/dist/types/context/base_context_compactor.d.ts +24 -0
  91. package/dist/types/context/summarizers/base_summarizer.d.ts +19 -0
  92. package/dist/types/context/summarizers/llm_summarizer.d.ts +23 -0
  93. package/dist/types/context/token_based_context_compactor.d.ts +33 -0
  94. package/dist/types/context/truncating_context_compactor.d.ts +24 -0
  95. package/dist/types/events/compacted_event.d.ts +33 -0
  96. package/dist/types/index.d.ts +8 -0
  97. package/dist/types/runner/runner.d.ts +13 -0
  98. package/dist/types/sessions/db/operations.d.ts +2 -3
  99. package/dist/types/tools/load_artifacts_tool.d.ts +21 -0
  100. package/dist/types/tools/load_memory_tool.d.ts +22 -0
  101. package/dist/types/tools/preload_memory_tool.d.ts +23 -0
  102. package/dist/types/version.d.ts +1 -1
  103. package/dist/web/a2a/a2a_event.js +52 -26
  104. package/dist/web/a2a/a2a_remote_agent.js +193 -0
  105. package/dist/web/a2a/a2a_remote_agent_run_processor.js +175 -0
  106. package/dist/web/a2a/a2a_remote_agent_utils.js +131 -0
  107. package/dist/web/a2a/agent_card.js +340 -0
  108. package/dist/web/a2a/agent_executor.js +216 -0
  109. package/dist/web/a2a/agent_to_a2a.js +80 -0
  110. package/dist/web/a2a/event_processor_utils.js +168 -0
  111. package/dist/web/a2a/executor_context.js +1 -1
  112. package/dist/web/a2a/metadata_converter_utils.js +1 -0
  113. package/dist/web/a2a/part_converter_utils.js +24 -13
  114. package/dist/web/agents/llm_agent.js +17 -0
  115. package/dist/web/agents/{content_processor_utils.js → processors/content_processor_utils.js} +22 -2
  116. package/dist/web/agents/processors/content_request_processor.js +25 -4
  117. package/dist/web/agents/processors/context_compactor_request_processor.js +49 -0
  118. package/dist/web/agents/processors/instructions_llm_request_processor.js +1 -1
  119. package/dist/web/artifacts/file_artifact_service.js +30 -3
  120. package/dist/web/common.js +33 -1
  121. package/dist/web/context/base_context_compactor.js +5 -0
  122. package/dist/web/context/summarizers/base_summarizer.js +5 -0
  123. package/dist/web/context/summarizers/llm_summarizer.js +74 -0
  124. package/dist/web/context/token_based_context_compactor.js +105 -0
  125. package/dist/web/context/truncating_context_compactor.js +28 -0
  126. package/dist/web/events/compacted_event.js +40 -0
  127. package/dist/web/index.js +1 -1
  128. package/dist/web/index.js.map +4 -4
  129. package/dist/web/memory/in_memory_memory_service.js +1 -1
  130. package/dist/web/runner/runner.js +17 -9
  131. package/dist/web/sessions/db/operations.js +4 -14
  132. package/dist/web/sessions/state.js +2 -2
  133. package/dist/web/tools/agent_tool.js +6 -5
  134. package/dist/web/tools/load_artifacts_tool.js +150 -0
  135. package/dist/web/tools/load_memory_tool.js +77 -0
  136. package/dist/web/tools/preload_memory_tool.js +75 -0
  137. package/dist/web/utils/logger.js +1 -0
  138. package/dist/web/version.js +1 -1
  139. package/package.json +6 -4
@@ -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) {
@@ -3,6 +3,7 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ var _a;
6
7
  import { createPartFromText } from "@google/genai";
7
8
  import { context, trace } from "@opentelemetry/api";
8
9
  import {
@@ -24,12 +25,18 @@ import {
24
25
  } from "../telemetry/tracing.js";
25
26
  import { logger } from "../utils/logger.js";
26
27
  import { isGemini2OrAbove } from "../utils/model_name.js";
28
+ const RUNNER_SIGNATURE_SYMBOL = Symbol.for("google.adk.runner");
29
+ function isRunner(obj) {
30
+ return typeof obj === "object" && obj !== null && RUNNER_SIGNATURE_SYMBOL in obj && obj[RUNNER_SIGNATURE_SYMBOL] === true;
31
+ }
32
+ _a = RUNNER_SIGNATURE_SYMBOL;
27
33
  class Runner {
28
34
  constructor(input) {
29
- var _a;
35
+ this[_a] = true;
36
+ var _a2;
30
37
  this.appName = input.appName;
31
38
  this.agent = input.agent;
32
- this.pluginManager = new PluginManager((_a = input.plugins) != null ? _a : []);
39
+ this.pluginManager = new PluginManager((_a2 = input.plugins) != null ? _a2 : []);
33
40
  this.artifactService = input.artifactService;
34
41
  this.sessionService = input.sessionService;
35
42
  this.memoryService = input.memoryService;
@@ -89,7 +96,7 @@ class Runner {
89
96
  ctx,
90
97
  this,
91
98
  async function* () {
92
- var _a;
99
+ var _a2;
93
100
  const session = await this.sessionService.getSession({
94
101
  appName: this.appName,
95
102
  userId,
@@ -134,7 +141,7 @@ class Runner {
134
141
  newMessage = pluginUserMessage;
135
142
  }
136
143
  if (newMessage) {
137
- if (!((_a = newMessage.parts) == null ? void 0 : _a.length)) {
144
+ if (!((_a2 = newMessage.parts) == null ? void 0 : _a2.length)) {
138
145
  throw new Error("No parts in the newMessage.");
139
146
  }
140
147
  if (runConfig.saveInputBlobsAsArtifacts) {
@@ -210,8 +217,8 @@ class Runner {
210
217
  * @param message The message containing parts to process.
211
218
  */
212
219
  async saveArtifacts(invocationId, userId, sessionId, message) {
213
- var _a;
214
- if (!this.artifactService || !((_a = message.parts) == null ? void 0 : _a.length)) {
220
+ var _a2;
221
+ if (!this.artifactService || !((_a2 = message.parts) == null ? void 0 : _a2.length)) {
215
222
  return;
216
223
  }
217
224
  for (let i = 0; i < message.parts.length; i++) {
@@ -292,12 +299,12 @@ class Runner {
292
299
  // TODO - b/425992518: Implement runLive and related methods.
293
300
  }
294
301
  function findEventByLastFunctionResponseId(events) {
295
- var _a, _b, _c, _d;
302
+ var _a2, _b, _c, _d;
296
303
  if (!events.length) {
297
304
  return null;
298
305
  }
299
306
  const lastEvent = events[events.length - 1];
300
- const functionCallId = (_d = (_c = (_b = (_a = lastEvent.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.find(
307
+ const functionCallId = (_d = (_c = (_b = (_a2 = lastEvent.content) == null ? void 0 : _a2.parts) == null ? void 0 : _b.find(
301
308
  (part) => part.functionResponse
302
309
  )) == null ? void 0 : _c.functionResponse) == null ? void 0 : _d.id;
303
310
  if (!functionCallId) {
@@ -318,5 +325,6 @@ function findEventByLastFunctionResponseId(events) {
318
325
  return null;
319
326
  }
320
327
  export {
321
- Runner
328
+ Runner,
329
+ isRunner
322
330
  };
@@ -25,7 +25,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
25
  * Copyright 2026 Google LLC
26
26
  * SPDX-License-Identifier: Apache-2.0
27
27
  */
28
- import { MikroORM } from "@mikro-orm/core";
29
28
  import {
30
29
  ENTITIES,
31
30
  SCHEMA_VERSION_1_JSON,
@@ -61,9 +60,10 @@ async function getConnectionOptionsFromUri(uri) {
61
60
  }
62
61
  const { host, port, username, password, pathname } = new URL(uri);
63
62
  const hostName = host.split(":")[0];
63
+ const dbName = uri.startsWith("sqlite://") ? uri.substring("sqlite://".length) : pathname.slice(1);
64
64
  return {
65
65
  entities: ENTITIES,
66
- dbName: pathname.slice(1),
66
+ dbName,
67
67
  host: hostName,
68
68
  port: port ? parseInt(port) : void 0,
69
69
  user: username,
@@ -71,19 +71,9 @@ async function getConnectionOptionsFromUri(uri) {
71
71
  driver
72
72
  };
73
73
  }
74
- async function ensureDatabaseCreated(ormOrUrlOrOptions) {
75
- let orm;
76
- if (ormOrUrlOrOptions instanceof MikroORM) {
77
- orm = ormOrUrlOrOptions;
78
- } else if (typeof ormOrUrlOrOptions === "string") {
79
- orm = await MikroORM.init(
80
- await getConnectionOptionsFromUri(ormOrUrlOrOptions)
81
- );
82
- } else {
83
- orm = await MikroORM.init(ormOrUrlOrOptions);
84
- }
74
+ async function ensureDatabaseCreated(orm) {
85
75
  await orm.schema.ensureDatabase();
86
- await orm.schema.updateSchema();
76
+ await orm.schema.updateSchema({ safe: true });
87
77
  }
88
78
  async function validateDatabaseSchemaVersion(orm) {
89
79
  const em = orm.em.fork();
@@ -53,8 +53,8 @@ class State {
53
53
  * @param delta The delta to update the state with.
54
54
  */
55
55
  update(delta) {
56
- this.delta = { ...this.delta, ...delta };
57
- this.value = { ...this.value, ...delta };
56
+ Object.assign(this.delta, delta);
57
+ Object.assign(this.value, delta);
58
58
  }
59
59
  /**
60
60
  * Returns the state as a plain JSON object.
@@ -63,7 +63,7 @@ class AgentTool extends (_b = BaseTool, _a = AGENT_TOOL_SIGNATURE_SYMBOL, _b) {
63
63
  args,
64
64
  toolContext
65
65
  }) {
66
- var _a2, _b2;
66
+ var _a2, _b2, _c, _d;
67
67
  if (this.skipSummarization) {
68
68
  toolContext.actions.skipSummarization = true;
69
69
  }
@@ -82,13 +82,14 @@ class AgentTool extends (_b = BaseTool, _a = AGENT_TOOL_SIGNATURE_SYMBOL, _b) {
82
82
  appName: this.agent.name,
83
83
  agent: this.agent,
84
84
  artifactService: new ForwardingArtifactService(toolContext),
85
- sessionService: new InMemorySessionService(),
86
- memoryService: new InMemoryMemoryService(),
85
+ sessionService: (_a2 = toolContext.invocationContext.sessionService) != null ? _a2 : new InMemorySessionService(),
86
+ memoryService: (_b2 = toolContext.invocationContext.memoryService) != null ? _b2 : new InMemoryMemoryService(),
87
87
  credentialService: toolContext.invocationContext.credentialService
88
88
  });
89
89
  const session = await runner.sessionService.createSession({
90
90
  appName: this.agent.name,
91
- userId: "tmp_user",
91
+ userId: toolContext.invocationContext.userId,
92
+ sessionId: toolContext.invocationContext.session.id,
92
93
  state: toolContext.state.toRecord()
93
94
  });
94
95
  let lastEvent;
@@ -102,7 +103,7 @@ class AgentTool extends (_b = BaseTool, _a = AGENT_TOOL_SIGNATURE_SYMBOL, _b) {
102
103
  }
103
104
  lastEvent = event;
104
105
  }
105
- if (!((_b2 = (_a2 = lastEvent == null ? void 0 : lastEvent.content) == null ? void 0 : _a2.parts) == null ? void 0 : _b2.length)) {
106
+ if (!((_d = (_c = lastEvent == null ? void 0 : lastEvent.content) == null ? void 0 : _c.parts) == null ? void 0 : _d.length)) {
106
107
  return "";
107
108
  }
108
109
  const hasOutputSchema = isLlmAgent(this.agent) && this.agent.outputSchema;
@@ -0,0 +1,159 @@
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: ${artifactName}, type: ${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 {
57
+ }
58
+ }
59
+ const sizeKb = decodedBuffer.length / 1024;
60
+ return {
61
+ text: `[Binary artifact: ${artifactName}, type: ${mimeType}, size: ${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.
69
+
70
+ NOTE: Call when you need access to artifacts (for example, uploads saved by the web UI).`
71
+ });
72
+ }
73
+ _getDeclaration() {
74
+ return {
75
+ name: this.name,
76
+ description: this.description,
77
+ parameters: {
78
+ type: Type.OBJECT,
79
+ properties: {
80
+ artifact_names: {
81
+ type: Type.ARRAY,
82
+ items: {
83
+ type: Type.STRING
84
+ },
85
+ description: "The names of the artifacts to load."
86
+ }
87
+ }
88
+ }
89
+ };
90
+ }
91
+ async runAsync({ args }) {
92
+ const artifactNames = args["artifact_names"] || [];
93
+ return {
94
+ artifact_names: artifactNames,
95
+ status: "artifact contents temporarily inserted and removed. to access these artifacts, call load_artifacts tool again."
96
+ };
97
+ }
98
+ async processLlmRequest(request) {
99
+ await super.processLlmRequest(request);
100
+ await this.appendArtifactsToLlmRequest(
101
+ request.toolContext,
102
+ request.llmRequest
103
+ );
104
+ }
105
+ async appendArtifactsToLlmRequest(toolContext, llmRequest) {
106
+ if (!toolContext.invocationContext.artifactService) {
107
+ return;
108
+ }
109
+ const artifactNames = await toolContext.listArtifacts();
110
+ if (!artifactNames || artifactNames.length === 0) {
111
+ return;
112
+ }
113
+ appendInstructions(llmRequest, [
114
+ `You have a list of artifacts:
115
+ ${JSON.stringify(
116
+ artifactNames
117
+ )}
118
+
119
+ When the user asks questions about any of the artifacts, you should call the
120
+ \`load_artifacts\` function to load the artifact. Always call load_artifacts
121
+ before answering questions related to the artifacts, regardless of whether the
122
+ artifacts have been loaded before. Do not depend on prior answers about the
123
+ artifacts.`
124
+ ]);
125
+ const contents = llmRequest.contents;
126
+ if (contents && contents.length > 0) {
127
+ const lastContent = contents[contents.length - 1];
128
+ if (lastContent.role === "user" && lastContent.parts && lastContent.parts.length > 0) {
129
+ const functionResponsePart = lastContent.parts[0];
130
+ const functionResponse = functionResponsePart.functionResponse;
131
+ if (functionResponse && functionResponse.name === "load_artifacts") {
132
+ const response = functionResponse.response || {};
133
+ const namesToLoad = response["artifact_names"] || [];
134
+ for (const artifactName of namesToLoad) {
135
+ let artifact = await toolContext.loadArtifact(artifactName);
136
+ if (!artifact && !artifactName.startsWith("user:")) {
137
+ const prefixedName = `user:${artifactName}`;
138
+ artifact = await toolContext.loadArtifact(prefixedName);
139
+ }
140
+ if (!artifact) {
141
+ logger.warn(`Artifact "${artifactName}" not found, skipping`);
142
+ continue;
143
+ }
144
+ const artifactPart = asSafePartForLlm(artifact, artifactName);
145
+ llmRequest.contents.push({
146
+ role: "user",
147
+ parts: [{ text: `Artifact ${artifactName} is:` }, artifactPart]
148
+ });
149
+ }
150
+ }
151
+ }
152
+ }
153
+ }
154
+ }
155
+ const LOAD_ARTIFACTS = new LoadArtifactsTool();
156
+ export {
157
+ LOAD_ARTIFACTS,
158
+ LoadArtifactsTool
159
+ };
@@ -0,0 +1,78 @@
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
70
+ you to look up the memory, you should call load_memory function with a query.`
71
+ ]);
72
+ }
73
+ }
74
+ const LOAD_MEMORY = new LoadMemoryTool();
75
+ export {
76
+ LOAD_MEMORY,
77
+ LoadMemoryTool
78
+ };
@@ -0,0 +1,80 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { appendInstructions } from "../models/llm_request.js";
7
+ import { logger } from "../utils/logger.js";
8
+ import {
9
+ BaseTool
10
+ } from "./base_tool.js";
11
+ class PreloadMemoryTool extends BaseTool {
12
+ constructor() {
13
+ super({
14
+ // Name and description are not used because this tool only
15
+ // changes llm_request.
16
+ name: "preload_memory",
17
+ description: "preload_memory"
18
+ });
19
+ }
20
+ async runAsync({
21
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
22
+ args,
23
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
24
+ toolContext
25
+ }) {
26
+ throw new Error("PreloadMemoryTool should not be called by model");
27
+ }
28
+ async processLlmRequest(request) {
29
+ var _a, _b, _c;
30
+ await super.processLlmRequest(request);
31
+ const userContent = request.toolContext.userContent;
32
+ if (!userContent || !userContent.parts || !((_a = userContent.parts[0]) == null ? void 0 : _a.text)) {
33
+ return;
34
+ }
35
+ const userQuery = userContent.parts[0].text;
36
+ let response;
37
+ try {
38
+ if (!request.toolContext.invocationContext.memoryService) {
39
+ return;
40
+ }
41
+ response = await request.toolContext.searchMemory(userQuery);
42
+ } catch (_) {
43
+ logger.warn(`Failed to preload memory for query: ${userQuery}`);
44
+ return;
45
+ }
46
+ if (!response.memories || response.memories.length === 0) {
47
+ return;
48
+ }
49
+ const memoryTextLines = [];
50
+ for (const memory of response.memories) {
51
+ const timeStr = memory.timestamp ? `Time: ${memory.timestamp}` : "";
52
+ if (timeStr) memoryTextLines.push(timeStr);
53
+ const memoryText = (_c = (_b = memory.content.parts) == null ? void 0 : _b.map((p) => {
54
+ var _a2;
55
+ return (_a2 = p.text) != null ? _a2 : "";
56
+ }).join(" ")) != null ? _c : "";
57
+ if (memoryText) {
58
+ memoryTextLines.push(
59
+ memory.author ? `${memory.author}: ${memoryText}` : memoryText
60
+ );
61
+ }
62
+ }
63
+ if (memoryTextLines.length === 0) {
64
+ return;
65
+ }
66
+ const fullMemoryText = memoryTextLines.join("\n");
67
+ const si = `The following content is from your previous conversations with the user.
68
+ They may be useful for answering the user's current query.
69
+ <PAST_CONVERSATIONS>
70
+ ${fullMemoryText}
71
+ </PAST_CONVERSATIONS>
72
+ `;
73
+ appendInstructions(request.llmRequest, [si]);
74
+ }
75
+ }
76
+ const PRELOAD_MEMORY = new PreloadMemoryTool();
77
+ export {
78
+ PRELOAD_MEMORY,
79
+ PreloadMemoryTool
80
+ };
@@ -21,6 +21,7 @@ class SimpleLogger {
21
21
  "warn": 2 /* WARN */,
22
22
  "error": 3 /* ERROR */
23
23
  },
24
+ level: "error",
24
25
  format: winston.format.combine(
25
26
  winston.format.label({ label: "ADK" }),
26
27
  winston.format((info) => {
@@ -3,7 +3,7 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- const version = "0.5.0";
6
+ const version = "0.6.0";
7
7
  export {
8
8
  version
9
9
  };
@@ -11,6 +11,18 @@ export declare enum MessageRole {
11
11
  USER = "user",
12
12
  AGENT = "agent"
13
13
  }
14
+ /**
15
+ * Task states.
16
+ */
17
+ export declare enum TaskState {
18
+ SUBMITTED = "submitted",
19
+ WORKING = "working",
20
+ COMPLETED = "completed",
21
+ FAILED = "failed",
22
+ CANCELED = "canceled",
23
+ REJECTED = "rejected",
24
+ INPUT_REQUIRED = "input-required"
25
+ }
14
26
  /**
15
27
  * A2A event.
16
28
  */
@@ -54,26 +66,29 @@ export declare function getFailedTaskStatusUpdateEventError(event: TaskStatusUpd
54
66
  /**
55
67
  * Creates a task submitted event.
56
68
  */
57
- export declare function createTaskSubmittedEvent({ taskId, contextId, message, }: {
69
+ export declare function createTaskSubmittedEvent({ taskId, contextId, message, metadata, }: {
58
70
  taskId: string;
59
71
  contextId: string;
60
72
  message: Message;
73
+ metadata?: Record<string, unknown>;
61
74
  }): TaskStatusUpdateEvent;
62
75
  /**
63
76
  * Creates a task with submitted status.
64
77
  */
65
- export declare function createTask({ contextId, message, taskId, }: {
78
+ export declare function createTask({ contextId, message, taskId, metadata, }: {
66
79
  taskId: string;
67
80
  contextId: string;
68
81
  message: Message;
82
+ metadata?: Record<string, unknown>;
69
83
  }): Task;
70
84
  /**
71
85
  * Creates a task working event.
72
86
  */
73
- export declare function createTaskWorkingEvent({ taskId, contextId, message, }: {
87
+ export declare function createTaskWorkingEvent({ taskId, contextId, message, metadata, }: {
74
88
  taskId: string;
75
89
  contextId: string;
76
- message: Message;
90
+ message?: Message;
91
+ metadata?: Record<string, unknown>;
77
92
  }): TaskStatusUpdateEvent;
78
93
  /**
79
94
  * Creates a task completed event.
@@ -107,16 +122,18 @@ export declare function createTaskFailedEvent({ taskId, contextId, error, metada
107
122
  /**
108
123
  * Creates an input required event.
109
124
  */
110
- export declare function createTaskInputRequiredEvent({ taskId, contextId, parts, }: {
125
+ export declare function createTaskInputRequiredEvent({ taskId, contextId, parts, metadata, }: {
111
126
  taskId: string;
112
127
  contextId: string;
113
128
  parts: A2APart[];
129
+ metadata?: Record<string, unknown>;
114
130
  }): TaskStatusUpdateEvent;
115
131
  /**
116
132
  * Creates an error message for missing input for a function call.
117
133
  */
118
- export declare function createInputMissingErrorEvent({ taskId, contextId, parts, }: {
134
+ export declare function createInputMissingErrorEvent({ taskId, contextId, parts, metadata, }: {
119
135
  parts: A2APart[];
120
136
  taskId: string;
121
137
  contextId: string;
138
+ metadata?: Record<string, unknown>;
122
139
  }): TaskStatusUpdateEvent;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { AGENT_CARD_PATH, AgentCard, Message, MessageSendConfiguration, MessageSendParams, Task, TaskArtifactUpdateEvent, TaskStatusUpdateEvent } from '@a2a-js/sdk';
7
+ import { ClientFactory } from '@a2a-js/sdk/client';
8
+ import { BaseAgent, BaseAgentConfig } from '../agents/base_agent.js';
9
+ import { InvocationContext } from '../agents/invocation_context.js';
10
+ import { Event as AdkEvent } from '../events/event.js';
11
+ export { AGENT_CARD_PATH };
12
+ /**
13
+ * Type alias for A2A stream event data.
14
+ */
15
+ export type A2AStreamEventData = Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent;
16
+ /**
17
+ * Callback called before sending a request to the remote agent.
18
+ * Allows modifying the request parameters.
19
+ */
20
+ export type BeforeA2ARequestCallback = (ctx: InvocationContext, params: MessageSendParams) => Promise<void> | void;
21
+ /**
22
+ * Callback called after receiving a response from the remote agent.
23
+ * Allows inspecting or modifying the response.
24
+ */
25
+ export type AfterA2ARequestCallback = (ctx: InvocationContext, resp: A2AStreamEventData) => Promise<void> | void;
26
+ /**
27
+ * Configuration for the A2ARemoteAgent.
28
+ */
29
+ export interface RemoteA2AAgentConfig extends BaseAgentConfig {
30
+ /**
31
+ * Loaded AgentCard or URL to AgentCard
32
+ */
33
+ agentCard: AgentCard | string;
34
+ /**
35
+ * Optional ClientFactory for creating the A2A Client.
36
+ */
37
+ clientFactory?: ClientFactory;
38
+ /**
39
+ * Optional default configuration for sending messages.
40
+ */
41
+ messageSendConfig?: MessageSendConfiguration;
42
+ /**
43
+ * Callbacks run before the remote request is sent.
44
+ */
45
+ beforeRequestCallbacks?: BeforeA2ARequestCallback[];
46
+ /**
47
+ * Callbacks run after receiving a response chunk or event, before conversion.
48
+ */
49
+ afterRequestCallbacks?: AfterA2ARequestCallback[];
50
+ }
51
+ /**
52
+ * RemoteA2AAgent delegates execution to a remote agent using the A2A protocol.
53
+ */
54
+ export declare class RemoteA2AAgent extends BaseAgent {
55
+ private readonly a2aConfig;
56
+ private client?;
57
+ private card?;
58
+ private isInitialized;
59
+ constructor(a2aConfig: RemoteA2AAgentConfig);
60
+ private init;
61
+ protected runAsyncImpl(context: InvocationContext): AsyncGenerator<AdkEvent, void, void>;
62
+ protected runLiveImpl(_context: InvocationContext): AsyncGenerator<AdkEvent, void, void>;
63
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { MessageSendParams } from '@a2a-js/sdk';
7
+ import { InvocationContext } from '../agents/invocation_context.js';
8
+ import { Event as AdkEvent } from '../events/event.js';
9
+ import { A2AEvent } from './a2a_event.js';
10
+ /**
11
+ * Processes streams of A2A events and aggregates partials for emissions.
12
+ */
13
+ export declare class A2ARemoteAgentRunProcessor {
14
+ private readonly request?;
15
+ private aggregations;
16
+ private aggregationOrder;
17
+ constructor(request?: MessageSendParams | undefined);
18
+ /**
19
+ * aggregatePartial stores contents of partial events to emit them with the terminal event.
20
+ * It can return multiple events to emit instead of just the provided one.
21
+ */
22
+ aggregatePartial(context: InvocationContext, a2aEvent: A2AEvent, adkEvent: AdkEvent): AdkEvent[];
23
+ private removeAggregation;
24
+ private updateAggregation;
25
+ private buildNonPartialAggregation;
26
+ private promoteTextBlocksToParts;
27
+ /**
28
+ * Adds request and response metadata to the event.
29
+ */
30
+ updateCustomMetadata(event: AdkEvent, response?: A2AEvent): void;
31
+ }