@paean-ai/adk 0.2.19 → 0.2.21

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 (255) hide show
  1. package/dist/cjs/agents/active_streaming_tool.js +44 -0
  2. package/dist/cjs/agents/base_agent.js +245 -0
  3. package/dist/cjs/agents/base_llm_processor.js +44 -0
  4. package/dist/cjs/agents/callback_context.js +98 -0
  5. package/dist/cjs/agents/content_processor_utils.js +311 -0
  6. package/dist/cjs/agents/functions.js +425 -0
  7. package/dist/cjs/agents/instructions.js +110 -0
  8. package/dist/cjs/agents/invocation_context.js +107 -0
  9. package/dist/cjs/agents/live_request_queue.js +136 -0
  10. package/dist/cjs/agents/llm_agent.js +1279 -0
  11. package/dist/cjs/agents/loop_agent.js +68 -0
  12. package/dist/cjs/agents/parallel_agent.js +78 -0
  13. package/dist/cjs/agents/readonly_context.js +68 -0
  14. package/dist/cjs/agents/run_config.js +70 -0
  15. package/dist/cjs/agents/sequential_agent.js +84 -0
  16. package/dist/cjs/agents/transcription_entry.js +27 -0
  17. package/dist/cjs/artifacts/base_artifact_service.js +27 -0
  18. package/dist/cjs/artifacts/gcs_artifact_service.js +140 -0
  19. package/dist/cjs/artifacts/in_memory_artifact_service.js +119 -0
  20. package/dist/cjs/auth/auth_credential.js +46 -0
  21. package/dist/cjs/auth/auth_handler.js +92 -0
  22. package/dist/cjs/auth/auth_schemes.js +62 -0
  23. package/dist/cjs/auth/auth_tool.js +27 -0
  24. package/dist/cjs/auth/credential_service/base_credential_service.js +27 -0
  25. package/dist/cjs/auth/credential_service/in_memory_credential_service.js +63 -0
  26. package/dist/cjs/auth/exchanger/base_credential_exchanger.js +40 -0
  27. package/dist/cjs/auth/exchanger/credential_exchanger_registry.js +59 -0
  28. package/dist/cjs/code_executors/base_code_executor.js +76 -0
  29. package/dist/cjs/code_executors/built_in_code_executor.js +58 -0
  30. package/dist/cjs/code_executors/code_execution_utils.js +142 -0
  31. package/dist/cjs/code_executors/code_executor_context.js +198 -0
  32. package/dist/cjs/common.js +181 -0
  33. package/dist/cjs/events/event.js +119 -0
  34. package/dist/cjs/events/event_actions.js +83 -0
  35. package/dist/cjs/examples/base_example_provider.js +40 -0
  36. package/dist/cjs/examples/example.js +27 -0
  37. package/dist/cjs/examples/example_util.js +107 -0
  38. package/dist/cjs/index.js +12 -12
  39. package/dist/cjs/index.js.map +3 -3
  40. package/dist/cjs/index_web.js +33 -0
  41. package/dist/cjs/memory/base_memory_service.js +27 -0
  42. package/dist/cjs/memory/in_memory_memory_service.js +97 -0
  43. package/dist/cjs/memory/memory_entry.js +27 -0
  44. package/dist/cjs/models/base_llm.js +95 -0
  45. package/dist/cjs/models/base_llm_connection.js +27 -0
  46. package/dist/cjs/models/gemini_llm_connection.js +132 -0
  47. package/dist/cjs/models/google_llm.js +472 -0
  48. package/dist/cjs/models/llm_request.js +82 -0
  49. package/dist/cjs/models/llm_response.js +71 -0
  50. package/dist/cjs/models/registry.js +121 -0
  51. package/dist/cjs/plugins/base_plugin.js +236 -0
  52. package/dist/cjs/plugins/logging_plugin.js +222 -0
  53. package/dist/cjs/plugins/plugin_manager.js +239 -0
  54. package/dist/cjs/plugins/security_plugin.js +153 -0
  55. package/dist/cjs/runner/in_memory_runner.js +58 -0
  56. package/dist/cjs/runner/runner.js +277 -0
  57. package/dist/cjs/sessions/base_session_service.js +71 -0
  58. package/dist/cjs/sessions/in_memory_session_service.js +184 -0
  59. package/dist/cjs/sessions/session.js +48 -0
  60. package/dist/cjs/sessions/state.js +101 -0
  61. package/dist/cjs/telemetry/google_cloud.js +85 -0
  62. package/dist/cjs/telemetry/setup.js +97 -0
  63. package/dist/cjs/telemetry/tracing.js +231 -0
  64. package/dist/cjs/tools/agent_tool.js +134 -0
  65. package/dist/cjs/tools/base_tool.js +107 -0
  66. package/dist/cjs/tools/base_toolset.js +76 -0
  67. package/dist/cjs/tools/forwarding_artifact_service.js +71 -0
  68. package/dist/cjs/tools/function_tool.js +101 -0
  69. package/dist/cjs/tools/google_search_tool.js +77 -0
  70. package/dist/cjs/tools/long_running_tool.js +63 -0
  71. package/dist/cjs/tools/mcp/mcp_session_manager.js +65 -0
  72. package/dist/cjs/tools/mcp/mcp_tool.js +65 -0
  73. package/dist/cjs/tools/mcp/mcp_toolset.js +61 -0
  74. package/dist/cjs/tools/tool_confirmation.js +49 -0
  75. package/dist/cjs/tools/tool_context.js +129 -0
  76. package/dist/cjs/utils/client_labels.js +56 -0
  77. package/dist/cjs/utils/deep_clone.js +44 -0
  78. package/dist/cjs/utils/env_aware_utils.js +83 -0
  79. package/dist/cjs/utils/gemini_schema_util.js +88 -0
  80. package/dist/cjs/utils/logger.js +121 -0
  81. package/dist/cjs/utils/model_name.js +76 -0
  82. package/dist/cjs/utils/simple_zod_to_json.js +191 -0
  83. package/dist/cjs/utils/variant_utils.js +55 -0
  84. package/dist/cjs/version.js +39 -0
  85. package/dist/esm/agents/active_streaming_tool.js +14 -0
  86. package/dist/esm/agents/base_agent.js +214 -0
  87. package/dist/esm/agents/base_llm_processor.js +13 -0
  88. package/dist/esm/agents/callback_context.js +68 -0
  89. package/dist/esm/agents/content_processor_utils.js +280 -0
  90. package/dist/esm/agents/functions.js +384 -0
  91. package/dist/esm/agents/instructions.js +80 -0
  92. package/dist/esm/agents/invocation_context.js +76 -0
  93. package/dist/esm/agents/live_request_queue.js +106 -0
  94. package/dist/esm/agents/llm_agent.js +1247 -0
  95. package/dist/esm/agents/loop_agent.js +38 -0
  96. package/dist/esm/agents/parallel_agent.js +48 -0
  97. package/dist/esm/agents/readonly_context.js +38 -0
  98. package/dist/esm/agents/run_config.js +39 -0
  99. package/dist/esm/agents/sequential_agent.js +54 -0
  100. package/dist/esm/agents/transcription_entry.js +5 -0
  101. package/dist/esm/artifacts/base_artifact_service.js +5 -0
  102. package/dist/esm/artifacts/gcs_artifact_service.js +110 -0
  103. package/dist/esm/artifacts/in_memory_artifact_service.js +89 -0
  104. package/dist/esm/auth/auth_credential.js +16 -0
  105. package/dist/esm/auth/auth_handler.js +62 -0
  106. package/dist/esm/auth/auth_schemes.js +31 -0
  107. package/dist/esm/auth/auth_tool.js +5 -0
  108. package/dist/esm/auth/credential_service/base_credential_service.js +5 -0
  109. package/dist/esm/auth/credential_service/in_memory_credential_service.js +33 -0
  110. package/dist/esm/auth/exchanger/base_credential_exchanger.js +10 -0
  111. package/dist/esm/auth/exchanger/credential_exchanger_registry.js +29 -0
  112. package/dist/esm/code_executors/base_code_executor.js +46 -0
  113. package/dist/esm/code_executors/built_in_code_executor.js +28 -0
  114. package/dist/esm/code_executors/code_execution_utils.js +108 -0
  115. package/dist/esm/code_executors/code_executor_context.js +168 -0
  116. package/dist/esm/common.js +98 -0
  117. package/dist/esm/events/event.js +83 -0
  118. package/dist/esm/events/event_actions.js +52 -0
  119. package/dist/esm/examples/base_example_provider.js +10 -0
  120. package/dist/esm/examples/example.js +5 -0
  121. package/dist/esm/examples/example_util.js +76 -0
  122. package/dist/esm/index.js +12 -12
  123. package/dist/esm/index.js.map +3 -3
  124. package/dist/esm/index_web.js +6 -0
  125. package/dist/esm/memory/base_memory_service.js +5 -0
  126. package/dist/esm/memory/in_memory_memory_service.js +67 -0
  127. package/dist/esm/memory/memory_entry.js +5 -0
  128. package/dist/esm/models/base_llm.js +64 -0
  129. package/dist/esm/models/base_llm_connection.js +5 -0
  130. package/dist/esm/models/gemini_llm_connection.js +102 -0
  131. package/dist/esm/models/google_llm.js +446 -0
  132. package/dist/esm/models/llm_request.js +50 -0
  133. package/dist/esm/models/llm_response.js +41 -0
  134. package/dist/esm/models/registry.js +91 -0
  135. package/dist/esm/plugins/base_plugin.js +206 -0
  136. package/dist/esm/plugins/logging_plugin.js +192 -0
  137. package/dist/esm/plugins/plugin_manager.js +209 -0
  138. package/dist/esm/plugins/security_plugin.js +119 -0
  139. package/dist/esm/runner/in_memory_runner.js +28 -0
  140. package/dist/esm/runner/runner.js +247 -0
  141. package/dist/esm/sessions/base_session_service.js +41 -0
  142. package/dist/esm/sessions/in_memory_session_service.js +154 -0
  143. package/dist/esm/sessions/session.js +18 -0
  144. package/dist/esm/sessions/state.js +71 -0
  145. package/dist/esm/telemetry/google_cloud.js +54 -0
  146. package/dist/esm/telemetry/setup.js +67 -0
  147. package/dist/esm/telemetry/tracing.js +195 -0
  148. package/dist/esm/tools/agent_tool.js +104 -0
  149. package/dist/esm/tools/base_tool.js +77 -0
  150. package/dist/esm/tools/base_toolset.js +46 -0
  151. package/dist/esm/tools/forwarding_artifact_service.js +41 -0
  152. package/dist/esm/tools/function_tool.js +71 -0
  153. package/dist/esm/tools/google_search_tool.js +47 -0
  154. package/dist/esm/tools/long_running_tool.js +33 -0
  155. package/dist/esm/tools/mcp/mcp_session_manager.js +35 -0
  156. package/dist/esm/tools/mcp/mcp_tool.js +35 -0
  157. package/dist/esm/tools/mcp/mcp_toolset.js +31 -0
  158. package/dist/esm/tools/tool_confirmation.js +19 -0
  159. package/dist/esm/tools/tool_context.js +99 -0
  160. package/dist/esm/utils/client_labels.js +26 -0
  161. package/dist/esm/utils/deep_clone.js +14 -0
  162. package/dist/esm/utils/env_aware_utils.js +49 -0
  163. package/dist/esm/utils/gemini_schema_util.js +58 -0
  164. package/dist/esm/utils/logger.js +89 -0
  165. package/dist/esm/utils/model_name.js +41 -0
  166. package/dist/esm/utils/simple_zod_to_json.js +160 -0
  167. package/dist/esm/utils/variant_utils.js +24 -0
  168. package/dist/esm/version.js +9 -0
  169. package/dist/types/agents/llm_agent.d.ts +1 -0
  170. package/dist/types/models/google_llm.d.ts +0 -7
  171. package/dist/web/agents/active_streaming_tool.js +14 -0
  172. package/dist/web/agents/base_agent.js +265 -0
  173. package/dist/web/agents/base_llm_processor.js +13 -0
  174. package/dist/web/agents/callback_context.js +68 -0
  175. package/dist/web/agents/content_processor_utils.js +280 -0
  176. package/dist/web/agents/functions.js +384 -0
  177. package/dist/web/agents/instructions.js +80 -0
  178. package/dist/web/agents/invocation_context.js +76 -0
  179. package/dist/web/agents/live_request_queue.js +124 -0
  180. package/dist/web/agents/llm_agent.js +1377 -0
  181. package/dist/web/agents/loop_agent.js +71 -0
  182. package/dist/web/agents/parallel_agent.js +83 -0
  183. package/dist/web/agents/readonly_context.js +38 -0
  184. package/dist/web/agents/run_config.js +54 -0
  185. package/dist/web/agents/sequential_agent.js +99 -0
  186. package/dist/web/agents/transcription_entry.js +5 -0
  187. package/dist/web/artifacts/base_artifact_service.js +5 -0
  188. package/dist/web/artifacts/gcs_artifact_service.js +126 -0
  189. package/dist/web/artifacts/in_memory_artifact_service.js +89 -0
  190. package/dist/web/auth/auth_credential.js +16 -0
  191. package/dist/web/auth/auth_handler.js +62 -0
  192. package/dist/web/auth/auth_schemes.js +31 -0
  193. package/dist/web/auth/auth_tool.js +5 -0
  194. package/dist/web/auth/credential_service/base_credential_service.js +5 -0
  195. package/dist/web/auth/credential_service/in_memory_credential_service.js +33 -0
  196. package/dist/web/auth/exchanger/base_credential_exchanger.js +10 -0
  197. package/dist/web/auth/exchanger/credential_exchanger_registry.js +29 -0
  198. package/dist/web/code_executors/base_code_executor.js +46 -0
  199. package/dist/web/code_executors/built_in_code_executor.js +28 -0
  200. package/dist/web/code_executors/code_execution_utils.js +105 -0
  201. package/dist/web/code_executors/code_executor_context.js +168 -0
  202. package/dist/web/common.js +98 -0
  203. package/dist/web/events/event.js +101 -0
  204. package/dist/web/events/event_actions.js +67 -0
  205. package/dist/web/examples/base_example_provider.js +10 -0
  206. package/dist/web/examples/example.js +5 -0
  207. package/dist/web/examples/example_util.js +75 -0
  208. package/dist/web/index.js +1 -1
  209. package/dist/web/index.js.map +3 -3
  210. package/dist/web/index_web.js +6 -0
  211. package/dist/web/memory/base_memory_service.js +5 -0
  212. package/dist/web/memory/in_memory_memory_service.js +67 -0
  213. package/dist/web/memory/memory_entry.js +5 -0
  214. package/dist/web/models/base_llm.js +64 -0
  215. package/dist/web/models/base_llm_connection.js +5 -0
  216. package/dist/web/models/gemini_llm_connection.js +120 -0
  217. package/dist/web/models/google_llm.js +487 -0
  218. package/dist/web/models/llm_request.js +50 -0
  219. package/dist/web/models/llm_response.js +41 -0
  220. package/dist/web/models/registry.js +91 -0
  221. package/dist/web/plugins/base_plugin.js +206 -0
  222. package/dist/web/plugins/logging_plugin.js +192 -0
  223. package/dist/web/plugins/plugin_manager.js +209 -0
  224. package/dist/web/plugins/security_plugin.js +119 -0
  225. package/dist/web/runner/in_memory_runner.js +28 -0
  226. package/dist/web/runner/runner.js +278 -0
  227. package/dist/web/sessions/base_session_service.js +41 -0
  228. package/dist/web/sessions/in_memory_session_service.js +154 -0
  229. package/dist/web/sessions/session.js +18 -0
  230. package/dist/web/sessions/state.js +87 -0
  231. package/dist/web/telemetry/google_cloud.js +54 -0
  232. package/dist/web/telemetry/setup.js +67 -0
  233. package/dist/web/telemetry/tracing.js +210 -0
  234. package/dist/web/tools/agent_tool.js +118 -0
  235. package/dist/web/tools/base_tool.js +77 -0
  236. package/dist/web/tools/base_toolset.js +46 -0
  237. package/dist/web/tools/forwarding_artifact_service.js +41 -0
  238. package/dist/web/tools/function_tool.js +71 -0
  239. package/dist/web/tools/google_search_tool.js +47 -0
  240. package/dist/web/tools/long_running_tool.js +50 -0
  241. package/dist/web/tools/mcp/mcp_session_manager.js +35 -0
  242. package/dist/web/tools/mcp/mcp_tool.js +35 -0
  243. package/dist/web/tools/mcp/mcp_toolset.js +31 -0
  244. package/dist/web/tools/tool_confirmation.js +19 -0
  245. package/dist/web/tools/tool_context.js +99 -0
  246. package/dist/web/utils/client_labels.js +26 -0
  247. package/dist/web/utils/deep_clone.js +14 -0
  248. package/dist/web/utils/env_aware_utils.js +49 -0
  249. package/dist/web/utils/gemini_schema_util.js +58 -0
  250. package/dist/web/utils/logger.js +89 -0
  251. package/dist/web/utils/model_name.js +41 -0
  252. package/dist/web/utils/simple_zod_to_json.js +174 -0
  253. package/dist/web/utils/variant_utils.js +24 -0
  254. package/dist/web/version.js +9 -0
  255. package/package.json +1 -1
