@google/adk 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/dist/cjs/a2a/part_converter_utils.js +210 -0
  2. package/dist/cjs/agents/active_streaming_tool.js +1 -1
  3. package/dist/cjs/agents/base_agent.js +3 -3
  4. package/dist/cjs/agents/base_llm_processor.js +1 -1
  5. package/dist/cjs/agents/callback_context.js +1 -1
  6. package/dist/cjs/agents/content_processor_utils.js +1 -1
  7. package/dist/cjs/agents/functions.js +2 -1
  8. package/dist/cjs/agents/instructions.js +1 -1
  9. package/dist/cjs/agents/invocation_context.js +1 -1
  10. package/dist/cjs/agents/live_request_queue.js +1 -1
  11. package/dist/cjs/agents/llm_agent.js +58 -40
  12. package/dist/cjs/agents/loop_agent.js +1 -1
  13. package/dist/cjs/agents/parallel_agent.js +1 -1
  14. package/dist/cjs/agents/readonly_context.js +13 -1
  15. package/dist/cjs/agents/run_config.js +2 -1
  16. package/dist/cjs/agents/sequential_agent.js +1 -1
  17. package/dist/cjs/agents/transcription_entry.js +1 -1
  18. package/dist/cjs/artifacts/base_artifact_service.js +1 -1
  19. package/dist/cjs/artifacts/file_artifact_service.js +491 -0
  20. package/dist/cjs/artifacts/gcs_artifact_service.js +127 -48
  21. package/dist/cjs/artifacts/in_memory_artifact_service.js +54 -6
  22. package/dist/cjs/artifacts/registry.js +55 -0
  23. package/dist/cjs/auth/auth_credential.js +1 -1
  24. package/dist/cjs/auth/auth_handler.js +1 -1
  25. package/dist/cjs/auth/auth_schemes.js +1 -1
  26. package/dist/cjs/auth/auth_tool.js +1 -1
  27. package/dist/cjs/auth/credential_service/base_credential_service.js +1 -1
  28. package/dist/cjs/auth/credential_service/in_memory_credential_service.js +1 -1
  29. package/dist/cjs/auth/exchanger/base_credential_exchanger.js +1 -1
  30. package/dist/cjs/auth/exchanger/credential_exchanger_registry.js +1 -1
  31. package/dist/cjs/code_executors/base_code_executor.js +1 -1
  32. package/dist/cjs/code_executors/built_in_code_executor.js +1 -1
  33. package/dist/cjs/code_executors/code_execution_utils.js +1 -1
  34. package/dist/cjs/code_executors/code_executor_context.js +1 -1
  35. package/dist/cjs/common.js +14 -1
  36. package/dist/cjs/events/event.js +33 -4
  37. package/dist/cjs/events/event_actions.js +2 -2
  38. package/dist/cjs/events/structured_events.js +105 -0
  39. package/dist/cjs/examples/base_example_provider.js +1 -1
  40. package/dist/cjs/examples/example.js +1 -1
  41. package/dist/cjs/examples/example_util.js +1 -1
  42. package/dist/cjs/index.js +54 -83
  43. package/dist/cjs/index_web.js +1 -1
  44. package/dist/cjs/memory/base_memory_service.js +1 -1
  45. package/dist/cjs/memory/in_memory_memory_service.js +1 -1
  46. package/dist/cjs/memory/memory_entry.js +1 -1
  47. package/dist/cjs/models/apigee_llm.js +182 -0
  48. package/dist/cjs/models/base_llm.js +1 -1
  49. package/dist/cjs/models/base_llm_connection.js +1 -1
  50. package/dist/cjs/models/gemini_llm_connection.js +1 -1
  51. package/dist/cjs/models/google_llm.js +70 -51
  52. package/dist/cjs/models/llm_request.js +1 -1
  53. package/dist/cjs/models/llm_response.js +1 -1
  54. package/dist/cjs/models/registry.js +3 -1
  55. package/dist/cjs/plugins/base_plugin.js +1 -1
  56. package/dist/cjs/plugins/logging_plugin.js +1 -1
  57. package/dist/cjs/plugins/plugin_manager.js +1 -1
  58. package/dist/cjs/plugins/security_plugin.js +1 -1
  59. package/dist/cjs/runner/in_memory_runner.js +1 -1
  60. package/dist/cjs/runner/runner.js +32 -1
  61. package/dist/cjs/sessions/base_session_service.js +53 -3
  62. package/dist/cjs/sessions/database_session_service.js +364 -0
  63. package/dist/cjs/sessions/db/operations.js +114 -0
  64. package/dist/cjs/sessions/db/schema.js +204 -0
  65. package/dist/cjs/sessions/in_memory_session_service.js +24 -22
  66. package/dist/cjs/sessions/registry.js +49 -0
  67. package/dist/cjs/sessions/session.js +1 -1
  68. package/dist/cjs/sessions/state.js +1 -1
  69. package/dist/cjs/telemetry/google_cloud.js +1 -1
  70. package/dist/cjs/telemetry/setup.js +1 -1
  71. package/dist/cjs/telemetry/tracing.js +1 -1
  72. package/dist/cjs/tools/agent_tool.js +1 -1
  73. package/dist/cjs/tools/base_tool.js +1 -1
  74. package/dist/cjs/tools/base_toolset.js +1 -1
  75. package/dist/cjs/tools/forwarding_artifact_service.js +17 -1
  76. package/dist/cjs/tools/function_tool.js +1 -1
  77. package/dist/cjs/tools/google_search_tool.js +1 -1
  78. package/dist/cjs/tools/long_running_tool.js +1 -1
  79. package/dist/cjs/tools/mcp/mcp_session_manager.js +1 -1
  80. package/dist/cjs/tools/mcp/mcp_tool.js +1 -1
  81. package/dist/cjs/tools/mcp/mcp_toolset.js +1 -1
  82. package/dist/cjs/tools/tool_confirmation.js +1 -1
  83. package/dist/cjs/tools/tool_context.js +1 -1
  84. package/dist/cjs/utils/client_labels.js +1 -1
  85. package/dist/cjs/utils/env_aware_utils.js +10 -1
  86. package/dist/cjs/utils/gemini_schema_util.js +1 -1
  87. package/dist/cjs/utils/logger.js +1 -1
  88. package/dist/cjs/utils/model_name.js +1 -1
  89. package/dist/cjs/utils/object_notation_utils.js +78 -0
  90. package/dist/cjs/utils/simple_zod_to_json.js +1 -1
  91. package/dist/cjs/utils/variant_utils.js +3 -9
  92. package/dist/cjs/version.js +2 -2
  93. package/dist/esm/a2a/part_converter_utils.js +171 -0
  94. package/dist/esm/agents/base_agent.js +2 -2
  95. package/dist/esm/agents/functions.js +1 -0
  96. package/dist/esm/agents/llm_agent.js +58 -40
  97. package/dist/esm/agents/readonly_context.js +12 -0
  98. package/dist/esm/agents/run_config.js +1 -0
  99. package/dist/esm/artifacts/file_artifact_service.js +451 -0
  100. package/dist/esm/artifacts/gcs_artifact_service.js +126 -47
  101. package/dist/esm/artifacts/in_memory_artifact_service.js +51 -4
  102. package/dist/esm/artifacts/registry.js +28 -0
  103. package/dist/esm/common.js +9 -1
  104. package/dist/esm/events/event.js +29 -2
  105. package/dist/esm/events/event_actions.js +1 -1
  106. package/dist/esm/events/structured_events.js +74 -0
  107. package/dist/esm/index.js +18 -88
  108. package/dist/esm/models/apigee_llm.js +152 -0
  109. package/dist/esm/models/google_llm.js +67 -49
  110. package/dist/esm/models/registry.js +2 -0
  111. package/dist/esm/runner/runner.js +31 -0
  112. package/dist/esm/sessions/base_session_service.js +49 -1
  113. package/dist/esm/sessions/database_session_service.js +350 -0
  114. package/dist/esm/sessions/db/operations.js +87 -0
  115. package/dist/esm/sessions/db/schema.js +172 -0
  116. package/dist/esm/sessions/in_memory_session_service.js +23 -21
  117. package/dist/esm/sessions/registry.js +25 -0
  118. package/dist/esm/tools/forwarding_artifact_service.js +16 -0
  119. package/dist/esm/utils/env_aware_utils.js +8 -0
  120. package/dist/esm/utils/object_notation_utils.js +47 -0
  121. package/dist/esm/utils/variant_utils.js +1 -7
  122. package/dist/esm/version.js +1 -1
  123. package/dist/types/a2a/part_converter_utils.d.ts +47 -0
  124. package/dist/types/agents/llm_agent.d.ts +11 -11
  125. package/dist/types/agents/readonly_context.d.ts +8 -0
  126. package/dist/types/agents/run_config.d.ts +6 -0
  127. package/dist/types/artifacts/base_artifact_service.d.ts +31 -0
  128. package/dist/types/artifacts/file_artifact_service.d.ts +43 -0
  129. package/dist/types/artifacts/gcs_artifact_service.d.ts +3 -1
  130. package/dist/types/artifacts/in_memory_artifact_service.d.ts +5 -2
  131. package/dist/types/artifacts/registry.d.ts +7 -0
  132. package/dist/types/common.d.ts +11 -2
  133. package/dist/types/events/event.d.ts +15 -1
  134. package/dist/types/events/event_actions.d.ts +1 -1
  135. package/dist/types/events/structured_events.d.ts +106 -0
  136. package/dist/types/index.d.ts +5 -1
  137. package/dist/types/models/apigee_llm.d.ts +59 -0
  138. package/dist/types/models/google_llm.d.ts +5 -2
  139. package/dist/types/runner/runner.d.ts +15 -0
  140. package/dist/types/sessions/base_session_service.d.ts +20 -0
  141. package/dist/types/sessions/database_session_service.d.ts +31 -0
  142. package/dist/types/sessions/db/operations.d.ts +29 -0
  143. package/dist/types/sessions/db/schema.d.ts +45 -0
  144. package/dist/types/sessions/in_memory_session_service.d.ts +4 -1
  145. package/dist/types/sessions/registry.d.ts +7 -0
  146. package/dist/types/tools/forwarding_artifact_service.d.ts +3 -1
  147. package/dist/types/utils/env_aware_utils.d.ts +7 -0
  148. package/dist/types/utils/object_notation_utils.d.ts +21 -0
  149. package/dist/types/version.d.ts +1 -1
  150. package/dist/web/a2a/part_converter_utils.js +171 -0
  151. package/dist/web/agents/base_agent.js +2 -2
  152. package/dist/web/agents/functions.js +1 -0
  153. package/dist/web/agents/llm_agent.js +79 -59
  154. package/dist/web/agents/readonly_context.js +12 -0
  155. package/dist/web/agents/run_config.js +2 -1
  156. package/dist/web/artifacts/file_artifact_service.js +506 -0
  157. package/dist/web/artifacts/gcs_artifact_service.js +123 -46
  158. package/dist/web/artifacts/in_memory_artifact_service.js +51 -4
  159. package/dist/web/artifacts/registry.js +28 -0
  160. package/dist/web/common.js +9 -1
  161. package/dist/web/events/event.js +29 -2
  162. package/dist/web/events/event_actions.js +1 -1
  163. package/dist/web/events/structured_events.js +74 -0
  164. package/dist/web/index.js +18 -8
  165. package/dist/web/models/apigee_llm.js +219 -0
  166. package/dist/web/models/google_llm.js +67 -46
  167. package/dist/web/models/registry.js +2 -0
  168. package/dist/web/runner/runner.js +33 -0
  169. package/dist/web/sessions/base_session_service.js +49 -1
  170. package/dist/web/sessions/database_session_service.js +368 -0
  171. package/dist/web/sessions/db/operations.js +87 -0
  172. package/dist/web/sessions/db/schema.js +172 -0
  173. package/dist/web/sessions/in_memory_session_service.js +23 -21
  174. package/dist/web/sessions/registry.js +25 -0
  175. package/dist/web/tools/forwarding_artifact_service.js +16 -0
  176. package/dist/web/utils/env_aware_utils.js +8 -0
  177. package/dist/web/utils/object_notation_utils.js +47 -0
  178. package/dist/web/utils/variant_utils.js +1 -7
  179. package/dist/web/version.js +1 -1
  180. package/package.json +13 -4
  181. package/dist/cjs/index.js.map +0 -7
  182. package/dist/esm/index.js.map +0 -7
  183. package/dist/web/index.js.map +0 -7
