@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
@@ -0,0 +1,108 @@
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));
20
+ /**
21
+ * @license
22
+ * Copyright 2026 Google LLC
23
+ * SPDX-License-Identifier: Apache-2.0
24
+ */
25
+ import { isTask } from "./a2a_event.js";
26
+ const ADK_METADATA_KEY_PREFIX = "adk_";
27
+ const A2A_METADATA_KEY_PREFIX = "a2a:";
28
+ var A2AMetadataKeys = ((A2AMetadataKeys2) => {
29
+ A2AMetadataKeys2[A2AMetadataKeys2["APP_NAME"] = "".concat(ADK_METADATA_KEY_PREFIX, "app_name")] = "APP_NAME";
30
+ A2AMetadataKeys2[A2AMetadataKeys2["USER_ID"] = "".concat(ADK_METADATA_KEY_PREFIX, "user_id")] = "USER_ID";
31
+ A2AMetadataKeys2[A2AMetadataKeys2["SESSION_ID"] = "".concat(ADK_METADATA_KEY_PREFIX, "session_id")] = "SESSION_ID";
32
+ A2AMetadataKeys2[A2AMetadataKeys2["INVOCATION_ID"] = "".concat(ADK_METADATA_KEY_PREFIX, "invocation_id")] = "INVOCATION_ID";
33
+ A2AMetadataKeys2[A2AMetadataKeys2["AUTHOR"] = "".concat(ADK_METADATA_KEY_PREFIX, "author")] = "AUTHOR";
34
+ A2AMetadataKeys2[A2AMetadataKeys2["BRANCH"] = "".concat(ADK_METADATA_KEY_PREFIX, "branch")] = "BRANCH";
35
+ A2AMetadataKeys2[A2AMetadataKeys2["DATA_PART_TYPE"] = "".concat(ADK_METADATA_KEY_PREFIX, "type")] = "DATA_PART_TYPE";
36
+ A2AMetadataKeys2[A2AMetadataKeys2["PARTIAL"] = "".concat(ADK_METADATA_KEY_PREFIX, "partial")] = "PARTIAL";
37
+ A2AMetadataKeys2[A2AMetadataKeys2["ESCALATE"] = "".concat(ADK_METADATA_KEY_PREFIX, "escalate")] = "ESCALATE";
38
+ A2AMetadataKeys2[A2AMetadataKeys2["TRANSFER_TO_AGENT"] = "".concat(ADK_METADATA_KEY_PREFIX, "transfer_to_agent")] = "TRANSFER_TO_AGENT";
39
+ A2AMetadataKeys2[A2AMetadataKeys2["IS_LONG_RUNNING"] = "".concat(ADK_METADATA_KEY_PREFIX, "is_long_running")] = "IS_LONG_RUNNING";
40
+ A2AMetadataKeys2[A2AMetadataKeys2["THOUGHT"] = "".concat(ADK_METADATA_KEY_PREFIX, "thought")] = "THOUGHT";
41
+ A2AMetadataKeys2[A2AMetadataKeys2["ERROR_CODE"] = "".concat(ADK_METADATA_KEY_PREFIX, "error_code")] = "ERROR_CODE";
42
+ A2AMetadataKeys2[A2AMetadataKeys2["ERROR_MESSAGE"] = "".concat(ADK_METADATA_KEY_PREFIX, "error_message")] = "ERROR_MESSAGE";
43
+ A2AMetadataKeys2[A2AMetadataKeys2["CITATION_METADATA"] = "".concat(ADK_METADATA_KEY_PREFIX, "citation_metadata")] = "CITATION_METADATA";
44
+ A2AMetadataKeys2[A2AMetadataKeys2["GROUNDING_METADATA"] = "".concat(ADK_METADATA_KEY_PREFIX, "grounding_metadata")] = "GROUNDING_METADATA";
45
+ A2AMetadataKeys2[A2AMetadataKeys2["USAGE_METADATA"] = "".concat(ADK_METADATA_KEY_PREFIX, "usage_metadata")] = "USAGE_METADATA";
46
+ A2AMetadataKeys2[A2AMetadataKeys2["CUSTOM_METADATA"] = "".concat(ADK_METADATA_KEY_PREFIX, "custom_metadata")] = "CUSTOM_METADATA";
47
+ A2AMetadataKeys2[A2AMetadataKeys2["VIDEO_METADATA"] = "".concat(ADK_METADATA_KEY_PREFIX, "video_metadata")] = "VIDEO_METADATA";
48
+ return A2AMetadataKeys2;
49
+ })(A2AMetadataKeys || {});
50
+ var AdkMetadataKeys = ((AdkMetadataKeys2) => {
51
+ AdkMetadataKeys2[AdkMetadataKeys2["TASK_ID"] = "".concat(A2A_METADATA_KEY_PREFIX, "task_id")] = "TASK_ID";
52
+ AdkMetadataKeys2[AdkMetadataKeys2["CONTEXT_ID"] = "".concat(A2A_METADATA_KEY_PREFIX, "context_id")] = "CONTEXT_ID";
53
+ return AdkMetadataKeys2;
54
+ })(AdkMetadataKeys || {});
55
+ function getAdkEventMetadata(a2aEvent) {
56
+ return {
57
+ [AdkMetadataKeys.TASK_ID]: isTask(a2aEvent) ? a2aEvent.id : a2aEvent.taskId,
58
+ [AdkMetadataKeys.CONTEXT_ID]: a2aEvent.contextId
59
+ };
60
+ }
61
+ function getA2AEventMetadata(adkEvent, {
62
+ appName,
63
+ userId,
64
+ sessionId
65
+ }) {
66
+ return __spreadProps(__spreadValues(__spreadValues({}, getA2AEventMetadataFromActions(adkEvent.actions)), getA2ASessionMetadata({
67
+ appName,
68
+ userId,
69
+ sessionId
70
+ })), {
71
+ [A2AMetadataKeys.INVOCATION_ID]: adkEvent.invocationId,
72
+ [A2AMetadataKeys.AUTHOR]: adkEvent.author,
73
+ [A2AMetadataKeys.BRANCH]: adkEvent.branch,
74
+ [A2AMetadataKeys.ERROR_CODE]: adkEvent.errorMessage,
75
+ [A2AMetadataKeys.ERROR_MESSAGE]: adkEvent.errorMessage,
76
+ [A2AMetadataKeys.CITATION_METADATA]: adkEvent.citationMetadata,
77
+ [A2AMetadataKeys.GROUNDING_METADATA]: adkEvent.groundingMetadata,
78
+ [A2AMetadataKeys.USAGE_METADATA]: adkEvent.usageMetadata,
79
+ [A2AMetadataKeys.CUSTOM_METADATA]: adkEvent.customMetadata,
80
+ [A2AMetadataKeys.PARTIAL]: adkEvent.partial,
81
+ [A2AMetadataKeys.IS_LONG_RUNNING]: (adkEvent.longRunningToolIds || []).length > 0
82
+ });
83
+ }
84
+ function getA2ASessionMetadata({
85
+ appName,
86
+ userId,
87
+ sessionId
88
+ }) {
89
+ return {
90
+ [A2AMetadataKeys.APP_NAME]: appName,
91
+ [A2AMetadataKeys.USER_ID]: userId,
92
+ [A2AMetadataKeys.SESSION_ID]: sessionId
93
+ };
94
+ }
95
+ function getA2AEventMetadataFromActions(actions) {
96
+ return {
97
+ [A2AMetadataKeys.ESCALATE]: actions.escalate,
98
+ [A2AMetadataKeys.TRANSFER_TO_AGENT]: actions.transferToAgent
99
+ };
100
+ }
101
+ export {
102
+ A2AMetadataKeys,
103
+ AdkMetadataKeys,
104
+ getA2AEventMetadata,
105
+ getA2AEventMetadataFromActions,
106
+ getA2ASessionMetadata,
107
+ getAdkEventMetadata
108
+ };
@@ -3,12 +3,11 @@
3
3
  * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- var MetadataKeys = /* @__PURE__ */ ((MetadataKeys2) => {
7
- MetadataKeys2["TYPE"] = "adk_type";
8
- MetadataKeys2["LONG_RUNNING"] = "adk_is_long_running";
9
- MetadataKeys2["THOUGHT"] = "adk_thought";
10
- return MetadataKeys2;
11
- })(MetadataKeys || {});
6
+ import {
7
+ createModelContent,
8
+ createUserContent
9
+ } from "@google/genai";
10
+ import { A2AMetadataKeys } from "./metadata_converter_utils.js";
12
11
  var DataPartType = /* @__PURE__ */ ((DataPartType2) => {
13
12
  DataPartType2["FUNCTION_CALL"] = "function_call";
14
13
  DataPartType2["FUNCTION_RESPONSE"] = "function_response";
@@ -16,7 +15,7 @@ var DataPartType = /* @__PURE__ */ ((DataPartType2) => {
16
15
  DataPartType2["CODE_EXECUTABLE_CODE"] = "executable_code";
17
16
  return DataPartType2;
18
17
  })(DataPartType || {});
19
- function toA2AParts(parts, longRunningToolIDs = []) {
18
+ function toA2AParts(parts = [], longRunningToolIDs = []) {
20
19
  return parts.map((part) => toA2APart(part, longRunningToolIDs));
21
20
  }
22
21
  function toA2APart(part, longRunningToolIDs) {
@@ -30,14 +29,18 @@ function toA2APart(part, longRunningToolIDs) {
30
29
  }
31
30
  function toA2ATextPart(part) {
32
31
  const a2aPart = { kind: "text", text: part.text || "" };
33
- if ("thought" in part && part["thought"]) {
32
+ if (part.thought) {
34
33
  a2aPart.metadata = {
35
- ["adk_thought" /* THOUGHT */]: true
34
+ [A2AMetadataKeys.THOUGHT]: true
36
35
  };
37
36
  }
38
37
  return a2aPart;
39
38
  }
40
39
  function toA2AFilePart(part) {
40
+ const metadata = {};
41
+ if (part.videoMetadata) {
42
+ metadata[A2AMetadataKeys.VIDEO_METADATA] = part.videoMetadata;
43
+ }
41
44
  if (part.fileData) {
42
45
  return {
43
46
  kind: "file",
@@ -45,7 +48,7 @@ function toA2AFilePart(part) {
45
48
  uri: part.fileData.fileUri || "",
46
49
  mimeType: part.fileData.mimeType
47
50
  },
48
- metadata: {}
51
+ metadata
49
52
  };
50
53
  }
51
54
  if (part.inlineData) {
@@ -55,37 +58,41 @@ function toA2AFilePart(part) {
55
58
  bytes: part.inlineData.data || "",
56
59
  mimeType: part.inlineData.mimeType
57
60
  },
58
- metadata: {}
61
+ metadata
59
62
  };
60
63
  }
61
64
  throw new Error("Not a file part: ".concat(JSON.stringify(part)));
62
65
  }
63
66
  function toA2ADataPart(part, longRunningToolIDs = []) {
64
- let type;
67
+ let dataPartType;
65
68
  let data;
66
69
  if (part.functionCall) {
67
- type = "function_call" /* FUNCTION_CALL */;
70
+ dataPartType = "function_call" /* FUNCTION_CALL */;
68
71
  data = part.functionCall;
69
72
  } else if (part.functionResponse) {
70
- type = "function_response" /* FUNCTION_RESPONSE */;
73
+ dataPartType = "function_response" /* FUNCTION_RESPONSE */;
71
74
  data = part.functionResponse;
72
75
  } else if (part.executableCode) {
73
- type = "executable_code" /* CODE_EXECUTABLE_CODE */;
76
+ dataPartType = "executable_code" /* CODE_EXECUTABLE_CODE */;
74
77
  data = part.executableCode;
75
78
  } else if (part.codeExecutionResult) {
76
- type = "code_execution_result" /* CODE_EXEC_RESULT */;
79
+ dataPartType = "code_execution_result" /* CODE_EXEC_RESULT */;
77
80
  data = part.codeExecutionResult;
78
81
  } else {
79
- throw new Error("Unknown part type: ".concat(JSON.stringify(part)));
82
+ return {
83
+ kind: "data",
84
+ data: {},
85
+ metadata: {}
86
+ };
80
87
  }
81
88
  const metadata = {
82
- ["adk_type" /* TYPE */]: type
89
+ [A2AMetadataKeys.DATA_PART_TYPE]: dataPartType
83
90
  };
84
- if (part.functionCall && part.functionCall.name && longRunningToolIDs.includes(part.functionCall.name)) {
85
- metadata["adk_is_long_running" /* LONG_RUNNING */] = true;
91
+ if (part.functionCall && part.functionCall.id && longRunningToolIDs.includes(part.functionCall.id)) {
92
+ metadata[A2AMetadataKeys.IS_LONG_RUNNING] = true;
86
93
  }
87
- if (part.functionResponse && part.functionResponse.name && longRunningToolIDs.includes(part.functionResponse.name)) {
88
- metadata["adk_is_long_running" /* LONG_RUNNING */] = true;
94
+ if (part.functionResponse && part.functionResponse.id && longRunningToolIDs.includes(part.functionResponse.id)) {
95
+ metadata[A2AMetadataKeys.IS_LONG_RUNNING] = true;
89
96
  }
90
97
  return {
91
98
  kind: "data",
@@ -93,6 +100,10 @@ function toA2ADataPart(part, longRunningToolIDs = []) {
93
100
  metadata
94
101
  };
95
102
  }
103
+ function toGenAIContent(a2aMessage) {
104
+ const parts = toGenAIParts(a2aMessage.parts);
105
+ return a2aMessage.role === "user" ? createUserContent(parts) : createModelContent(parts);
106
+ }
96
107
  function toGenAIParts(a2aParts) {
97
108
  return a2aParts.map((a2aPart) => toGenAIPart(a2aPart));
98
109
  }
@@ -112,25 +123,28 @@ function toGenAIPartText(a2aPart) {
112
123
  var _a;
113
124
  return {
114
125
  text: a2aPart.text,
115
- thought: !!((_a = a2aPart.metadata) == null ? void 0 : _a["adk_thought" /* THOUGHT */])
126
+ thought: !!((_a = a2aPart.metadata) == null ? void 0 : _a[A2AMetadataKeys.THOUGHT])
116
127
  };
117
128
  }
118
129
  function toGenAIPartFile(a2aPart) {
130
+ var _a;
131
+ const part = {};
132
+ if ((_a = a2aPart.metadata) == null ? void 0 : _a[A2AMetadataKeys.VIDEO_METADATA]) {
133
+ part.videoMetadata = a2aPart.metadata[A2AMetadataKeys.VIDEO_METADATA];
134
+ }
119
135
  if ("bytes" in a2aPart.file) {
120
- return {
121
- inlineData: {
122
- data: a2aPart.file.bytes,
123
- mimeType: a2aPart.file.mimeType || ""
124
- }
136
+ part.inlineData = {
137
+ data: a2aPart.file.bytes,
138
+ mimeType: a2aPart.file.mimeType || ""
125
139
  };
140
+ return part;
126
141
  }
127
142
  if ("uri" in a2aPart.file) {
128
- return {
129
- fileData: {
130
- fileUri: a2aPart.file.uri,
131
- mimeType: a2aPart.file.mimeType || ""
132
- }
143
+ part.fileData = {
144
+ fileUri: a2aPart.file.uri,
145
+ mimeType: a2aPart.file.mimeType || ""
133
146
  };
147
+ return part;
134
148
  }
135
149
  throw new Error("Not a file part: ".concat(JSON.stringify(a2aPart)));
136
150
  }
@@ -140,7 +154,7 @@ function toGenAIPartData(a2aPart) {
140
154
  throw new Error("No data in part: ".concat(JSON.stringify(a2aPart)));
141
155
  }
142
156
  const data = a2aPart.data;
143
- const type = (_a = a2aPart.metadata) == null ? void 0 : _a["adk_type" /* TYPE */];
157
+ const type = (_a = a2aPart.metadata) == null ? void 0 : _a[A2AMetadataKeys.DATA_PART_TYPE];
144
158
  if (type === "function_call" /* FUNCTION_CALL */) {
145
159
  return { functionCall: data };
146
160
  }
@@ -163,6 +177,7 @@ export {
163
177
  toA2APart,
164
178
  toA2AParts,
165
179
  toA2ATextPart,
180
+ toGenAIContent,
166
181
  toGenAIPart,
167
182
  toGenAIPartData,
168
183
  toGenAIPartFile,
@@ -78,7 +78,7 @@ import {
78
78
  traceAgentInvocation,
79
79
  tracer
80
80
  } from "../telemetry/tracing.js";
81
- import { CallbackContext } from "./callback_context.js";
81
+ import { Context } from "./context.js";
82
82
  import { InvocationContext } from "./invocation_context.js";
83
83
  const BASE_AGENT_SIGNATURE_SYMBOL = Symbol.for("google.adk.baseAgent");
84
84
  function isBaseAgent(obj) {
@@ -239,7 +239,7 @@ class BaseAgent {
239
239
  if (this.beforeAgentCallback.length === 0) {
240
240
  return void 0;
241
241
  }
242
- const callbackContext = new CallbackContext({ invocationContext });
242
+ const callbackContext = new Context({ invocationContext });
243
243
  for (const callback of this.beforeAgentCallback) {
244
244
  const content = await callback(callbackContext);
245
245
  if (content) {
@@ -274,7 +274,7 @@ class BaseAgent {
274
274
  if (this.afterAgentCallback.length === 0) {
275
275
  return void 0;
276
276
  }
277
- const callbackContext = new CallbackContext({ invocationContext });
277
+ const callbackContext = new Context({ invocationContext });
278
278
  for (const callback of this.afterAgentCallback) {
279
279
  const content = await callback(callbackContext);
280
280
  if (content) {
@@ -3,29 +3,84 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { CallbackContext } from "../agents/callback_context.js";
7
6
  import { AuthHandler } from "../auth/auth_handler.js";
7
+ import { createEventActions } from "../events/event_actions.js";
8
+ import { State } from "../sessions/state.js";
8
9
  import { ToolConfirmation } from "../tools/tool_confirmation.js";
9
- class ToolContext extends CallbackContext {
10
+ import { ReadonlyContext } from "./readonly_context.js";
11
+ class Context extends ReadonlyContext {
10
12
  /**
11
- * @param params.invocationContext The invocation context of the tool.
12
- * @param params.eventActions The event actions of the current tool call.
13
- * @param params.functionCallId The function call id of the current tool call.
13
+ * @param options The configuration options for the Context.
14
+ * @param options.invocationContext The invocation context.
15
+ * @param options.eventActions The event actions of the current call.
16
+ * @param options.functionCallId The function call id of the current tool call.
14
17
  * This id was returned in the function call event from LLM to identify a
15
18
  * function call. If LLM didn't return this id, ADK will assign one to it.
16
19
  * This id is used to map function call response to the original function
17
20
  * call.
18
- * @param params.toolConfirmation The tool confirmation of the current tool
21
+ * @param options.toolConfirmation The tool confirmation of the current tool
19
22
  * call.
20
23
  */
21
- constructor(params) {
22
- super(params);
23
- this.functionCallId = params.functionCallId;
24
- this.toolConfirmation = params.toolConfirmation;
24
+ constructor(options) {
25
+ super(options.invocationContext);
26
+ this.eventActions = options.eventActions || createEventActions();
27
+ this._state = new State(
28
+ options.invocationContext.session.state,
29
+ this.eventActions.stateDelta
30
+ );
31
+ this.functionCallId = options.functionCallId;
32
+ this.toolConfirmation = options.toolConfirmation;
33
+ }
34
+ /**
35
+ * The delta-aware state of the current session.
36
+ */
37
+ get state() {
38
+ return this._state;
25
39
  }
26
40
  get actions() {
27
41
  return this.eventActions;
28
42
  }
43
+ /**
44
+ * Loads an artifact attached to the current session.
45
+ *
46
+ * @param filename The filename of the artifact.
47
+ * @param version The version of the artifact. If not provided, the latest
48
+ * version will be used.
49
+ * @return A promise that resolves to the loaded artifact.
50
+ */
51
+ loadArtifact(filename, version) {
52
+ if (!this.invocationContext.artifactService) {
53
+ throw new Error("Artifact service is not initialized.");
54
+ }
55
+ return this.invocationContext.artifactService.loadArtifact({
56
+ appName: this.invocationContext.appName,
57
+ userId: this.invocationContext.userId,
58
+ sessionId: this.invocationContext.session.id,
59
+ filename,
60
+ version
61
+ });
62
+ }
63
+ /**
64
+ * Saves an artifact attached to the current session.
65
+ *
66
+ * @param filename The filename of the artifact.
67
+ * @param artifact The artifact to save.
68
+ * @return A promise that resolves to the version of the saved artifact.
69
+ */
70
+ async saveArtifact(filename, artifact) {
71
+ if (!this.invocationContext.artifactService) {
72
+ throw new Error("Artifact service is not initialized.");
73
+ }
74
+ const version = await this.invocationContext.artifactService.saveArtifact({
75
+ appName: this.invocationContext.appName,
76
+ userId: this.invocationContext.userId,
77
+ sessionId: this.invocationContext.session.id,
78
+ filename,
79
+ artifact
80
+ });
81
+ this.eventActions.artifactDelta[filename] = version;
82
+ return version;
83
+ }
29
84
  requestCredential(authConfig) {
30
85
  if (!this.functionCallId) {
31
86
  throw new Error("functionCallId is not set.");
@@ -90,5 +145,5 @@ class ToolContext extends CallbackContext {
90
145
  }
91
146
  }
92
147
  export {
93
- ToolContext
148
+ Context
94
149
  };
@@ -7,9 +7,9 @@ import { createUserContent } from "@google/genai";
7
7
  import { isEmpty } from "lodash-es";
8
8
  import { createEvent, getFunctionCalls } from "../events/event.js";
9
9
  import { mergeEventActions } from "../events/event_actions.js";
10
- import { ToolContext } from "../tools/tool_context.js";
11
10
  import { randomUUID } from "../utils/env_aware_utils.js";
12
11
  import { logger } from "../utils/logger.js";
12
+ import { Context } from "./context.js";
13
13
  import {
14
14
  traceMergedToolCalls,
15
15
  tracer,
@@ -352,7 +352,7 @@ function getToolAndContext({
352
352
  "Function ".concat(functionCall.name, " is not found in the toolsDict.")
353
353
  );
354
354
  }
355
- const toolContext = new ToolContext({
355
+ const toolContext = new Context({
356
356
  invocationContext,
357
357
  functionCallId: functionCall.id || void 0,
358
358
  toolConfirmation