@@ -0,0 +1,1279 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 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 llm_agent_exports = {};
26
+ __export(llm_agent_exports, {
27
+ LlmAgent: () => LlmAgent,
28
+ REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR: () => REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR,
29
+ responseProcessor: () => responseProcessor
30
+ });
31
+ module.exports = __toCommonJS(llm_agent_exports);
32
+ var import_zod = require("zod");
33
+ var import_base_code_executor = require("../code_executors/base_code_executor.js");
34
+ var import_built_in_code_executor = require("../code_executors/built_in_code_executor.js");
35
+ var import_code_execution_utils = require("../code_executors/code_execution_utils.js");
36
+ var import_code_executor_context = require("../code_executors/code_executor_context.js");
37
+ var import_event = require("../events/event.js");
38
+ var import_event_actions = require("../events/event_actions.js");
39
+ var import_base_llm = require("../models/base_llm.js");
40
+ var import_llm_request = require("../models/llm_request.js");
41
+ var import_registry = require("../models/registry.js");
42
+ var import_state = require("../sessions/state.js");
43
+ var import_base_tool = require("../tools/base_tool.js");
44
+ var import_function_tool = require("../tools/function_tool.js");
45
+ var import_tool_confirmation = require("../tools/tool_confirmation.js");
46
+ var import_tool_context = require("../tools/tool_context.js");
47
+ var import_deep_clone = require("../utils/deep_clone.js");
48
+ var import_env_aware_utils = require("../utils/env_aware_utils.js");
49
+ var import_logger = require("../utils/logger.js");
50
+ var import_base_agent = require("./base_agent.js");
51
+ var import_base_llm_processor = require("./base_llm_processor.js");
52
+ var import_callback_context = require("./callback_context.js");
53
+ var import_content_processor_utils = require("./content_processor_utils.js");
54
+ var import_functions = require("./functions.js");
55
+ var import_instructions = require("./instructions.js");
56
+ var import_readonly_context = require("./readonly_context.js");
57
+ var import_run_config = require("./run_config.js");
58
+ /**
59
+ * @license
60
+ * Copyright 2025 Google LLC
61
+ * SPDX-License-Identifier: Apache-2.0
62
+ */
63
+ const ADK_AGENT_NAME_LABEL_KEY = "adk_agent_name";
64
+ async function convertToolUnionToTools(toolUnion, context) {
65
+ if (toolUnion instanceof import_base_tool.BaseTool) {
66
+ return [toolUnion];
67
+ }
68
+ return await toolUnion.getTools(context);
69
+ }
70
+ class BasicLlmRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
71
+ async *runAsync(invocationContext, llmRequest) {
72
+ var _a;
73
+ const agent = invocationContext.agent;
74
+ if (!(agent instanceof LlmAgent)) {
75
+ return;
76
+ }
77
+ llmRequest.model = agent.canonicalModel.model;
78
+ llmRequest.config = { ...(_a = agent.generateContentConfig) != null ? _a : {} };
79
+ if (agent.outputSchema) {
80
+ (0, import_llm_request.setOutputSchema)(llmRequest, agent.outputSchema);
81
+ }
82
+ if (invocationContext.runConfig) {
83
+ llmRequest.liveConnectConfig.responseModalities = invocationContext.runConfig.responseModalities;
84
+ llmRequest.liveConnectConfig.speechConfig = invocationContext.runConfig.speechConfig;
85
+ llmRequest.liveConnectConfig.outputAudioTranscription = invocationContext.runConfig.outputAudioTranscription;
86
+ llmRequest.liveConnectConfig.inputAudioTranscription = invocationContext.runConfig.inputAudioTranscription;
87
+ llmRequest.liveConnectConfig.realtimeInputConfig = invocationContext.runConfig.realtimeInputConfig;
88
+ llmRequest.liveConnectConfig.enableAffectiveDialog = invocationContext.runConfig.enableAffectiveDialog;
89
+ llmRequest.liveConnectConfig.proactivity = invocationContext.runConfig.proactivity;
90
+ }
91
+ }
92
+ }
93
+ const BASIC_LLM_REQUEST_PROCESSOR = new BasicLlmRequestProcessor();
94
+ class IdentityLlmRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
95
+ async *runAsync(invocationContext, llmRequest) {
96
+ const agent = invocationContext.agent;
97
+ const si = [`You are an agent. Your internal name is "${agent.name}".`];
98
+ if (agent.description) {
99
+ si.push(`The description about you is "${agent.description}"`);
100
+ }
101
+ (0, import_llm_request.appendInstructions)(llmRequest, si);
102
+ }
103
+ }
104
+ const IDENTITY_LLM_REQUEST_PROCESSOR = new IdentityLlmRequestProcessor();
105
+ class InstructionsLlmRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
106
+ /**
107
+ * Handles instructions and global instructions for LLM flow.
108
+ */
109
+ async *runAsync(invocationContext, llmRequest) {
110
+ const agent = invocationContext.agent;
111
+ if (!(agent instanceof LlmAgent) || !(agent.rootAgent instanceof LlmAgent)) {
112
+ return;
113
+ }
114
+ const rootAgent = agent.rootAgent;
115
+ if (rootAgent instanceof LlmAgent && rootAgent.globalInstruction) {
116
+ const { instruction, requireStateInjection } = await rootAgent.canonicalGlobalInstruction(
117
+ new import_readonly_context.ReadonlyContext(invocationContext)
118
+ );
119
+ let instructionWithState = instruction;
120
+ if (requireStateInjection) {
121
+ instructionWithState = await (0, import_instructions.injectSessionState)(
122
+ instruction,
123
+ new import_readonly_context.ReadonlyContext(invocationContext)
124
+ );
125
+ }
126
+ (0, import_llm_request.appendInstructions)(llmRequest, [instructionWithState]);
127
+ }
128
+ if (agent.instruction) {
129
+ const { instruction, requireStateInjection } = await agent.canonicalInstruction(
130
+ new import_readonly_context.ReadonlyContext(invocationContext)
131
+ );
132
+ let instructionWithState = instruction;
133
+ if (requireStateInjection) {
134
+ instructionWithState = await (0, import_instructions.injectSessionState)(
135
+ instruction,
136
+ new import_readonly_context.ReadonlyContext(invocationContext)
137
+ );
138
+ }
139
+ (0, import_llm_request.appendInstructions)(llmRequest, [instructionWithState]);
140
+ }
141
+ }
142
+ }
143
+ const INSTRUCTIONS_LLM_REQUEST_PROCESSOR = new InstructionsLlmRequestProcessor();
144
+ class ContentRequestProcessor {
145
+ async *runAsync(invocationContext, llmRequest) {
146
+ const agent = invocationContext.agent;
147
+ if (!agent || !(agent instanceof LlmAgent)) {
148
+ return;
149
+ }
150
+ if (agent.includeContents === "default") {
151
+ llmRequest.contents = (0, import_content_processor_utils.getContents)(
152
+ invocationContext.session.events,
153
+ agent.name,
154
+ invocationContext.branch
155
+ );
156
+ } else {
157
+ llmRequest.contents = (0, import_content_processor_utils.getCurrentTurnContents)(
158
+ invocationContext.session.events,
159
+ agent.name,
160
+ invocationContext.branch
161
+ );
162
+ }
163
+ return;
164
+ }
165
+ }
166
+ const CONTENT_REQUEST_PROCESSOR = new ContentRequestProcessor();
167
+ class AgentTransferLlmRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
168
+ constructor() {
169
+ super(...arguments);
170
+ this.toolName = "transfer_to_agent";
171
+ this.tool = new import_function_tool.FunctionTool({
172
+ name: this.toolName,
173
+ description: "Transfer the question to another agent. This tool hands off control to another agent when it is more suitable to answer the user question according to the agent description.",
174
+ parameters: import_zod.z.object({
175
+ agentName: import_zod.z.string().describe("the agent name to transfer to.")
176
+ }),
177
+ execute: function(args, toolContext) {
178
+ if (!toolContext) {
179
+ throw new Error("toolContext is required.");
180
+ }
181
+ toolContext.actions.transferToAgent = args.agentName;
182
+ return "Transfer queued";
183
+ }
184
+ });
185
+ }
186
+ async *runAsync(invocationContext, llmRequest) {
187
+ if (!(invocationContext.agent instanceof LlmAgent)) {
188
+ return;
189
+ }
190
+ const transferTargets = this.getTransferTargets(invocationContext.agent);
191
+ if (!transferTargets.length) {
192
+ return;
193
+ }
194
+ (0, import_llm_request.appendInstructions)(llmRequest, [
195
+ this.buildTargetAgentsInstructions(
196
+ invocationContext.agent,
197
+ transferTargets
198
+ )
199
+ ]);
200
+ const toolContext = new import_tool_context.ToolContext({ invocationContext });
201
+ await this.tool.processLlmRequest({ toolContext, llmRequest });
202
+ }
203
+ buildTargetAgentsInfo(targetAgent) {
204
+ return `
205
+ Agent name: ${targetAgent.name}
206
+ Agent description: ${targetAgent.description}
207
+ `;
208
+ }
209
+ buildTargetAgentsInstructions(agent, targetAgents) {
210
+ let instructions = `
211
+ You have a list of other agents to transfer to:
212
+
213
+ ${targetAgents.map(this.buildTargetAgentsInfo).join("\n")}
214
+
215
+ If you are the best to answer the question according to your description, you
216
+ can answer it.
217
+
218
+ If another agent is better for answering the question according to its
219
+ description, call \`${this.toolName}\` function to transfer the
220
+ question to that agent. When transferring, do not generate any text other than
221
+ the function call.
222
+ `;
223
+ if (agent.parentAgent && !agent.disallowTransferToParent) {
224
+ instructions += `
225
+ Your parent agent is ${agent.parentAgent.name}. If neither the other agents nor
226
+ you are best for answering the question according to the descriptions, transfer
227
+ to your parent agent.
228
+ `;
229
+ }
230
+ return instructions;
231
+ }
232
+ getTransferTargets(agent) {
233
+ const targets = [];
234
+ targets.push(...agent.subAgents);
235
+ if (!agent.parentAgent || !(agent.parentAgent instanceof LlmAgent)) {
236
+ return targets;
237
+ }
238
+ if (!agent.disallowTransferToParent) {
239
+ targets.push(agent.parentAgent);
240
+ }
241
+ if (!agent.disallowTransferToPeers) {
242
+ targets.push(
243
+ ...agent.parentAgent.subAgents.filter(
244
+ (peerAgent) => peerAgent.name !== agent.name
245
+ )
246
+ );
247
+ }
248
+ return targets;
249
+ }
250
+ }
251
+ const AGENT_TRANSFER_LLM_REQUEST_PROCESSOR = new AgentTransferLlmRequestProcessor();
252
+ class RequestConfirmationLlmRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
253
+ /** Handles tool confirmation information to build the LLM request. */
254
+ async *runAsync(invocationContext, llmRequest) {
255
+ const agent = invocationContext.agent;
256
+ if (!(agent instanceof LlmAgent)) {
257
+ return;
258
+ }
259
+ const events = invocationContext.session.events;
260
+ if (!events || events.length === 0) {
261
+ return;
262
+ }
263
+ const requestConfirmationFunctionResponses = {};
264
+ let confirmationEventIndex = -1;
265
+ for (let i = events.length - 1; i >= 0; i--) {
266
+ const event = events[i];
267
+ if (event.author !== "user") {
268
+ continue;
269
+ }
270
+ const responses = (0, import_event.getFunctionResponses)(event);
271
+ if (!responses) {
272
+ continue;
273
+ }
274
+ let foundConfirmation = false;
275
+ for (const functionResponse of responses) {
276
+ if (functionResponse.name !== import_functions.REQUEST_CONFIRMATION_FUNCTION_CALL_NAME) {
277
+ continue;
278
+ }
279
+ foundConfirmation = true;
280
+ let toolConfirmation = null;
281
+ if (functionResponse.response && Object.keys(functionResponse.response).length === 1 && "response" in functionResponse.response) {
282
+ toolConfirmation = JSON.parse(functionResponse.response["response"]);
283
+ } else if (functionResponse.response) {
284
+ toolConfirmation = new import_tool_confirmation.ToolConfirmation({
285
+ hint: functionResponse.response["hint"],
286
+ payload: functionResponse.response["payload"],
287
+ confirmed: functionResponse.response["confirmed"]
288
+ });
289
+ }
290
+ if (functionResponse.id && toolConfirmation) {
291
+ requestConfirmationFunctionResponses[functionResponse.id] = toolConfirmation;
292
+ }
293
+ }
294
+ if (foundConfirmation) {
295
+ confirmationEventIndex = i;
296
+ break;
297
+ }
298
+ }
299
+ if (Object.keys(requestConfirmationFunctionResponses).length === 0) {
300
+ return;
301
+ }
302
+ for (let i = confirmationEventIndex - 1; i >= 0; i--) {
303
+ const event = events[i];
304
+ const functionCalls = (0, import_event.getFunctionCalls)(event);
305
+ if (!functionCalls) {
306
+ continue;
307
+ }
308
+ const toolsToResumeWithConfirmation = {};
309
+ const toolsToResumeWithArgs = {};
310
+ for (const functionCall of functionCalls) {
311
+ if (!functionCall.id || !(functionCall.id in requestConfirmationFunctionResponses)) {
312
+ continue;
313
+ }
314
+ const args = functionCall.args;
315
+ if (!args || !("originalFunctionCall" in args)) {
316
+ continue;
317
+ }
318
+ const originalFunctionCall = args["originalFunctionCall"];
319
+ if (originalFunctionCall.id) {
320
+ toolsToResumeWithConfirmation[originalFunctionCall.id] = requestConfirmationFunctionResponses[functionCall.id];
321
+ toolsToResumeWithArgs[originalFunctionCall.id] = originalFunctionCall;
322
+ }
323
+ }
324
+ if (Object.keys(toolsToResumeWithConfirmation).length === 0) {
325
+ continue;
326
+ }
327
+ for (let j = events.length - 1; j > confirmationEventIndex; j--) {
328
+ const eventToCheck = events[j];
329
+ const functionResponses = (0, import_event.getFunctionResponses)(eventToCheck);
330
+ if (!functionResponses) {
331
+ continue;
332
+ }
333
+ for (const fr of functionResponses) {
334
+ if (fr.id && fr.id in toolsToResumeWithConfirmation) {
335
+ delete toolsToResumeWithConfirmation[fr.id];
336
+ delete toolsToResumeWithArgs[fr.id];
337
+ }
338
+ }
339
+ if (Object.keys(toolsToResumeWithConfirmation).length === 0) {
340
+ break;
341
+ }
342
+ }
343
+ if (Object.keys(toolsToResumeWithConfirmation).length === 0) {
344
+ continue;
345
+ }
346
+ const toolsList = await agent.canonicalTools(new import_readonly_context.ReadonlyContext(invocationContext));
347
+ const toolsDict = Object.fromEntries(toolsList.map((tool) => [tool.name, tool]));
348
+ const functionResponseEvent = await (0, import_functions.handleFunctionCallList)({
349
+ invocationContext,
350
+ functionCalls: Object.values(toolsToResumeWithArgs),
351
+ toolsDict,
352
+ beforeToolCallbacks: agent.canonicalBeforeToolCallbacks,
353
+ afterToolCallbacks: agent.canonicalAfterToolCallbacks,
354
+ filters: new Set(Object.keys(toolsToResumeWithConfirmation)),
355
+ toolConfirmationDict: toolsToResumeWithConfirmation
356
+ });
357
+ if (functionResponseEvent) {
358
+ yield functionResponseEvent;
359
+ }
360
+ return;
361
+ }
362
+ }
363
+ }
364
+ const REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR = new RequestConfirmationLlmRequestProcessor();
365
+ class CodeExecutionRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
366
+ async *runAsync(invocationContext, llmRequest) {
367
+ if (!(invocationContext.agent instanceof LlmAgent)) {
368
+ return;
369
+ }
370
+ if (!invocationContext.agent.codeExecutor) {
371
+ return;
372
+ }
373
+ for await (const event of runPreProcessor(invocationContext, llmRequest)) {
374
+ yield event;
375
+ }
376
+ if (!(invocationContext.agent.codeExecutor instanceof import_base_code_executor.BaseCodeExecutor)) {
377
+ return;
378
+ }
379
+ for (const content of llmRequest.contents) {
380
+ const delimeters = invocationContext.agent.codeExecutor.codeBlockDelimiters.length ? invocationContext.agent.codeExecutor.codeBlockDelimiters[0] : ["", ""];
381
+ const codeExecutionParts = (0, import_code_execution_utils.convertCodeExecutionParts)(
382
+ content,
383
+ delimeters,
384
+ invocationContext.agent.codeExecutor.executionResultDelimiters
385
+ );
386
+ }
387
+ }
388
+ }
389
+ const DATA_FILE_UTIL_MAP = {
390
+ "text/csv": {
391
+ extension: ".csv",
392
+ loaderCodeTemplate: "pd.read_csv('{filename}')"
393
+ }
394
+ };
395
+ const DATA_FILE_HELPER_LIB = `
396
+ import pandas as pd
397
+
398
+ def explore_df(df: pd.DataFrame) -> None:
399
+ """Prints some information about a pandas DataFrame."""
400
+
401
+ with pd.option_context(
402
+ 'display.max_columns', None, 'display.expand_frame_repr', False
403
+ ):
404
+ # Print the column names to never encounter KeyError when selecting one.
405
+ df_dtypes = df.dtypes
406
+
407
+ # Obtain information about data types and missing values.
408
+ df_nulls = (len(df) - df.isnull().sum()).apply(
409
+ lambda x: f'{x} / {df.shape[0]} non-null'
410
+ )
411
+
412
+ # Explore unique total values in columns using \`.unique()\`.
413
+ df_unique_count = df.apply(lambda x: len(x.unique()))
414
+
415
+ # Explore unique values in columns using \`.unique()\`.
416
+ df_unique = df.apply(lambda x: crop(str(list(x.unique()))))
417
+
418
+ df_info = pd.concat(
419
+ (
420
+ df_dtypes.rename('Dtype'),
421
+ df_nulls.rename('Non-Null Count'),
422
+ df_unique_count.rename('Unique Values Count'),
423
+ df_unique.rename('Unique Values'),
424
+ ),
425
+ axis=1,
426
+ )
427
+ df_info.index.name = 'Columns'
428
+ print(f"""Total rows: {df.shape[0]}
429
+ Total columns: {df.shape[1]}
430
+
431
+ {df_info}""")
432
+ `;
433
+ class CodeExecutionResponseProcessor {
434
+ /**
435
+ * Processes the LLM response asynchronously.
436
+ *
437
+ * @param invocationContext The invocation context
438
+ * @param llmResponse The LLM response to process
439
+ * @returns An async generator yielding events
440
+ */
441
+ async *runAsync(invocationContext, llmResponse) {
442
+ if (llmResponse.partial) {
443
+ return;
444
+ }
445
+ for await (const event of runPostProcessor(invocationContext, llmResponse)) {
446
+ yield event;
447
+ }
448
+ }
449
+ }
450
+ const responseProcessor = new CodeExecutionResponseProcessor();
451
+ async function* runPreProcessor(invocationContext, llmRequest) {
452
+ const agent = invocationContext.agent;
453
+ if (!(agent instanceof LlmAgent)) {
454
+ return;
455
+ }
456
+ const codeExecutor = agent.codeExecutor;
457
+ if (!codeExecutor || !(codeExecutor instanceof import_base_code_executor.BaseCodeExecutor)) {
458
+ return;
459
+ }
460
+ if (codeExecutor instanceof import_built_in_code_executor.BuiltInCodeExecutor) {
461
+ codeExecutor.processLlmRequest(llmRequest);
462
+ return;
463
+ }
464
+ if (!codeExecutor.optimizeDataFile) {
465
+ return;
466
+ }
467
+ const codeExecutorContext = new import_code_executor_context.CodeExecutorContext(new import_state.State(invocationContext.session.state));
468
+ if (codeExecutorContext.getErrorCount(invocationContext.invocationId) >= codeExecutor.errorRetryAttempts) {
469
+ return;
470
+ }
471
+ const allInputFiles = extractAndReplaceInlineFiles(codeExecutorContext, llmRequest);
472
+ const processedFileNames = new Set(codeExecutorContext.getProcessedFileNames());
473
+ const filesToProcess = allInputFiles.filter((f) => !processedFileNames.has(f.name));
474
+ for (const file of filesToProcess) {
475
+ const codeStr = getDataFilePreprocessingCode(file);
476
+ if (!codeStr) {
477
+ return;
478
+ }
479
+ const codeContent = {
480
+ role: "model",
481
+ parts: [
482
+ { text: `Processing input file: \`${file.name}\`` },
483
+ (0, import_code_execution_utils.buildExecutableCodePart)(codeStr)
484
+ ]
485
+ };
486
+ llmRequest.contents.push((0, import_deep_clone.deepClone)(codeContent));
487
+ yield (0, import_event.createEvent)({
488
+ invocationId: invocationContext.invocationId,
489
+ author: agent.name,
490
+ branch: invocationContext.branch,
491
+ content: codeContent
492
+ });
493
+ const executionId = getOrSetExecutionId(invocationContext, codeExecutorContext);
494
+ const codeExecutionResult = await codeExecutor.executeCode({
495
+ invocationContext,
496
+ codeExecutionInput: {
497
+ code: codeStr,
498
+ inputFiles: [file],
499
+ executionId
500
+ }
501
+ });
502
+ codeExecutorContext.updateCodeExecutionResult({
503
+ invocationId: invocationContext.invocationId,
504
+ code: codeStr,
505
+ resultStdout: codeExecutionResult.stdout,
506
+ resultStderr: codeExecutionResult.stderr
507
+ });
508
+ codeExecutorContext.addProcessedFileNames([file.name]);
509
+ const executionResultEvent = await postProcessCodeExecutionResult(
510
+ invocationContext,
511
+ codeExecutorContext,
512
+ codeExecutionResult
513
+ );
514
+ yield executionResultEvent;
515
+ llmRequest.contents.push((0, import_deep_clone.deepClone)(executionResultEvent.content));
516
+ }
517
+ }
518
+ async function* runPostProcessor(invocationContext, llmResponse) {
519
+ const agent = invocationContext.agent;
520
+ if (!(agent instanceof LlmAgent)) {
521
+ return;
522
+ }
523
+ const codeExecutor = agent.codeExecutor;
524
+ if (!codeExecutor || !(codeExecutor instanceof import_base_code_executor.BaseCodeExecutor)) {
525
+ return;
526
+ }
527
+ if (!llmResponse || !llmResponse.content) {
528
+ return;
529
+ }
530
+ if (codeExecutor instanceof import_built_in_code_executor.BuiltInCodeExecutor) {
531
+ return;
532
+ }
533
+ const codeExecutorContext = new import_code_executor_context.CodeExecutorContext(new import_state.State(invocationContext.session.state));
534
+ if (codeExecutorContext.getErrorCount(invocationContext.invocationId) >= codeExecutor.errorRetryAttempts) {
535
+ return;
536
+ }
537
+ const responseContent = llmResponse.content;
538
+ const codeStr = (0, import_code_execution_utils.extractCodeAndTruncateContent)(
539
+ responseContent,
540
+ codeExecutor.codeBlockDelimiters
541
+ );
542
+ if (!codeStr) {
543
+ return;
544
+ }
545
+ yield (0, import_event.createEvent)({
546
+ invocationId: invocationContext.invocationId,
547
+ author: agent.name,
548
+ branch: invocationContext.branch,
549
+ content: responseContent
550
+ });
551
+ const executionId = getOrSetExecutionId(invocationContext, codeExecutorContext);
552
+ const codeExecutionResult = await codeExecutor.executeCode({
553
+ invocationContext,
554
+ codeExecutionInput: {
555
+ code: codeStr,
556
+ inputFiles: codeExecutorContext.getInputFiles(),
557
+ executionId
558
+ }
559
+ });
560
+ codeExecutorContext.updateCodeExecutionResult({
561
+ invocationId: invocationContext.invocationId,
562
+ code: codeStr,
563
+ resultStdout: codeExecutionResult.stdout,
564
+ resultStderr: codeExecutionResult.stderr
565
+ });
566
+ yield await postProcessCodeExecutionResult(
567
+ invocationContext,
568
+ codeExecutorContext,
569
+ codeExecutionResult
570
+ );
571
+ llmResponse.content = null;
572
+ }
573
+ function extractAndReplaceInlineFiles(codeExecutorContext, llmRequest) {
574
+ var _a;
575
+ const allInputFiles = codeExecutorContext.getInputFiles();
576
+ const savedFileNames = new Set(allInputFiles.map((f) => f.name));
577
+ for (let i = 0; i < llmRequest.contents.length; i++) {
578
+ const content = llmRequest.contents[i];
579
+ if (content.role !== "user" || !content.parts) {
580
+ continue;
581
+ }
582
+ for (let j = 0; j < content.parts.length; j++) {
583
+ const part = content.parts[j];
584
+ const mimeType = (_a = part.inlineData) == null ? void 0 : _a.mimeType;
585
+ if (!mimeType || !part.inlineData || !DATA_FILE_UTIL_MAP[mimeType]) {
586
+ continue;
587
+ }
588
+ const fileName = `data_${i + 1}_${j + 1}${DATA_FILE_UTIL_MAP[mimeType].extension}`;
589
+ part.text = `
590
+ Available file: \`${fileName}\`
591
+ `;
592
+ const file = {
593
+ name: fileName,
594
+ content: (0, import_env_aware_utils.base64Decode)(part.inlineData.data),
595
+ mimeType
596
+ };
597
+ if (!savedFileNames.has(fileName)) {
598
+ codeExecutorContext.addInputFiles([file]);
599
+ allInputFiles.push(file);
600
+ }
601
+ }
602
+ }
603
+ return allInputFiles;
604
+ }
605
+ function getOrSetExecutionId(invocationContext, codeExecutorContext) {
606
+ var _a;
607
+ const agent = invocationContext.agent;
608
+ if (!(agent instanceof LlmAgent) || !((_a = agent.codeExecutor) == null ? void 0 : _a.stateful)) {
609
+ return void 0;
610
+ }
611
+ let executionId = codeExecutorContext.getExecutionId();
612
+ if (!executionId) {
613
+ executionId = invocationContext.session.id;
614
+ codeExecutorContext.setExecutionId(executionId);
615
+ }
616
+ return executionId;
617
+ }
618
+ async function postProcessCodeExecutionResult(invocationContext, codeExecutorContext, codeExecutionResult) {
619
+ if (!invocationContext.artifactService) {
620
+ throw new Error("Artifact service is not initialized.");
621
+ }
622
+ const resultContent = {
623
+ role: "model",
624
+ parts: [(0, import_code_execution_utils.buildCodeExecutionResultPart)(codeExecutionResult)]
625
+ };
626
+ const eventActions = (0, import_event_actions.createEventActions)({ stateDelta: codeExecutorContext.getStateDelta() });
627
+ if (codeExecutionResult.stderr) {
628
+ codeExecutorContext.incrementErrorCount(invocationContext.invocationId);
629
+ } else {
630
+ codeExecutorContext.resetErrorCount(invocationContext.invocationId);
631
+ }
632
+ for (const outputFile of codeExecutionResult.outputFiles) {
633
+ const version = await invocationContext.artifactService.saveArtifact({
634
+ appName: invocationContext.appName || "",
635
+ userId: invocationContext.userId || "",
636
+ sessionId: invocationContext.session.id,
637
+ filename: outputFile.name,
638
+ artifact: {
639
+ inlineData: { data: outputFile.content, mimeType: outputFile.mimeType }
640
+ }
641
+ });
642
+ eventActions.artifactDelta[outputFile.name] = version;
643
+ }
644
+ return (0, import_event.createEvent)({
645
+ invocationId: invocationContext.invocationId,
646
+ author: invocationContext.agent.name,
647
+ branch: invocationContext.branch,
648
+ content: resultContent,
649
+ actions: eventActions
650
+ });
651
+ }
652
+ function getDataFilePreprocessingCode(file) {
653
+ function getNormalizedFileName(fileName) {
654
+ const [varName2] = fileName.split(".");
655
+ let normalizedName = varName2.replace(/[^a-zA-Z0-9_]/g, "_");
656
+ if (/^\d/.test(normalizedName)) {
657
+ normalizedName = "_" + normalizedName;
658
+ }
659
+ return normalizedName;
660
+ }
661
+ if (!DATA_FILE_UTIL_MAP[file.mimeType]) {
662
+ return void 0;
663
+ }
664
+ const varName = getNormalizedFileName(file.name);
665
+ const loaderCode = DATA_FILE_UTIL_MAP[file.mimeType].loaderCodeTemplate.replace(
666
+ "{filename}",
667
+ file.name
668
+ );
669
+ return `
670
+ ${DATA_FILE_HELPER_LIB}
671
+
672
+ # Load the dataframe.
673
+ ${varName} = ${loaderCode}
674
+
675
+ # Use \`explore_df\` to guide my analysis.
676
+ explore_df(${varName})
677
+ `;
678
+ }
679
+ const CODE_EXECUTION_REQUEST_PROCESSOR = new CodeExecutionRequestProcessor();
680
+ const _LlmAgent = class _LlmAgent extends import_base_agent.BaseAgent {
681
+ constructor(config) {
682
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
683
+ super(config);
684
+ this.model = config.model;
685
+ this.instruction = (_a = config.instruction) != null ? _a : "";
686
+ this.globalInstruction = (_b = config.globalInstruction) != null ? _b : "";
687
+ this.tools = (_c = config.tools) != null ? _c : [];
688
+ this.generateContentConfig = config.generateContentConfig;
689
+ this.disallowTransferToParent = (_d = config.disallowTransferToParent) != null ? _d : false;
690
+ this.disallowTransferToPeers = (_e = config.disallowTransferToPeers) != null ? _e : false;
691
+ this.includeContents = (_f = config.includeContents) != null ? _f : "default";
692
+ this.inputSchema = config.inputSchema;
693
+ this.outputSchema = config.outputSchema;
694
+ this.outputKey = config.outputKey;
695
+ this.beforeModelCallback = config.beforeModelCallback;
696
+ this.afterModelCallback = config.afterModelCallback;
697
+ this.beforeToolCallback = config.beforeToolCallback;
698
+ this.afterToolCallback = config.afterToolCallback;
699
+ this.codeExecutor = config.codeExecutor;
700
+ this.requestProcessors = (_g = config.requestProcessors) != null ? _g : [
701
+ BASIC_LLM_REQUEST_PROCESSOR,
702
+ IDENTITY_LLM_REQUEST_PROCESSOR,
703
+ INSTRUCTIONS_LLM_REQUEST_PROCESSOR,
704
+ REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR,
705
+ CONTENT_REQUEST_PROCESSOR,
706
+ CODE_EXECUTION_REQUEST_PROCESSOR
707
+ ];
708
+ this.responseProcessors = (_h = config.responseProcessors) != null ? _h : [];
709
+ const agentTransferDisabled = this.disallowTransferToParent && this.disallowTransferToPeers && !((_i = this.subAgents) == null ? void 0 : _i.length);
710
+ if (!agentTransferDisabled) {
711
+ this.requestProcessors.push(AGENT_TRANSFER_LLM_REQUEST_PROCESSOR);
712
+ }
713
+ if (config.generateContentConfig) {
714
+ if (config.generateContentConfig.tools) {
715
+ throw new Error("All tools must be set via LlmAgent.tools.");
716
+ }
717
+ if (config.generateContentConfig.systemInstruction) {
718
+ throw new Error(
719
+ "System instruction must be set via LlmAgent.instruction."
720
+ );
721
+ }
722
+ if (config.generateContentConfig.responseSchema) {
723
+ throw new Error(
724
+ "Response schema must be set via LlmAgent.output_schema."
725
+ );
726
+ }
727
+ } else {
728
+ this.generateContentConfig = {};
729
+ }
730
+ if (this.outputSchema) {
731
+ if (!this.disallowTransferToParent || !this.disallowTransferToPeers) {
732
+ import_logger.logger.warn(
733
+ `Invalid config for agent ${this.name}: outputSchema cannot co-exist with agent transfer configurations. Setting disallowTransferToParent=true, disallowTransferToPeers=true`
734
+ );
735
+ this.disallowTransferToParent = true;
736
+ this.disallowTransferToPeers = true;
737
+ }
738
+ if (this.subAgents && this.subAgents.length > 0) {
739
+ throw new Error(
740
+ `Invalid config for agent ${this.name}: if outputSchema is set, subAgents must be empty to disable agent transfer.`
741
+ );
742
+ }
743
+ if (this.tools && this.tools.length > 0) {
744
+ throw new Error(
745
+ `Invalid config for agent ${this.name}: if outputSchema is set, tools must be empty`
746
+ );
747
+ }
748
+ }
749
+ }
750
+ /**
751
+ * The resolved BaseLlm instance.
752
+ *
753
+ * When not set, the agent will inherit the model from its ancestor.
754
+ */
755
+ get canonicalModel() {
756
+ if ((0, import_base_llm.isBaseLlm)(this.model)) {
757
+ return this.model;
758
+ }
759
+ if (typeof this.model === "string" && this.model) {
760
+ return import_registry.LLMRegistry.newLlm(this.model);
761
+ }
762
+ let ancestorAgent = this.parentAgent;
763
+ while (ancestorAgent) {
764
+ if (ancestorAgent instanceof _LlmAgent) {
765
+ return ancestorAgent.canonicalModel;
766
+ }
767
+ ancestorAgent = ancestorAgent.parentAgent;
768
+ }
769
+ throw new Error(`No model found for ${this.name}.`);
770
+ }
771
+ /**
772
+ * The resolved self.instruction field to construct instruction for this
773
+ * agent.
774
+ *
775
+ * This method is only for use by Agent Development Kit.
776
+ * @param context The context to retrieve the session state.
777
+ * @returns The resolved self.instruction field.
778
+ */
779
+ async canonicalInstruction(context) {
780
+ if (typeof this.instruction === "string") {
781
+ return { instruction: this.instruction, requireStateInjection: true };
782
+ }
783
+ return {
784
+ instruction: await this.instruction(context),
785
+ requireStateInjection: false
786
+ };
787
+ }
788
+ /**
789
+ * The resolved self.instruction field to construct global instruction.
790
+ *
791
+ * This method is only for use by Agent Development Kit.
792
+ * @param context The context to retrieve the session state.
793
+ * @returns The resolved self.global_instruction field.
794
+ */
795
+ async canonicalGlobalInstruction(context) {
796
+ if (typeof this.globalInstruction === "string") {
797
+ return { instruction: this.globalInstruction, requireStateInjection: true };
798
+ }
799
+ return {
800
+ instruction: await this.globalInstruction(context),
801
+ requireStateInjection: false
802
+ };
803
+ }
804
+ /**
805
+ * The resolved self.tools field as a list of BaseTool based on the context.
806
+ *
807
+ * This method is only for use by Agent Development Kit.
808
+ */
809
+ async canonicalTools(context) {
810
+ const resolvedTools = [];
811
+ for (const toolUnion of this.tools) {
812
+ const tools = await convertToolUnionToTools(toolUnion, context);
813
+ resolvedTools.push(...tools);
814
+ }
815
+ return resolvedTools;
816
+ }
817
+ /**
818
+ * Normalizes a callback or an array of callbacks into an array of callbacks.
819
+ *
820
+ * @param callback The callback or an array of callbacks.
821
+ * @returns An array of callbacks.
822
+ */
823
+ static normalizeCallbackArray(callback) {
824
+ if (!callback) {
825
+ return [];
826
+ }
827
+ if (Array.isArray(callback)) {
828
+ return callback;
829
+ }
830
+ return [callback];
831
+ }
832
+ /**
833
+ * The resolved self.before_model_callback field as a list of
834
+ * SingleBeforeModelCallback.
835
+ *
836
+ * This method is only for use by Agent Development Kit.
837
+ */
838
+ get canonicalBeforeModelCallbacks() {
839
+ return _LlmAgent.normalizeCallbackArray(this.beforeModelCallback);
840
+ }
841
+ /**
842
+ * The resolved self.after_model_callback field as a list of
843
+ * SingleAfterModelCallback.
844
+ *
845
+ * This method is only for use by Agent Development Kit.
846
+ */
847
+ get canonicalAfterModelCallbacks() {
848
+ return _LlmAgent.normalizeCallbackArray(this.afterModelCallback);
849
+ }
850
+ /**
851
+ * The resolved self.before_tool_callback field as a list of
852
+ * BeforeToolCallback.
853
+ *
854
+ * This method is only for use by Agent Development Kit.
855
+ */
856
+ get canonicalBeforeToolCallbacks() {
857
+ return _LlmAgent.normalizeCallbackArray(this.beforeToolCallback);
858
+ }
859
+ /**
860
+ * The resolved self.after_tool_callback field as a list of AfterToolCallback.
861
+ *
862
+ * This method is only for use by Agent Development Kit.
863
+ */
864
+ get canonicalAfterToolCallbacks() {
865
+ return _LlmAgent.normalizeCallbackArray(this.afterToolCallback);
866
+ }
867
+ /**
868
+ * Saves the agent's final response to the session state if configured.
869
+ *
870
+ * It extracts the text content from the final response event, optionally
871
+ * parses it as JSON based on the output schema, and stores the result in the
872
+ * session state using the specified output key.
873
+ *
874
+ * @param event The event to process.
875
+ */
876
+ maybeSaveOutputToState(event) {
877
+ var _a, _b;
878
+ if (event.author !== this.name) {
879
+ import_logger.logger.debug(
880
+ `Skipping output save for agent ${this.name}: event authored by ${event.author}`
881
+ );
882
+ return;
883
+ }
884
+ if (!this.outputKey) {
885
+ import_logger.logger.debug(
886
+ `Skipping output save for agent ${this.name}: outputKey is not set`
887
+ );
888
+ return;
889
+ }
890
+ if (!(0, import_event.isFinalResponse)(event)) {
891
+ import_logger.logger.debug(
892
+ `Skipping output save for agent ${this.name}: event is not a final response`
893
+ );
894
+ return;
895
+ }
896
+ if (!((_b = (_a = event.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.length)) {
897
+ import_logger.logger.debug(
898
+ `Skipping output save for agent ${this.name}: event content is empty`
899
+ );
900
+ return;
901
+ }
902
+ const resultStr = event.content.parts.map((part) => part.text ? part.text : "").join("");
903
+ let result = resultStr;
904
+ if (this.outputSchema) {
905
+ if (!resultStr.trim()) {
906
+ return;
907
+ }
908
+ try {
909
+ result = JSON.parse(resultStr);
910
+ } catch (e) {
911
+ import_logger.logger.error(`Error parsing output for agent ${this.name}`, e);
912
+ }
913
+ }
914
+ event.actions.stateDelta[this.outputKey] = result;
915
+ }
916
+ async *runAsyncImpl(context) {
917
+ var _a, _b;
918
+ let consecutiveErrors = 0;
919
+ while (true) {
920
+ let lastEvent = void 0;
921
+ for await (const event of this.runOneStepAsync(context)) {
922
+ lastEvent = event;
923
+ this.maybeSaveOutputToState(event);
924
+ yield event;
925
+ }
926
+ if (!lastEvent) {
927
+ break;
928
+ }
929
+ if (lastEvent.errorCode && !((_b = (_a = lastEvent.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.length)) {
930
+ consecutiveErrors++;
931
+ if (consecutiveErrors <= _LlmAgent.MAX_AGENT_LOOP_ERROR_RETRIES) {
932
+ import_logger.logger.warn(
933
+ `[runAsyncImpl] Error event (${lastEvent.errorCode}), retrying agent loop (${consecutiveErrors}/${_LlmAgent.MAX_AGENT_LOOP_ERROR_RETRIES})`
934
+ );
935
+ continue;
936
+ }
937
+ import_logger.logger.error(
938
+ `[runAsyncImpl] Max agent-loop error retries exhausted for ${lastEvent.errorCode}`
939
+ );
940
+ break;
941
+ }
942
+ consecutiveErrors = 0;
943
+ if ((0, import_event.isFinalResponse)(lastEvent)) {
944
+ break;
945
+ }
946
+ if (lastEvent.partial) {
947
+ import_logger.logger.warn("The last event is partial, which is not expected.");
948
+ break;
949
+ }
950
+ }
951
+ }
952
+ async *runLiveImpl(context) {
953
+ for await (const event of this.runLiveFlow(context)) {
954
+ this.maybeSaveOutputToState(event);
955
+ yield event;
956
+ }
957
+ if (context.endInvocation) {
958
+ return;
959
+ }
960
+ }
961
+ // --------------------------------------------------------------------------
962
+ // #START LlmFlow Logic
963
+ // --------------------------------------------------------------------------
964
+ async *runLiveFlow(invocationContext) {
965
+ await Promise.resolve();
966
+ throw new Error("LlmAgent.runLiveFlow not implemented");
967
+ }
968
+ async *runOneStepAsync(invocationContext) {
969
+ const llmRequest = {
970
+ contents: [],
971
+ toolsDict: {},
972
+ liveConnectConfig: {}
973
+ };
974
+ for (const processor of this.requestProcessors) {
975
+ for await (const event of processor.runAsync(invocationContext, llmRequest)) {
976
+ yield event;
977
+ }
978
+ }
979
+ for (const toolUnion of this.tools) {
980
+ const toolContext = new import_tool_context.ToolContext({ invocationContext });
981
+ const tools = await convertToolUnionToTools(
982
+ toolUnion,
983
+ new import_readonly_context.ReadonlyContext(invocationContext)
984
+ );
985
+ for (const tool of tools) {
986
+ await tool.processLlmRequest({ toolContext, llmRequest });
987
+ }
988
+ }
989
+ if (invocationContext.endInvocation) {
990
+ return;
991
+ }
992
+ const modelResponseEvent = (0, import_event.createEvent)({
993
+ invocationId: invocationContext.invocationId,
994
+ author: this.name,
995
+ branch: invocationContext.branch
996
+ });
997
+ for await (const llmResponse of this.callLlmAsync(
998
+ invocationContext,
999
+ llmRequest,
1000
+ modelResponseEvent
1001
+ )) {
1002
+ try {
1003
+ for await (const event of this.postprocess(
1004
+ invocationContext,
1005
+ llmRequest,
1006
+ llmResponse,
1007
+ modelResponseEvent
1008
+ )) {
1009
+ modelResponseEvent.id = (0, import_event.createNewEventId)();
1010
+ modelResponseEvent.timestamp = (/* @__PURE__ */ new Date()).getTime();
1011
+ yield event;
1012
+ }
1013
+ } catch (postprocessError) {
1014
+ const errMsg = postprocessError instanceof Error ? postprocessError.message : String(postprocessError);
1015
+ import_logger.logger.error(`Postprocess error: ${errMsg}`);
1016
+ yield (0, import_event.createEvent)({
1017
+ invocationId: invocationContext.invocationId,
1018
+ author: this.name,
1019
+ branch: invocationContext.branch,
1020
+ errorCode: "POSTPROCESS_ERROR",
1021
+ errorMessage: errMsg
1022
+ });
1023
+ }
1024
+ }
1025
+ }
1026
+ async *postprocess(invocationContext, llmRequest, llmResponse, modelResponseEvent) {
1027
+ var _a, _b;
1028
+ for (const processor of this.responseProcessors) {
1029
+ for await (const event of processor.runAsync(invocationContext, llmResponse)) {
1030
+ yield event;
1031
+ }
1032
+ }
1033
+ if (!llmResponse.content && !llmResponse.errorCode && !llmResponse.interrupted) {
1034
+ return;
1035
+ }
1036
+ const mergedEvent = (0, import_event.createEvent)({
1037
+ ...modelResponseEvent,
1038
+ ...llmResponse
1039
+ });
1040
+ if (mergedEvent.content) {
1041
+ const functionCalls = (0, import_event.getFunctionCalls)(mergedEvent);
1042
+ if (functionCalls == null ? void 0 : functionCalls.length) {
1043
+ (0, import_functions.populateClientFunctionCallId)(mergedEvent);
1044
+ mergedEvent.longRunningToolIds = Array.from(
1045
+ (0, import_functions.getLongRunningFunctionCalls)(functionCalls, llmRequest.toolsDict)
1046
+ );
1047
+ const hasSignature = (_a = mergedEvent.content.parts) == null ? void 0 : _a.some(
1048
+ (p) => p.thoughtSignature
1049
+ );
1050
+ if (!hasSignature) {
1051
+ import_logger.logger.warn(
1052
+ `[postprocess] Function calls (${functionCalls.length}) without thoughtSignature`
1053
+ );
1054
+ }
1055
+ }
1056
+ }
1057
+ yield mergedEvent;
1058
+ if (!((_b = (0, import_event.getFunctionCalls)(mergedEvent)) == null ? void 0 : _b.length)) {
1059
+ return;
1060
+ }
1061
+ const functionResponseEvent = await (0, import_functions.handleFunctionCallsAsync)({
1062
+ invocationContext,
1063
+ functionCallEvent: mergedEvent,
1064
+ toolsDict: llmRequest.toolsDict,
1065
+ beforeToolCallbacks: this.canonicalBeforeToolCallbacks,
1066
+ afterToolCallbacks: this.canonicalAfterToolCallbacks
1067
+ });
1068
+ if (!functionResponseEvent) {
1069
+ return;
1070
+ }
1071
+ const authEvent = (0, import_functions.generateAuthEvent)(invocationContext, functionResponseEvent);
1072
+ if (authEvent) {
1073
+ yield authEvent;
1074
+ }
1075
+ const toolConfirmationEvent = (0, import_functions.generateRequestConfirmationEvent)({
1076
+ invocationContext,
1077
+ functionCallEvent: mergedEvent,
1078
+ functionResponseEvent
1079
+ });
1080
+ if (toolConfirmationEvent) {
1081
+ yield toolConfirmationEvent;
1082
+ }
1083
+ yield functionResponseEvent;
1084
+ const nextAgentName = functionResponseEvent.actions.transferToAgent;
1085
+ if (nextAgentName) {
1086
+ const nextAgent = this.getAgentByName(invocationContext, nextAgentName);
1087
+ for await (const event of nextAgent.runAsync(invocationContext)) {
1088
+ yield event;
1089
+ }
1090
+ }
1091
+ }
1092
+ /**
1093
+ * Retrieves an agent from the agent tree by its name.
1094
+ *
1095
+ * Performing a depth-first search to locate the agent with the given name.
1096
+ * - Starts searching from the root agent of the current invocation context.
1097
+ * - Traverses down the agent tree to find the specified agent.
1098
+ *
1099
+ * @param invocationContext The current invocation context.
1100
+ * @param agentName The name of the agent to retrieve.
1101
+ * @returns The agent with the given name.
1102
+ * @throws Error if the agent is not found.
1103
+ */
1104
+ getAgentByName(invocationContext, agentName) {
1105
+ const rootAgent = invocationContext.agent.rootAgent;
1106
+ const agentToRun = rootAgent.findAgent(agentName);
1107
+ if (!agentToRun) {
1108
+ throw new Error(`Agent ${agentName} not found in the agent tree.`);
1109
+ }
1110
+ return agentToRun;
1111
+ }
1112
+ async *callLlmAsync(invocationContext, llmRequest, modelResponseEvent) {
1113
+ var _a, _b, _c, _d, _e;
1114
+ const beforeModelResponse = await this.handleBeforeModelCallback(
1115
+ invocationContext,
1116
+ llmRequest,
1117
+ modelResponseEvent
1118
+ );
1119
+ if (beforeModelResponse) {
1120
+ yield beforeModelResponse;
1121
+ return;
1122
+ }
1123
+ (_a = llmRequest.config) != null ? _a : llmRequest.config = {};
1124
+ (_c = (_b = llmRequest.config).labels) != null ? _c : _b.labels = {};
1125
+ if (!llmRequest.config.labels[ADK_AGENT_NAME_LABEL_KEY]) {
1126
+ llmRequest.config.labels[ADK_AGENT_NAME_LABEL_KEY] = this.name;
1127
+ }
1128
+ const llm = this.canonicalModel;
1129
+ if ((_d = invocationContext.runConfig) == null ? void 0 : _d.supportCfc) {
1130
+ throw new Error("CFC is not yet supported in callLlmAsync");
1131
+ } else {
1132
+ invocationContext.incrementLlmCallCount();
1133
+ const isStreaming = ((_e = invocationContext.runConfig) == null ? void 0 : _e.streamingMode) === import_run_config.StreamingMode.SSE;
1134
+ const maxRetries = _LlmAgent.LLM_TRANSIENT_ERROR_MAX_RETRIES;
1135
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
1136
+ if (attempt > 0) {
1137
+ const delay = Math.min(
1138
+ _LlmAgent.LLM_TRANSIENT_ERROR_BASE_DELAY_MS * Math.pow(2, attempt - 1),
1139
+ _LlmAgent.LLM_TRANSIENT_ERROR_MAX_DELAY_MS
1140
+ );
1141
+ import_logger.logger.warn(
1142
+ `[callLlmAsync] Retrying LLM call after transient error (attempt ${attempt + 1}/${maxRetries + 1}), waiting ${delay}ms`
1143
+ );
1144
+ await new Promise((resolve) => setTimeout(resolve, delay));
1145
+ }
1146
+ const responsesGenerator = llm.generateContentAsync(
1147
+ llmRequest,
1148
+ isStreaming
1149
+ );
1150
+ let shouldRetry = false;
1151
+ let contentYielded = false;
1152
+ for await (const llmResponse of this.runAndHandleError(
1153
+ responsesGenerator,
1154
+ invocationContext,
1155
+ llmRequest,
1156
+ modelResponseEvent
1157
+ )) {
1158
+ if (llmResponse.content) {
1159
+ contentYielded = true;
1160
+ }
1161
+ if (llmResponse.errorCode && _LlmAgent.LLM_RETRYABLE_ERROR_CODES.has(llmResponse.errorCode) && !contentYielded && attempt < maxRetries) {
1162
+ shouldRetry = true;
1163
+ import_logger.logger.warn(
1164
+ `[callLlmAsync] Transient LLM error: ${llmResponse.errorCode}, usage: ${JSON.stringify(llmResponse.usageMetadata)}`
1165
+ );
1166
+ break;
1167
+ }
1168
+ const alteredLlmResponse = await this.handleAfterModelCallback(
1169
+ invocationContext,
1170
+ llmResponse,
1171
+ modelResponseEvent
1172
+ );
1173
+ yield alteredLlmResponse != null ? alteredLlmResponse : llmResponse;
1174
+ }
1175
+ if (!shouldRetry) {
1176
+ return;
1177
+ }
1178
+ }
1179
+ }
1180
+ }
1181
+ async handleBeforeModelCallback(invocationContext, llmRequest, modelResponseEvent) {
1182
+ const callbackContext = new import_callback_context.CallbackContext(
1183
+ { invocationContext, eventActions: modelResponseEvent.actions }
1184
+ );
1185
+ const beforeModelCallbackResponse = await invocationContext.pluginManager.runBeforeModelCallback(
1186
+ { callbackContext, llmRequest }
1187
+ );
1188
+ if (beforeModelCallbackResponse) {
1189
+ return beforeModelCallbackResponse;
1190
+ }
1191
+ for (const callback of this.canonicalBeforeModelCallbacks) {
1192
+ const callbackResponse = await callback({ context: callbackContext, request: llmRequest });
1193
+ if (callbackResponse) {
1194
+ return callbackResponse;
1195
+ }
1196
+ }
1197
+ return void 0;
1198
+ }
1199
+ async handleAfterModelCallback(invocationContext, llmResponse, modelResponseEvent) {
1200
+ const callbackContext = new import_callback_context.CallbackContext(
1201
+ { invocationContext, eventActions: modelResponseEvent.actions }
1202
+ );
1203
+ const afterModelCallbackResponse = await invocationContext.pluginManager.runAfterModelCallback(
1204
+ { callbackContext, llmResponse }
1205
+ );
1206
+ if (afterModelCallbackResponse) {
1207
+ return afterModelCallbackResponse;
1208
+ }
1209
+ for (const callback of this.canonicalAfterModelCallbacks) {
1210
+ const callbackResponse = await callback({ context: callbackContext, response: llmResponse });
1211
+ if (callbackResponse) {
1212
+ return callbackResponse;
1213
+ }
1214
+ }
1215
+ return void 0;
1216
+ }
1217
+ async *runAndHandleError(responseGenerator, invocationContext, llmRequest, modelResponseEvent) {
1218
+ try {
1219
+ for await (const response of responseGenerator) {
1220
+ yield response;
1221
+ }
1222
+ } catch (modelError) {
1223
+ const callbackContext = new import_callback_context.CallbackContext(
1224
+ { invocationContext, eventActions: modelResponseEvent.actions }
1225
+ );
1226
+ if (modelError instanceof Error) {
1227
+ const onModelErrorCallbackResponse = await invocationContext.pluginManager.runOnModelErrorCallback({
1228
+ callbackContext,
1229
+ llmRequest,
1230
+ error: modelError
1231
+ });
1232
+ if (onModelErrorCallbackResponse) {
1233
+ yield onModelErrorCallbackResponse;
1234
+ } else {
1235
+ try {
1236
+ const errorResponse = JSON.parse(modelError.message);
1237
+ yield {
1238
+ errorCode: String(errorResponse.error.code),
1239
+ errorMessage: errorResponse.error.message
1240
+ };
1241
+ } catch {
1242
+ import_logger.logger.warn(
1243
+ `LLM error message is not valid JSON, using raw message: ${modelError.message.substring(0, 200)}`
1244
+ );
1245
+ yield {
1246
+ errorCode: "UNKNOWN_ERROR",
1247
+ errorMessage: modelError.message
1248
+ };
1249
+ }
1250
+ }
1251
+ } else {
1252
+ import_logger.logger.error("Unknown error during response generation", modelError);
1253
+ throw modelError;
1254
+ }
1255
+ }
1256
+ }
1257
+ // --------------------------------------------------------------------------
1258
+ // #END LlmFlow Logic
1259
+ // --------------------------------------------------------------------------
1260
+ // TODO - b/425992518: omitted Py LlmAgent features.
1261
+ // - code_executor
1262
+ // - configurable agents by yaml config
1263
+ };
1264
+ _LlmAgent.MAX_AGENT_LOOP_ERROR_RETRIES = 2;
1265
+ _LlmAgent.LLM_TRANSIENT_ERROR_MAX_RETRIES = 2;
1266
+ _LlmAgent.LLM_TRANSIENT_ERROR_BASE_DELAY_MS = 1e3;
1267
+ _LlmAgent.LLM_TRANSIENT_ERROR_MAX_DELAY_MS = 4e3;
1268
+ _LlmAgent.LLM_RETRYABLE_ERROR_CODES = /* @__PURE__ */ new Set([
1269
+ "UNKNOWN_ERROR",
1270
+ "UNEXPECTED_TOOL_CALL",
1271
+ "MALFORMED_FUNCTION_CALL"
1272
+ ]);
1273
+ let LlmAgent = _LlmAgent;
1274
+ // Annotate the CommonJS export names for ESM import in node:
1275
+ 0 && (module.exports = {
1276
+ LlmAgent,
1277
+ REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR,
1278
+ responseProcessor
1279
+ });