@@ -0,0 +1,210 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ "use strict";
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __getOwnPropNames = Object.getOwnPropertyNames;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var part_converter_utils_exports = {};
26
+ __export(part_converter_utils_exports, {
27
+ toA2ADataPart: () => toA2ADataPart,
28
+ toA2AFilePart: () => toA2AFilePart,
29
+ toA2APart: () => toA2APart,
30
+ toA2AParts: () => toA2AParts,
31
+ toA2ATextPart: () => toA2ATextPart,
32
+ toGenAIPart: () => toGenAIPart,
33
+ toGenAIPartData: () => toGenAIPartData,
34
+ toGenAIPartFile: () => toGenAIPartFile,
35
+ toGenAIPartText: () => toGenAIPartText,
36
+ toGenAIParts: () => toGenAIParts
37
+ });
38
+ module.exports = __toCommonJS(part_converter_utils_exports);
39
+ /**
40
+ * @license
41
+ * Copyright 2026 Google LLC
42
+ * SPDX-License-Identifier: Apache-2.0
43
+ */
44
+ var MetadataKeys = /* @__PURE__ */ ((MetadataKeys2) => {
45
+ MetadataKeys2["TYPE"] = "adk_type";
46
+ MetadataKeys2["LONG_RUNNING"] = "adk_is_long_running";
47
+ MetadataKeys2["THOUGHT"] = "adk_thought";
48
+ return MetadataKeys2;
49
+ })(MetadataKeys || {});
50
+ var DataPartType = /* @__PURE__ */ ((DataPartType2) => {
51
+ DataPartType2["FUNCTION_CALL"] = "function_call";
52
+ DataPartType2["FUNCTION_RESPONSE"] = "function_response";
53
+ DataPartType2["CODE_EXEC_RESULT"] = "code_execution_result";
54
+ DataPartType2["CODE_EXECUTABLE_CODE"] = "executable_code";
55
+ return DataPartType2;
56
+ })(DataPartType || {});
57
+ function toA2AParts(parts, longRunningToolIDs = []) {
58
+ return parts.map((part) => toA2APart(part, longRunningToolIDs));
59
+ }
60
+ function toA2APart(part, longRunningToolIDs) {
61
+ if (part.text !== void 0 && part.text !== null) {
62
+ return toA2ATextPart(part);
63
+ }
64
+ if (part.inlineData || part.fileData) {
65
+ return toA2AFilePart(part);
66
+ }
67
+ return toA2ADataPart(part, longRunningToolIDs);
68
+ }
69
+ function toA2ATextPart(part) {
70
+ const a2aPart = { kind: "text", text: part.text || "" };
71
+ if ("thought" in part && part["thought"]) {
72
+ a2aPart.metadata = {
73
+ ["adk_thought" /* THOUGHT */]: true
74
+ };
75
+ }
76
+ return a2aPart;
77
+ }
78
+ function toA2AFilePart(part) {
79
+ if (part.fileData) {
80
+ return {
81
+ kind: "file",
82
+ file: {
83
+ uri: part.fileData.fileUri || "",
84
+ mimeType: part.fileData.mimeType
85
+ },
86
+ metadata: {}
87
+ };
88
+ }
89
+ if (part.inlineData) {
90
+ return {
91
+ kind: "file",
92
+ file: {
93
+ bytes: part.inlineData.data || "",
94
+ mimeType: part.inlineData.mimeType
95
+ },
96
+ metadata: {}
97
+ };
98
+ }
99
+ throw new Error(`Not a file part: ${JSON.stringify(part)}`);
100
+ }
101
+ function toA2ADataPart(part, longRunningToolIDs = []) {
102
+ let type;
103
+ let data;
104
+ if (part.functionCall) {
105
+ type = "function_call" /* FUNCTION_CALL */;
106
+ data = part.functionCall;
107
+ } else if (part.functionResponse) {
108
+ type = "function_response" /* FUNCTION_RESPONSE */;
109
+ data = part.functionResponse;
110
+ } else if (part.executableCode) {
111
+ type = "executable_code" /* CODE_EXECUTABLE_CODE */;
112
+ data = part.executableCode;
113
+ } else if (part.codeExecutionResult) {
114
+ type = "code_execution_result" /* CODE_EXEC_RESULT */;
115
+ data = part.codeExecutionResult;
116
+ } else {
117
+ throw new Error(`Unknown part type: ${JSON.stringify(part)}`);
118
+ }
119
+ const metadata = {
120
+ ["adk_type" /* TYPE */]: type
121
+ };
122
+ if (part.functionCall && part.functionCall.name && longRunningToolIDs.includes(part.functionCall.name)) {
123
+ metadata["adk_is_long_running" /* LONG_RUNNING */] = true;
124
+ }
125
+ if (part.functionResponse && part.functionResponse.name && longRunningToolIDs.includes(part.functionResponse.name)) {
126
+ metadata["adk_is_long_running" /* LONG_RUNNING */] = true;
127
+ }
128
+ return {
129
+ kind: "data",
130
+ data,
131
+ metadata
132
+ };
133
+ }
134
+ function toGenAIParts(a2aParts) {
135
+ return a2aParts.map((a2aPart) => toGenAIPart(a2aPart));
136
+ }
137
+ function toGenAIPart(a2aPart) {
138
+ if (a2aPart.kind === "text") {
139
+ return toGenAIPartText(a2aPart);
140
+ }
141
+ if (a2aPart.kind === "file") {
142
+ return toGenAIPartFile(a2aPart);
143
+ }
144
+ if (a2aPart.kind === "data") {
145
+ return toGenAIPartData(a2aPart);
146
+ }
147
+ throw new Error(`Unknown part kind: ${JSON.stringify(a2aPart)}`);
148
+ }
149
+ function toGenAIPartText(a2aPart) {
150
+ var _a;
151
+ return {
152
+ text: a2aPart.text,
153
+ thought: !!((_a = a2aPart.metadata) == null ? void 0 : _a["adk_thought" /* THOUGHT */])
154
+ };
155
+ }
156
+ function toGenAIPartFile(a2aPart) {
157
+ if ("bytes" in a2aPart.file) {
158
+ return {
159
+ inlineData: {
160
+ data: a2aPart.file.bytes,
161
+ mimeType: a2aPart.file.mimeType || ""
162
+ }
163
+ };
164
+ }
165
+ if ("uri" in a2aPart.file) {
166
+ return {
167
+ fileData: {
168
+ fileUri: a2aPart.file.uri,
169
+ mimeType: a2aPart.file.mimeType || ""
170
+ }
171
+ };
172
+ }
173
+ throw new Error(`Not a file part: ${JSON.stringify(a2aPart)}`);
174
+ }
175
+ function toGenAIPartData(a2aPart) {
176
+ var _a;
177
+ if (!a2aPart.data) {
178
+ throw new Error(`No data in part: ${JSON.stringify(a2aPart)}`);
179
+ }
180
+ const data = a2aPart.data;
181
+ const type = (_a = a2aPart.metadata) == null ? void 0 : _a["adk_type" /* TYPE */];
182
+ if (type === "function_call" /* FUNCTION_CALL */) {
183
+ return { functionCall: data };
184
+ }
185
+ if (type === "function_response" /* FUNCTION_RESPONSE */) {
186
+ return { functionResponse: data };
187
+ }
188
+ if (type === "executable_code" /* CODE_EXECUTABLE_CODE */) {
189
+ return { executableCode: data };
190
+ }
191
+ if (type === "code_execution_result" /* CODE_EXEC_RESULT */) {
192
+ return { codeExecutionResult: data };
193
+ }
194
+ return {
195
+ text: JSON.stringify(a2aPart.data)
196
+ };
197
+ }
198
+ // Annotate the CommonJS export names for ESM import in node:
199
+ 0 && (module.exports = {
200
+ toA2ADataPart,
201
+ toA2AFilePart,
202
+ toA2APart,
203
+ toA2AParts,
204
+ toA2ATextPart,
205
+ toGenAIPart,
206
+ toGenAIPartData,
207
+ toGenAIPartFile,
208
+ toGenAIPartText,
209
+ toGenAIParts
210
+ });
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -252,7 +252,7 @@ class BaseAgent {
252
252
  function validateAgentName(name) {
253
253
  if (!isIdentifier(name)) {
254
254
  throw new Error(
255
- `Found invalid agent name: "${name}". Agent name must be a valid identifier. It should start with a letter (a-z, A-Z) or an underscore (_), and can only contain letters, digits (0-9), and underscores.`
255
+ `Found invalid agent name: "${name}". Agent name must be a valid identifier. It should start with a letter (a-z, A-Z) or an underscore (_), and can only contain letters, digits (0-9), underscores, and hyphens.`
256
256
  );
257
257
  }
258
258
  if (name === "user") {
@@ -263,7 +263,7 @@ function validateAgentName(name) {
263
263
  return name;
264
264
  }
265
265
  function isIdentifier(str) {
266
- return /^[\p{ID_Start}$_][\p{ID_Continue}$_]*$/u.test(str);
266
+ return /^[\p{ID_Start}$_][\p{ID_Continue}$_-]*$/u.test(str);
267
267
  }
268
268
  function getRootAgent(rootAgent) {
269
269
  while (rootAgent.parentAgent) {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -164,6 +164,7 @@ function generateRequestConfirmationEvent({
164
164
  parts,
165
165
  role: functionResponseEvent.content.role
166
166
  },
167
+ actions: functionResponseEvent.actions,
167
168
  longRunningToolIds: Array.from(longRunningToolIds)
168
169
  });
169
170
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -50,6 +50,7 @@ var import_tool_context = require("../tools/tool_context.js");
50
50
  var import_env_aware_utils = require("../utils/env_aware_utils.js");
51
51
  var import_logger = require("../utils/logger.js");
52
52
  var import_tracing = require("../telemetry/tracing.js");
53
+ var import_simple_zod_to_json = require("../utils/simple_zod_to_json.js");
53
54
  var import_base_agent = require("./base_agent.js");
54
55
  var import_base_llm_processor = require("./base_llm_processor.js");
55
56
  var import_callback_context = require("./callback_context.js");
@@ -66,7 +67,7 @@ var import_run_config = require("./run_config.js");
66
67
  var _a, _b;
67
68
  const ADK_AGENT_NAME_LABEL_KEY = "adk_agent_name";
68
69
  async function convertToolUnionToTools(toolUnion, context2) {
69
- if (toolUnion instanceof import_base_tool.BaseTool) {
70
+ if ((0, import_base_tool.isBaseTool)(toolUnion)) {
70
71
  return [toolUnion];
71
72
  }
72
73
  return await toolUnion.getTools(context2);
@@ -115,7 +116,7 @@ class InstructionsLlmRequestProcessor extends import_base_llm_processor.BaseLlmR
115
116
  // eslint-disable-next-line require-yield
116
117
  async *runAsync(invocationContext, llmRequest) {
117
118
  const agent = invocationContext.agent;
118
- if (!(agent instanceof LlmAgent) || !(agent.rootAgent instanceof LlmAgent)) {
119
+ if (!isLlmAgent(agent) || !isLlmAgent(agent.rootAgent)) {
119
120
  return;
120
121
  }
121
122
  const rootAgent = agent.rootAgent;
@@ -193,7 +194,7 @@ class AgentTransferLlmRequestProcessor extends import_base_llm_processor.BaseLlm
193
194
  }
194
195
  // eslint-disable-next-line require-yield
195
196
  async *runAsync(invocationContext, llmRequest) {
196
- if (!(invocationContext.agent instanceof LlmAgent)) {
197
+ if (!isLlmAgent(invocationContext.agent)) {
197
198
  return;
198
199
  }
199
200
  const transferTargets = this.getTransferTargets(invocationContext.agent);
@@ -379,7 +380,7 @@ class RequestConfirmationLlmRequestProcessor extends import_base_llm_processor.B
379
380
  const REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR = new RequestConfirmationLlmRequestProcessor();
380
381
  class CodeExecutionRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
381
382
  async *runAsync(invocationContext, llmRequest) {
382
- if (!(invocationContext.agent instanceof LlmAgent)) {
383
+ if (!isLlmAgent(invocationContext.agent)) {
383
384
  return;
384
385
  }
385
386
  if (!invocationContext.agent.codeExecutor) {
@@ -729,8 +730,8 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
729
730
  this.disallowTransferToParent = (_d = config.disallowTransferToParent) != null ? _d : false;
730
731
  this.disallowTransferToPeers = (_e = config.disallowTransferToPeers) != null ? _e : false;
731
732
  this.includeContents = (_f = config.includeContents) != null ? _f : "default";
732
- this.inputSchema = config.inputSchema;
733
- this.outputSchema = config.outputSchema;
733
+ this.inputSchema = (0, import_simple_zod_to_json.isZodObject)(config.inputSchema) ? (0, import_simple_zod_to_json.zodObjectToSchema)(config.inputSchema) : config.inputSchema;
734
+ this.outputSchema = (0, import_simple_zod_to_json.isZodObject)(config.outputSchema) ? (0, import_simple_zod_to_json.zodObjectToSchema)(config.outputSchema) : config.outputSchema;
734
735
  this.outputKey = config.outputKey;
735
736
  this.beforeModelCallback = config.beforeModelCallback;
736
737
  this.afterModelCallback = config.afterModelCallback;
@@ -775,16 +776,6 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
775
776
  this.disallowTransferToParent = true;
776
777
  this.disallowTransferToPeers = true;
777
778
  }
778
- if (this.subAgents && this.subAgents.length > 0) {
779
- throw new Error(
780
- `Invalid config for agent ${this.name}: if outputSchema is set, subAgents must be empty to disable agent transfer.`
781
- );
782
- }
783
- if (this.tools && this.tools.length > 0) {
784
- throw new Error(
785
- `Invalid config for agent ${this.name}: if outputSchema is set, tools must be empty`
786
- );
787
- }
788
779
  }
789
780
  }
790
781
  /**
@@ -1028,28 +1019,36 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
1028
1019
  ctx,
1029
1020
  this,
1030
1021
  async function* () {
1031
- for await (const llmResponse of this.callLlmAsync(
1032
- invocationContext,
1033
- llmRequest,
1034
- modelResponseEvent
1035
- )) {
1036
- for await (const event of this.postprocess(
1022
+ const responsesGenerator = async function* () {
1023
+ for await (const llmResponse of this.callLlmAsync(
1037
1024
  invocationContext,
1038
1025
  llmRequest,
1039
- llmResponse,
1040
1026
  modelResponseEvent
1041
1027
  )) {
1042
- modelResponseEvent.id = (0, import_event.createNewEventId)();
1043
- modelResponseEvent.timestamp = (/* @__PURE__ */ new Date()).getTime();
1044
- yield event;
1028
+ for await (const event of this.postprocess(
1029
+ invocationContext,
1030
+ llmRequest,
1031
+ llmResponse,
1032
+ modelResponseEvent
1033
+ )) {
1034
+ modelResponseEvent.id = (0, import_event.createNewEventId)();
1035
+ modelResponseEvent.timestamp = (/* @__PURE__ */ new Date()).getTime();
1036
+ yield event;
1037
+ }
1045
1038
  }
1046
- }
1039
+ };
1040
+ yield* this.runAndHandleError(
1041
+ responsesGenerator.call(this),
1042
+ invocationContext,
1043
+ llmRequest,
1044
+ modelResponseEvent
1045
+ );
1047
1046
  }
1048
1047
  );
1049
1048
  span.end();
1050
1049
  }
1051
1050
  async *postprocess(invocationContext, llmRequest, llmResponse, modelResponseEvent) {
1052
- var _a2;
1051
+ var _a2, _b2;
1053
1052
  for (const processor of this.responseProcessors) {
1054
1053
  for await (const event of processor.runAsync(
1055
1054
  invocationContext,
@@ -1078,6 +1077,10 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
1078
1077
  if (!((_a2 = (0, import_event.getFunctionCalls)(mergedEvent)) == null ? void 0 : _a2.length)) {
1079
1078
  return;
1080
1079
  }
1080
+ if ((_b2 = invocationContext.runConfig) == null ? void 0 : _b2.pauseOnToolCalls) {
1081
+ invocationContext.endInvocation = true;
1082
+ return;
1083
+ }
1081
1084
  const functionResponseEvent = await (0, import_functions.handleFunctionCallsAsync)({
1082
1085
  invocationContext,
1083
1086
  functionCallEvent: mergedEvent,
@@ -1102,6 +1105,8 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
1102
1105
  });
1103
1106
  if (toolConfirmationEvent) {
1104
1107
  yield toolConfirmationEvent;
1108
+ invocationContext.endInvocation = true;
1109
+ return;
1105
1110
  }
1106
1111
  yield functionResponseEvent;
1107
1112
  const nextAgentName = functionResponseEvent.actions.transferToAgent;
@@ -1158,12 +1163,7 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
1158
1163
  /* stream= */
1159
1164
  ((_e = invocationContext.runConfig) == null ? void 0 : _e.streamingMode) === import_run_config.StreamingMode.SSE
1160
1165
  );
1161
- for await (const llmResponse of this.runAndHandleError(
1162
- responsesGenerator,
1163
- invocationContext,
1164
- llmRequest,
1165
- modelResponseEvent
1166
- )) {
1166
+ for await (const llmResponse of responsesGenerator) {
1167
1167
  (0, import_tracing.traceCallLlm)({
1168
1168
  invocationContext,
1169
1169
  eventId: modelResponseEvent.id,
@@ -1244,11 +1244,29 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
1244
1244
  if (onModelErrorCallbackResponse) {
1245
1245
  yield onModelErrorCallbackResponse;
1246
1246
  } else {
1247
- const errorResponse = JSON.parse(modelError.message);
1248
- yield {
1249
- errorCode: String(errorResponse.error.code),
1250
- errorMessage: errorResponse.error.message
1251
- };
1247
+ let errorCode = "UNKNOWN_ERROR";
1248
+ let errorMessage = modelError.message;
1249
+ try {
1250
+ const errorResponse = JSON.parse(modelError.message);
1251
+ if (errorResponse == null ? void 0 : errorResponse.error) {
1252
+ errorCode = String(errorResponse.error.code || "UNKNOWN_ERROR");
1253
+ errorMessage = errorResponse.error.message || errorMessage;
1254
+ }
1255
+ } catch {
1256
+ }
1257
+ if (modelResponseEvent.actions) {
1258
+ yield (0, import_event.createEvent)({
1259
+ invocationId: invocationContext.invocationId,
1260
+ author: this.name,
1261
+ errorCode,
1262
+ errorMessage
1263
+ });
1264
+ } else {
1265
+ yield {
1266
+ errorCode,
1267
+ errorMessage
1268
+ };
1269
+ }
1252
1270
  }
1253
1271
  } else {
1254
1272
  import_logger.logger.error("Unknown error during response generation", modelError);
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -49,6 +49,18 @@ class ReadonlyContext {
49
49
  get invocationId() {
50
50
  return this.invocationContext.invocationId;
51
51
  }
52
+ /**
53
+ * The user ID of the current session.
54
+ */
55
+ get userId() {
56
+ return this.invocationContext.userId;
57
+ }
58
+ /**
59
+ * The ID of the current session.
60
+ */
61
+ get sessionId() {
62
+ return this.invocationContext.session.id;
63
+ }
52
64
  /**
53
65
  * The current agent name.
54
66
  */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -47,6 +47,7 @@ function createRunConfig(params = {}) {
47
47
  enableAffectiveDialog: false,
48
48
  streamingMode: "none" /* NONE */,
49
49
  maxLlmCalls: validateMaxLlmCalls(params.maxLlmCalls || 500),
50
+ pauseOnToolCalls: false,
50
51
  ...params
51
52
  };
52
53
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6