@google/adk 0.2.4 → 0.3.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 (191) hide show
  1. package/dist/cjs/agents/base_agent.js +52 -24
  2. package/dist/cjs/agents/callback_context.js +4 -1
  3. package/dist/cjs/agents/content_processor_utils.js +15 -7
  4. package/dist/cjs/agents/functions.js +79 -29
  5. package/dist/cjs/agents/invocation_context.js +3 -1
  6. package/dist/cjs/agents/llm_agent.js +188 -108
  7. package/dist/cjs/agents/loop_agent.js +18 -6
  8. package/dist/cjs/agents/parallel_agent.js +20 -7
  9. package/dist/cjs/agents/readonly_context.js +4 -1
  10. package/dist/cjs/agents/sequential_agent.js +34 -12
  11. package/dist/cjs/artifacts/gcs_artifact_service.js +28 -20
  12. package/dist/cjs/artifacts/in_memory_artifact_service.js +18 -4
  13. package/dist/cjs/auth/auth_handler.js +3 -1
  14. package/dist/cjs/code_executors/base_code_executor.js +14 -2
  15. package/dist/cjs/code_executors/built_in_code_executor.js +21 -5
  16. package/dist/cjs/code_executors/code_executor_context.js +5 -5
  17. package/dist/cjs/common.js +45 -0
  18. package/dist/cjs/events/event.js +1 -3
  19. package/dist/cjs/examples/base_example_provider.js +18 -2
  20. package/dist/cjs/examples/example_util.js +1 -1
  21. package/dist/cjs/index.js +19 -19
  22. package/dist/cjs/index.js.map +4 -4
  23. package/dist/cjs/memory/in_memory_memory_service.js +3 -1
  24. package/dist/cjs/models/base_llm.js +8 -4
  25. package/dist/cjs/models/gemini_llm_connection.js +1 -0
  26. package/dist/cjs/models/google_llm.js +3 -3
  27. package/dist/cjs/plugins/base_plugin.js +71 -49
  28. package/dist/cjs/plugins/logging_plugin.js +50 -13
  29. package/dist/cjs/plugins/plugin_manager.js +56 -24
  30. package/dist/cjs/plugins/security_plugin.js +5 -2
  31. package/dist/cjs/runner/runner.js +126 -101
  32. package/dist/cjs/sessions/in_memory_session_service.js +38 -14
  33. package/dist/cjs/telemetry/google_cloud.js +7 -9
  34. package/dist/cjs/telemetry/setup.js +15 -7
  35. package/dist/cjs/telemetry/tracing.js +37 -15
  36. package/dist/cjs/tools/agent_tool.js +26 -13
  37. package/dist/cjs/tools/base_tool.js +19 -7
  38. package/dist/cjs/tools/forwarding_artifact_service.js +1 -1
  39. package/dist/cjs/tools/function_tool.js +15 -7
  40. package/dist/cjs/tools/google_search_tool.js +8 -4
  41. package/dist/cjs/tools/mcp/mcp_session_manager.js +16 -10
  42. package/dist/cjs/tools/mcp/mcp_tool.js +1 -3
  43. package/dist/cjs/tools/mcp/mcp_toolset.js +1 -1
  44. package/dist/cjs/tools/tool_context.js +4 -9
  45. package/dist/cjs/utils/env_aware_utils.js +1 -1
  46. package/dist/cjs/utils/gemini_schema_util.js +10 -4
  47. package/dist/cjs/utils/logger.js +47 -3
  48. package/dist/cjs/utils/simple_zod_to_json.js +100 -141
  49. package/dist/cjs/utils/variant_utils.js +1 -1
  50. package/dist/cjs/version.js +1 -1
  51. package/dist/esm/agents/base_agent.js +57 -25
  52. package/dist/esm/agents/callback_context.js +4 -1
  53. package/dist/esm/agents/content_processor_utils.js +25 -9
  54. package/dist/esm/agents/functions.js +83 -29
  55. package/dist/esm/agents/invocation_context.js +3 -1
  56. package/dist/esm/agents/llm_agent.js +228 -116
  57. package/dist/esm/agents/loop_agent.js +16 -5
  58. package/dist/esm/agents/parallel_agent.js +18 -6
  59. package/dist/esm/agents/readonly_context.js +4 -1
  60. package/dist/esm/agents/sequential_agent.js +33 -12
  61. package/dist/esm/artifacts/gcs_artifact_service.js +28 -20
  62. package/dist/esm/artifacts/in_memory_artifact_service.js +18 -4
  63. package/dist/esm/auth/auth_handler.js +3 -1
  64. package/dist/esm/code_executors/base_code_executor.js +12 -1
  65. package/dist/esm/code_executors/built_in_code_executor.js +19 -4
  66. package/dist/esm/code_executors/code_executor_context.js +5 -5
  67. package/dist/esm/common.js +56 -11
  68. package/dist/esm/events/event.js +1 -3
  69. package/dist/esm/examples/base_example_provider.js +16 -1
  70. package/dist/esm/examples/example_util.js +4 -2
  71. package/dist/esm/index.js +19 -19
  72. package/dist/esm/index.js.map +4 -4
  73. package/dist/esm/memory/in_memory_memory_service.js +3 -1
  74. package/dist/esm/models/base_llm.js +8 -4
  75. package/dist/esm/models/gemini_llm_connection.js +1 -0
  76. package/dist/esm/models/google_llm.js +8 -4
  77. package/dist/esm/plugins/base_plugin.js +71 -49
  78. package/dist/esm/plugins/logging_plugin.js +55 -14
  79. package/dist/esm/plugins/plugin_manager.js +56 -24
  80. package/dist/esm/plugins/security_plugin.js +5 -2
  81. package/dist/esm/runner/runner.js +139 -105
  82. package/dist/esm/sessions/in_memory_session_service.js +41 -15
  83. package/dist/esm/telemetry/google_cloud.js +7 -9
  84. package/dist/esm/telemetry/setup.js +23 -9
  85. package/dist/esm/telemetry/tracing.js +37 -15
  86. package/dist/esm/tools/agent_tool.js +25 -13
  87. package/dist/esm/tools/base_tool.js +17 -6
  88. package/dist/esm/tools/forwarding_artifact_service.js +1 -1
  89. package/dist/esm/tools/function_tool.js +13 -8
  90. package/dist/esm/tools/google_search_tool.js +6 -3
  91. package/dist/esm/tools/long_running_tool.js +3 -1
  92. package/dist/esm/tools/mcp/mcp_session_manager.js +22 -12
  93. package/dist/esm/tools/mcp/mcp_tool.js +1 -3
  94. package/dist/esm/tools/mcp/mcp_toolset.js +1 -1
  95. package/dist/esm/tools/tool_context.js +4 -9
  96. package/dist/esm/utils/env_aware_utils.js +1 -1
  97. package/dist/esm/utils/gemini_schema_util.js +10 -4
  98. package/dist/esm/utils/logger.js +43 -2
  99. package/dist/esm/utils/simple_zod_to_json.js +102 -141
  100. package/dist/esm/utils/variant_utils.js +1 -1
  101. package/dist/esm/version.js +1 -1
  102. package/dist/types/agents/base_agent.d.ts +16 -4
  103. package/dist/types/agents/callback_context.d.ts +1 -1
  104. package/dist/types/agents/invocation_context.d.ts +4 -2
  105. package/dist/types/agents/llm_agent.d.ts +43 -31
  106. package/dist/types/agents/loop_agent.d.ts +17 -1
  107. package/dist/types/agents/parallel_agent.d.ts +17 -1
  108. package/dist/types/agents/sequential_agent.d.ts +17 -1
  109. package/dist/types/artifacts/in_memory_artifact_service.d.ts +3 -3
  110. package/dist/types/auth/auth_schemes.d.ts +5 -2
  111. package/dist/types/code_executors/base_code_executor.d.ts +14 -0
  112. package/dist/types/code_executors/built_in_code_executor.d.ts +20 -1
  113. package/dist/types/code_executors/code_executor_context.d.ts +2 -4
  114. package/dist/types/common.d.ts +40 -15
  115. package/dist/types/examples/base_example_provider.d.ts +16 -0
  116. package/dist/types/index.d.ts +3 -3
  117. package/dist/types/models/base_llm_connection.d.ts +1 -1
  118. package/dist/types/models/llm_response.d.ts +1 -1
  119. package/dist/types/plugins/base_plugin.d.ts +50 -40
  120. package/dist/types/plugins/logging_plugin.d.ts +12 -12
  121. package/dist/types/plugins/plugin_manager.d.ts +12 -12
  122. package/dist/types/plugins/security_plugin.d.ts +1 -1
  123. package/dist/types/runner/runner.d.ts +18 -10
  124. package/dist/types/sessions/in_memory_session_service.d.ts +5 -5
  125. package/dist/types/telemetry/setup.d.ts +1 -1
  126. package/dist/types/telemetry/tracing.d.ts +7 -6
  127. package/dist/types/tools/agent_tool.d.ts +15 -1
  128. package/dist/types/tools/base_tool.d.ts +15 -1
  129. package/dist/types/tools/base_toolset.d.ts +2 -1
  130. package/dist/types/tools/forwarding_artifact_service.d.ts +2 -2
  131. package/dist/types/tools/function_tool.d.ts +18 -4
  132. package/dist/types/tools/google_search_tool.d.ts +5 -6
  133. package/dist/types/tools/mcp/mcp_session_manager.d.ts +10 -3
  134. package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -2
  135. package/dist/types/tools/tool_context.d.ts +1 -1
  136. package/dist/types/utils/gemini_schema_util.d.ts +4 -12
  137. package/dist/types/utils/logger.d.ts +11 -10
  138. package/dist/types/utils/simple_zod_to_json.d.ts +5 -4
  139. package/dist/types/version.d.ts +1 -1
  140. package/dist/web/agents/base_agent.js +103 -36
  141. package/dist/web/agents/callback_context.js +4 -1
  142. package/dist/web/agents/content_processor_utils.js +25 -9
  143. package/dist/web/agents/functions.js +83 -29
  144. package/dist/web/agents/invocation_context.js +3 -1
  145. package/dist/web/agents/llm_agent.js +282 -137
  146. package/dist/web/agents/loop_agent.js +16 -5
  147. package/dist/web/agents/parallel_agent.js +18 -6
  148. package/dist/web/agents/readonly_context.js +4 -1
  149. package/dist/web/agents/sequential_agent.js +33 -12
  150. package/dist/web/artifacts/gcs_artifact_service.js +25 -17
  151. package/dist/web/artifacts/in_memory_artifact_service.js +18 -4
  152. package/dist/web/auth/auth_handler.js +3 -1
  153. package/dist/web/code_executors/base_code_executor.js +12 -1
  154. package/dist/web/code_executors/built_in_code_executor.js +19 -4
  155. package/dist/web/code_executors/code_executor_context.js +5 -5
  156. package/dist/web/common.js +56 -11
  157. package/dist/web/events/event.js +1 -3
  158. package/dist/web/examples/base_example_provider.js +16 -1
  159. package/dist/web/examples/example_util.js +4 -2
  160. package/dist/web/index.js +1 -1
  161. package/dist/web/index.js.map +4 -4
  162. package/dist/web/memory/in_memory_memory_service.js +3 -1
  163. package/dist/web/models/base_llm.js +8 -4
  164. package/dist/web/models/gemini_llm_connection.js +1 -0
  165. package/dist/web/models/google_llm.js +8 -4
  166. package/dist/web/plugins/base_plugin.js +71 -49
  167. package/dist/web/plugins/logging_plugin.js +55 -14
  168. package/dist/web/plugins/plugin_manager.js +56 -24
  169. package/dist/web/plugins/security_plugin.js +5 -2
  170. package/dist/web/runner/runner.js +186 -119
  171. package/dist/web/sessions/in_memory_session_service.js +41 -15
  172. package/dist/web/telemetry/google_cloud.js +7 -9
  173. package/dist/web/telemetry/setup.js +23 -9
  174. package/dist/web/telemetry/tracing.js +37 -15
  175. package/dist/web/tools/agent_tool.js +25 -13
  176. package/dist/web/tools/base_tool.js +17 -6
  177. package/dist/web/tools/forwarding_artifact_service.js +1 -1
  178. package/dist/web/tools/function_tool.js +13 -8
  179. package/dist/web/tools/google_search_tool.js +6 -3
  180. package/dist/web/tools/long_running_tool.js +3 -1
  181. package/dist/web/tools/mcp/mcp_session_manager.js +22 -12
  182. package/dist/web/tools/mcp/mcp_tool.js +1 -3
  183. package/dist/web/tools/mcp/mcp_toolset.js +1 -1
  184. package/dist/web/tools/tool_context.js +4 -9
  185. package/dist/web/utils/env_aware_utils.js +1 -1
  186. package/dist/web/utils/gemini_schema_util.js +10 -4
  187. package/dist/web/utils/logger.js +43 -2
  188. package/dist/web/utils/simple_zod_to_json.js +102 -155
  189. package/dist/web/utils/variant_utils.js +1 -1
  190. package/dist/web/version.js +1 -1
  191. package/package.json +5 -3
@@ -67,7 +67,9 @@ class InMemoryMemoryService {
67
67
  if (!wordsInEvent.size) {
68
68
  continue;
69
69
  }
70
- const matchQuery = wordsInQuery.some((queryWord) => wordsInEvent.has(queryWord));
70
+ const matchQuery = wordsInQuery.some(
71
+ (queryWord) => wordsInEvent.has(queryWord)
72
+ );
71
73
  if (matchQuery) {
72
74
  response.memories.push({
73
75
  content: event.content,
@@ -73,16 +73,20 @@ class BaseLlm {
73
73
  llmRequest.contents.push({
74
74
  role: "user",
75
75
  parts: [
76
- { text: "Handle the requests as specified in the System Instruction." }
76
+ {
77
+ text: "Handle the requests as specified in the System Instruction."
78
+ }
77
79
  ]
78
80
  });
79
81
  }
80
82
  if (((_a2 = llmRequest.contents[llmRequest.contents.length - 1]) == null ? void 0 : _a2.role) !== "user") {
81
83
  llmRequest.contents.push({
82
84
  role: "user",
83
- parts: [{
84
- text: "Continue processing previous requests as instructed. Exit or provide a summary if no more outputs are needed."
85
- }]
85
+ parts: [
86
+ {
87
+ text: "Continue processing previous requests as instructed. Exit or provide a summary if no more outputs are needed."
88
+ }
89
+ ]
86
90
  });
87
91
  }
88
92
  }
@@ -116,6 +116,7 @@ class GeminiLlmConnection {
116
116
  };
117
117
  }
118
118
  // TODO(b/425992518): GenAI SDK inconsistent API, missing methods.
119
+ // eslint-disable-next-line require-yield
119
120
  async *receive() {
120
121
  throw new Error("Not Implemented.");
121
122
  }
@@ -38,8 +38,6 @@ var import_llm_response = require("./llm_response.js");
38
38
  * Copyright 2025 Google LLC
39
39
  * SPDX-License-Identifier: Apache-2.0
40
40
  */
41
- const AGENT_ENGINE_TELEMETRY_TAG = "remote_reasoning_engine";
42
- const AGENT_ENGINE_TELEMETRY_ENV_VARIABLE_NAME = "GOOGLE_CLOUD_AGENT_ENGINE_ID";
43
41
  class Gemini extends import_base_llm.BaseLlm {
44
42
  /**
45
43
  * @param params The parameters for creating a Gemini instance.
@@ -252,7 +250,9 @@ class Gemini extends import_base_llm.BaseLlm {
252
250
  llmRequest.liveConnectConfig.systemInstruction = {
253
251
  role: "system",
254
252
  // TODO - b/425992518: validate type casting works well.
255
- parts: [(0, import_genai.createPartFromText)(llmRequest.config.systemInstruction)]
253
+ parts: [
254
+ (0, import_genai.createPartFromText)(llmRequest.config.systemInstruction)
255
+ ]
256
256
  };
257
257
  }
258
258
  llmRequest.liveConnectConfig.tools = (_c = llmRequest.config) == null ? void 0 : _c.tools;
@@ -48,13 +48,14 @@ class BasePlugin {
48
48
  * This callback helps logging and modifying the user message before the
49
49
  * runner starts the invocation.
50
50
  *
51
- * @param invocationContext The context for the entire invocation.
52
- * @param userMessage The message content input by user.
51
+ * @param params.invocationContext The context for the entire invocation.
52
+ * @param params.userMessage The message content input by user.
53
53
  * @returns An optional `Content` to be returned to the ADK. Returning a
54
54
  * value to replace the user message. Returning `undefined` to proceed
55
55
  * normally.
56
56
  */
57
- async onUserMessageCallback({ invocationContext, userMessage }) {
57
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
58
+ async onUserMessageCallback(params) {
58
59
  return;
59
60
  }
60
61
  /**
@@ -63,13 +64,14 @@ class BasePlugin {
63
64
  * This is the first callback to be called in the lifecycle, ideal for global
64
65
  * setup or initialization tasks.
65
66
  *
66
- * @param invocationContext The context for the entire invocation, containing
67
+ * @param params.invocationContext The context for the entire invocation, containing
67
68
  * session information, the root agent, etc.
68
69
  * @returns An optional `Event` to be returned to the ADK. Returning a value
69
70
  * to halt execution of the runner and ends the runner with that event.
70
71
  * Return `undefined` to proceed normally.
71
72
  */
72
- async beforeRunCallback({ invocationContext }) {
73
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
74
+ async beforeRunCallback(params) {
73
75
  return;
74
76
  }
75
77
  /**
@@ -78,13 +80,14 @@ class BasePlugin {
78
80
  * This is the ideal place to make modification to the event before the event
79
81
  * is handled by the underlying agent app.
80
82
  *
81
- * @param invocationContext The context for the entire invocation.
82
- * @param event The event raised by the runner.
83
+ * @param params.invocationContext The context for the entire invocation.
84
+ * @param params.event The event raised by the runner.
83
85
  * @returns An optional value. A non-`undefined` return may be used by the
84
86
  * framework to modify or replace the response. Returning `undefined`
85
87
  * allows the original response to be used.
86
88
  */
87
- async onEventCallback({ invocationContext, event }) {
89
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
90
+ async onEventCallback(params) {
88
91
  return;
89
92
  }
90
93
  /**
@@ -93,10 +96,11 @@ class BasePlugin {
93
96
  * This is the final callback in the ADK lifecycle, suitable for cleanup,
94
97
  * final logging, or reporting tasks.
95
98
  *
96
- * @param invocationContext The context for the entire invocation.
99
+ * @param params.invocationContext The context for the entire invocation.
97
100
  * @returns undefined
98
101
  */
99
- async afterRunCallback({ invocationContext }) {
102
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
103
+ async afterRunCallback(params) {
100
104
  return;
101
105
  }
102
106
  /**
@@ -105,13 +109,14 @@ class BasePlugin {
105
109
  * This callback can be used for logging, setup, or to short-circuit the
106
110
  * agent's execution by returning a value.
107
111
  *
108
- * @param agent The agent that is about to run.
109
- * @param callbackContext The context for the agent invocation.
112
+ * @param params.agent The agent that is about to run.
113
+ * @param params.callbackContext The context for the agent invocation.
110
114
  * @returns An optional `Content` object. If a value is returned, it will
111
115
  * bypass the agent's callbacks and its execution, and return this value
112
116
  * directly. Returning `undefined` allows the agent to proceed normally.
113
117
  */
114
- async beforeAgentCallback({ agent, callbackContext }) {
118
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
119
+ async beforeAgentCallback(params) {
115
120
  return;
116
121
  }
117
122
  /**
@@ -120,13 +125,14 @@ class BasePlugin {
120
125
  * This callback can be used to inspect, log, or modify the agent's final
121
126
  * result before it is returned.
122
127
  *
123
- * @param agent The agent that has just run.
124
- * @param callbackContext The context for the agent invocation.
128
+ * @param params.agent The agent that has just run.
129
+ * @param params.callbackContext The context for the agent invocation.
125
130
  * @returns An optional `Content` object. If a value is returned, it will
126
131
  * replace the agent's original result. Returning `undefined` uses the
127
132
  * original, unmodified result.
128
133
  */
129
- async afterAgentCallback({ agent, callbackContext }) {
134
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
135
+ async afterAgentCallback(params) {
130
136
  return;
131
137
  }
132
138
  /**
@@ -136,13 +142,14 @@ class BasePlugin {
136
142
  * object. It can also be used to implement caching by returning a cached
137
143
  * `LlmResponse`, which would skip the actual model call.
138
144
  *
139
- * @param callbackContext The context for the current agent call.
140
- * @param llmRequest The prepared request object to be sent to the model.
145
+ * @param params.callbackContext The context for the current agent call.
146
+ * @param params.llmRequest The prepared request object to be sent to the model.
141
147
  * @returns An optional value. The interpretation of a non-`undefined`
142
148
  * trigger an early exit and returns the response immediately. Returning
143
149
  * `undefined` allows the LLM request to proceed normally.
144
150
  */
145
- async beforeModelCallback({ callbackContext, llmRequest }) {
151
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
152
+ async beforeModelCallback(params) {
146
153
  return;
147
154
  }
148
155
  /**
@@ -151,13 +158,14 @@ class BasePlugin {
151
158
  * This is the ideal place to log model responses, collect metrics on token
152
159
  * usage, or perform post-processing on the raw `LlmResponse`.
153
160
  *
154
- * @param callbackContext The context for the current agent call.
155
- * @param llmResponse The response object received from the model.
161
+ * @param params.callbackContext The context for the current agent call.
162
+ * @param params.llmResponse The response object received from the model.
156
163
  * @returns An optional value. A non-`undefined` return may be used by the
157
164
  * framework to modify or replace the response. Returning `undefined`
158
165
  * allows the original response to be used.
159
166
  */
160
- async afterModelCallback({ callbackContext, llmResponse }) {
167
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
168
+ async afterModelCallback(params) {
161
169
  return;
162
170
  }
163
171
  /**
@@ -166,15 +174,16 @@ class BasePlugin {
166
174
  * This callback provides an opportunity to handle model errors gracefully,
167
175
  * potentially providing alternative responses or recovery mechanisms.
168
176
  *
169
- * @param callbackContext The context for the current agent call.
170
- * @param llmRequest The request that was sent to the model when the error
177
+ * @param params.callbackContext The context for the current agent call.
178
+ * @param params.llmRequest The request that was sent to the model when the error
171
179
  * occurred.
172
- * @param error The exception that was raised during model execution.
180
+ * @param params.error The exception that was raised during model execution.
173
181
  * @returns An optional LlmResponse. If an LlmResponse is returned, it will be
174
182
  * used instead of propagating the error. Returning `undefined` allows
175
183
  * the original error to be raised.
176
184
  */
177
- async onModelErrorCallback({ callbackContext, llmRequest, error }) {
185
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
186
+ async onModelErrorCallback(params) {
178
187
  return;
179
188
  }
180
189
  /**
@@ -183,15 +192,16 @@ class BasePlugin {
183
192
  * This callback is useful for logging tool usage, input validation, or
184
193
  * modifying the arguments before they are passed to the tool.
185
194
  *
186
- * @param tool The tool instance that is about to be executed.
187
- * @param toolArgs The dictionary of arguments to be used for invoking the
195
+ * @param params.tool The tool instance that is about to be executed.
196
+ * @param params.toolArgs The dictionary of arguments to be used for invoking the
188
197
  * tool.
189
- * @param toolContext The context specific to the tool execution.
198
+ * @param params.toolContext The context specific to the tool execution.
190
199
  * @returns An optional dictionary. If a dictionary is returned, it will stop
191
200
  * the tool execution and return this response immediately. Returning
192
201
  * `undefined` uses the original, unmodified arguments.
193
202
  */
194
- async beforeToolCallback({ tool, toolArgs, toolContext }) {
203
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
204
+ async beforeToolCallback(params) {
195
205
  return;
196
206
  }
197
207
  /**
@@ -200,33 +210,45 @@ class BasePlugin {
200
210
  * This callback allows for inspecting, logging, or modifying the result
201
211
  * returned by a tool.
202
212
  *
203
- * @param tool The tool instance that has just been executed.
204
- * @param toolArgs The original arguments that were passed to the tool.
205
- * @param toolContext The context specific to the tool execution.
206
- * @param result The dictionary returned by the tool invocation.
213
+ * @param params.tool The tool instance that has just been executed.
214
+ * @param params.toolArgs The original arguments that were passed to the tool.
215
+ * @param params.toolContext The context specific to the tool execution.
216
+ * @param params.result The dictionary returned by the tool invocation.
207
217
  * @returns An optional dictionary. If a dictionary is returned, it will
208
218
  * **replace** the original result from the tool. This allows for
209
219
  * post-processing or altering tool outputs. Returning `undefined` uses
210
220
  * the original, unmodified result.
211
221
  */
212
- async afterToolCallback({ tool, toolArgs, toolContext, result }) {
222
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
223
+ async afterToolCallback(params) {
213
224
  return;
214
225
  }
215
226
  /**
216
- * Callback executed when a tool call encounters an error.
217
- *
218
- * This callback provides an opportunity to handle tool errors gracefully,
219
- * potentially providing alternative responses or recovery mechanisms.
220
- *
221
- * @param tool The tool instance that encountered an error.
222
- * @param toolArgs The arguments that were passed to the tool.
223
- * @param toolContext The context specific to the tool execution.
224
- * @param error The exception that was raised during tool execution.
225
- * @returns An optional dictionary. If a dictionary is returned, it will be
226
- * used as the tool response instead of propagating the error. Returning
227
- * `undefined` allows the original error to be raised.
228
- */
229
- async onToolErrorCallback({ tool, toolArgs, toolContext, error }) {
227
+ * Callback executed when a tool call encounters an error.
228
+ tool: BaseTool;
229
+ toolArgs: Record<string, unknown>;
230
+ toolContext: ToolContext;
231
+ result: Record<string, unknown>;
232
+ }): Promise<Record<string, unknown> | undefined> {
233
+ return;
234
+ }
235
+
236
+ /**
237
+ * Callback executed when a tool call encounters an error.
238
+ *
239
+ * This callback provides an opportunity to handle tool errors gracefully,
240
+ * potentially providing alternative responses or recovery mechanisms.
241
+ *
242
+ * @param params.tool The tool instance that encountered an error.
243
+ * @param params.toolArgs The arguments that were passed to the tool.
244
+ * @param params.toolContext The context specific to the tool execution.
245
+ * @param params.error The exception that was raised during tool execution.
246
+ * @returns An optional dictionary. If a dictionary is returned, it will be
247
+ * used as the tool response instead of propagating the error. Returning
248
+ * `undefined` allows the original error to be raised.
249
+ */
250
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
251
+ async onToolErrorCallback(params) {
230
252
  return;
231
253
  }
232
254
  }
@@ -44,7 +44,10 @@ class LoggingPlugin extends import_base_plugin.BasePlugin {
44
44
  constructor(name = "logging_plugin") {
45
45
  super(name);
46
46
  }
47
- async onUserMessageCallback({ invocationContext, userMessage }) {
47
+ async onUserMessageCallback({
48
+ invocationContext,
49
+ userMessage
50
+ }) {
48
51
  var _a;
49
52
  this.log("\u{1F680} USER MESSAGE RECEIVED");
50
53
  this.log(` Invocation ID: ${invocationContext.invocationId}`);
@@ -58,14 +61,18 @@ class LoggingPlugin extends import_base_plugin.BasePlugin {
58
61
  }
59
62
  return void 0;
60
63
  }
61
- async beforeRunCallback({ invocationContext }) {
64
+ async beforeRunCallback({
65
+ invocationContext
66
+ }) {
62
67
  var _a;
63
68
  this.log("\u{1F3C3} INVOCATION STARTING");
64
69
  this.log(` Invocation ID: ${invocationContext.invocationId}`);
65
70
  this.log(` Starting Agent: ${(_a = invocationContext.agent.name) != null ? _a : "Unknown"}`);
66
71
  return void 0;
67
72
  }
68
- async onEventCallback({ invocationContext, event }) {
73
+ async onEventCallback({
74
+ event
75
+ }) {
69
76
  this.log("\u{1F4E2} EVENT YIELDED");
70
77
  this.log(` Event ID: ${event.id}`);
71
78
  this.log(` Author: ${event.author}`);
@@ -86,14 +93,18 @@ class LoggingPlugin extends import_base_plugin.BasePlugin {
86
93
  }
87
94
  return void 0;
88
95
  }
89
- async afterRunCallback({ invocationContext }) {
96
+ async afterRunCallback({
97
+ invocationContext
98
+ }) {
90
99
  var _a;
91
100
  this.log("\u2705 INVOCATION COMPLETED");
92
101
  this.log(` Invocation ID: ${invocationContext.invocationId}`);
93
102
  this.log(` Final Agent: ${(_a = invocationContext.agent.name) != null ? _a : "Unknown"}`);
94
103
  return void 0;
95
104
  }
96
- async beforeAgentCallback({ agent, callbackContext }) {
105
+ async beforeAgentCallback({
106
+ callbackContext
107
+ }) {
97
108
  this.log("\u{1F916} AGENT STARTING");
98
109
  this.log(` Agent Name: ${callbackContext.agentName}`);
99
110
  this.log(` Invocation ID: ${callbackContext.invocationId}`);
@@ -102,13 +113,18 @@ class LoggingPlugin extends import_base_plugin.BasePlugin {
102
113
  }
103
114
  return void 0;
104
115
  }
105
- async afterAgentCallback({ agent, callbackContext }) {
116
+ async afterAgentCallback({
117
+ callbackContext
118
+ }) {
106
119
  this.log("\u{1F916} AGENT COMPLETED");
107
120
  this.log(` Agent Name: ${callbackContext.agentName}`);
108
121
  this.log(` Invocation ID: ${callbackContext.invocationId}`);
109
122
  return void 0;
110
123
  }
111
- async beforeModelCallback({ callbackContext, llmRequest }) {
124
+ async beforeModelCallback({
125
+ callbackContext,
126
+ llmRequest
127
+ }) {
112
128
  var _a;
113
129
  this.log("\u{1F9E0} LLM REQUEST");
114
130
  this.log(` Model: ${(_a = llmRequest.model) != null ? _a : "default"}`);
@@ -126,7 +142,10 @@ class LoggingPlugin extends import_base_plugin.BasePlugin {
126
142
  }
127
143
  return void 0;
128
144
  }
129
- async afterModelCallback({ callbackContext, llmResponse }) {
145
+ async afterModelCallback({
146
+ callbackContext,
147
+ llmResponse
148
+ }) {
130
149
  this.log("\u{1F9E0} LLM RESPONSE");
131
150
  this.log(` Agent: ${callbackContext.agentName}`);
132
151
  if (llmResponse.errorCode) {
@@ -142,11 +161,17 @@ class LoggingPlugin extends import_base_plugin.BasePlugin {
142
161
  }
143
162
  }
144
163
  if (llmResponse.usageMetadata) {
145
- this.log(` Token Usage - Input: ${llmResponse.usageMetadata.promptTokenCount}, Output: ${llmResponse.usageMetadata.candidatesTokenCount}`);
164
+ this.log(
165
+ ` Token Usage - Input: ${llmResponse.usageMetadata.promptTokenCount}, Output: ${llmResponse.usageMetadata.candidatesTokenCount}`
166
+ );
146
167
  }
147
168
  return void 0;
148
169
  }
149
- async beforeToolCallback({ tool, toolArgs, toolContext }) {
170
+ async beforeToolCallback({
171
+ tool,
172
+ toolArgs,
173
+ toolContext
174
+ }) {
150
175
  this.log("\u{1F527} TOOL STARTING");
151
176
  this.log(` Tool Name: ${tool.name}`);
152
177
  this.log(` Agent: ${toolContext.agentName}`);
@@ -154,7 +179,11 @@ class LoggingPlugin extends import_base_plugin.BasePlugin {
154
179
  this.log(` Arguments: ${this.formatArgs(toolArgs)}`);
155
180
  return void 0;
156
181
  }
157
- async afterToolCallback({ tool, toolArgs, toolContext, result }) {
182
+ async afterToolCallback({
183
+ tool,
184
+ toolContext,
185
+ result
186
+ }) {
158
187
  this.log("\u{1F527} TOOL COMPLETED");
159
188
  this.log(` Tool Name: ${tool.name}`);
160
189
  this.log(` Agent: ${toolContext.agentName}`);
@@ -162,13 +191,21 @@ class LoggingPlugin extends import_base_plugin.BasePlugin {
162
191
  this.log(` Result: ${this.formatArgs(result)}`);
163
192
  return void 0;
164
193
  }
165
- async onModelErrorCallback({ callbackContext, llmRequest, error }) {
194
+ async onModelErrorCallback({
195
+ callbackContext,
196
+ error
197
+ }) {
166
198
  this.log("\u{1F9E0} LLM ERROR");
167
199
  this.log(` Agent: ${callbackContext.agentName}`);
168
200
  this.log(` Error: ${error}`);
169
201
  return void 0;
170
202
  }
171
- async onToolErrorCallback({ tool, toolArgs, toolContext, error }) {
203
+ async onToolErrorCallback({
204
+ tool,
205
+ toolArgs,
206
+ toolContext,
207
+ error
208
+ }) {
172
209
  this.log("\u{1F527} TOOL ERROR");
173
210
  this.log(` Tool Name: ${tool.name}`);
174
211
  this.log(` Agent: ${toolContext.agentName}`);
@@ -107,19 +107,22 @@ class PluginManager {
107
107
  /**
108
108
  * Runs the `onUserMessageCallback` for all plugins.
109
109
  */
110
- async runOnUserMessageCallback({ userMessage, invocationContext }) {
110
+ async runOnUserMessageCallback({
111
+ userMessage,
112
+ invocationContext
113
+ }) {
111
114
  return await this.runCallbacks(
112
115
  this.plugins,
113
- (plugin) => plugin.onUserMessageCallback(
114
- { userMessage, invocationContext }
115
- ),
116
+ (plugin) => plugin.onUserMessageCallback({ userMessage, invocationContext }),
116
117
  "onUserMessageCallback"
117
118
  );
118
119
  }
119
120
  /**
120
121
  * Runs the `beforeRunCallback` for all plugins.
121
122
  */
122
- async runBeforeRunCallback({ invocationContext }) {
123
+ async runBeforeRunCallback({
124
+ invocationContext
125
+ }) {
123
126
  return await this.runCallbacks(
124
127
  this.plugins,
125
128
  (plugin) => plugin.beforeRunCallback({ invocationContext }),
@@ -129,7 +132,9 @@ class PluginManager {
129
132
  /**
130
133
  * Runs the `afterRunCallback` for all plugins.
131
134
  */
132
- async runAfterRunCallback({ invocationContext }) {
135
+ async runAfterRunCallback({
136
+ invocationContext
137
+ }) {
133
138
  await this.runCallbacks(
134
139
  this.plugins,
135
140
  (plugin) => plugin.afterRunCallback({ invocationContext }),
@@ -139,7 +144,10 @@ class PluginManager {
139
144
  /**
140
145
  * Runs the `onEventCallback` for all plugins.
141
146
  */
142
- async runOnEventCallback({ invocationContext, event }) {
147
+ async runOnEventCallback({
148
+ invocationContext,
149
+ event
150
+ }) {
143
151
  return await this.runCallbacks(
144
152
  this.plugins,
145
153
  (plugin) => plugin.onEventCallback({ invocationContext, event }),
@@ -149,7 +157,10 @@ class PluginManager {
149
157
  /**
150
158
  * Runs the `beforeAgentCallback` for all plugins.
151
159
  */
152
- async runBeforeAgentCallback({ agent, callbackContext }) {
160
+ async runBeforeAgentCallback({
161
+ agent,
162
+ callbackContext
163
+ }) {
153
164
  return await this.runCallbacks(
154
165
  this.plugins,
155
166
  (plugin) => plugin.beforeAgentCallback({ agent, callbackContext }),
@@ -159,7 +170,10 @@ class PluginManager {
159
170
  /**
160
171
  * Runs the `afterAgentCallback` for all plugins.
161
172
  */
162
- async runAfterAgentCallback({ agent, callbackContext }) {
173
+ async runAfterAgentCallback({
174
+ agent,
175
+ callbackContext
176
+ }) {
163
177
  return await this.runCallbacks(
164
178
  this.plugins,
165
179
  (plugin) => plugin.afterAgentCallback({ agent, callbackContext }),
@@ -169,7 +183,11 @@ class PluginManager {
169
183
  /**
170
184
  * Runs the `beforeToolCallback` for all plugins.
171
185
  */
172
- async runBeforeToolCallback({ tool, toolArgs, toolContext }) {
186
+ async runBeforeToolCallback({
187
+ tool,
188
+ toolArgs,
189
+ toolContext
190
+ }) {
173
191
  return await this.runCallbacks(
174
192
  this.plugins,
175
193
  (plugin) => plugin.beforeToolCallback({ tool, toolArgs, toolContext }),
@@ -179,31 +197,39 @@ class PluginManager {
179
197
  /**
180
198
  * Runs the `afterToolCallback` for all plugins.
181
199
  */
182
- async runAfterToolCallback({ tool, toolArgs, toolContext, result }) {
200
+ async runAfterToolCallback({
201
+ tool,
202
+ toolArgs,
203
+ toolContext,
204
+ result
205
+ }) {
183
206
  return await this.runCallbacks(
184
207
  this.plugins,
185
- (plugin) => plugin.afterToolCallback(
186
- { tool, toolArgs, toolContext, result }
187
- ),
208
+ (plugin) => plugin.afterToolCallback({ tool, toolArgs, toolContext, result }),
188
209
  "afterToolCallback"
189
210
  );
190
211
  }
191
212
  /**
192
213
  * Runs the `onModelErrorCallback` for all plugins.
193
214
  */
194
- async runOnModelErrorCallback({ callbackContext, llmRequest, error }) {
215
+ async runOnModelErrorCallback({
216
+ callbackContext,
217
+ llmRequest,
218
+ error
219
+ }) {
195
220
  return await this.runCallbacks(
196
221
  this.plugins,
197
- (plugin) => plugin.onModelErrorCallback(
198
- { callbackContext, llmRequest, error }
199
- ),
222
+ (plugin) => plugin.onModelErrorCallback({ callbackContext, llmRequest, error }),
200
223
  "onModelErrorCallback"
201
224
  );
202
225
  }
203
226
  /**
204
227
  * Runs the `beforeModelCallback` for all plugins.
205
228
  */
206
- async runBeforeModelCallback({ callbackContext, llmRequest }) {
229
+ async runBeforeModelCallback({
230
+ callbackContext,
231
+ llmRequest
232
+ }) {
207
233
  return await this.runCallbacks(
208
234
  this.plugins,
209
235
  (plugin) => plugin.beforeModelCallback({ callbackContext, llmRequest }),
@@ -213,7 +239,10 @@ class PluginManager {
213
239
  /**
214
240
  * Runs the `afterModelCallback` for all plugins.
215
241
  */
216
- async runAfterModelCallback({ callbackContext, llmResponse }) {
242
+ async runAfterModelCallback({
243
+ callbackContext,
244
+ llmResponse
245
+ }) {
217
246
  return await this.runCallbacks(
218
247
  this.plugins,
219
248
  (plugin) => plugin.afterModelCallback({ callbackContext, llmResponse }),
@@ -223,12 +252,15 @@ class PluginManager {
223
252
  /**
224
253
  * Runs the `onToolErrorCallback` for all plugins.
225
254
  */
226
- async runOnToolErrorCallback({ tool, toolArgs, toolContext, error }) {
255
+ async runOnToolErrorCallback({
256
+ tool,
257
+ toolArgs,
258
+ toolContext,
259
+ error
260
+ }) {
227
261
  return await this.runCallbacks(
228
262
  this.plugins,
229
- (plugin) => plugin.onToolErrorCallback(
230
- { tool, toolArgs, toolContext, error }
231
- ),
263
+ (plugin) => plugin.onToolErrorCallback({ tool, toolArgs, toolContext, error }),
232
264
  "onToolErrorCallback"
233
265
  );
234
266
  }
@@ -47,7 +47,7 @@ var PolicyOutcome = /* @__PURE__ */ ((PolicyOutcome2) => {
47
47
  return PolicyOutcome2;
48
48
  })(PolicyOutcome || {});
49
49
  class InMemoryPolicyEngine {
50
- async evaluate(context) {
50
+ async evaluate() {
51
51
  return Promise.resolve({
52
52
  outcome: "ALLOW" /* ALLOW */,
53
53
  reason: "For prototyping purpose, all tool calls are allowed."
@@ -112,7 +112,10 @@ class SecurityPlugin extends import_base_plugin.BasePlugin {
112
112
  toolArgs,
113
113
  toolContext
114
114
  }) {
115
- const policyCheckResult = await this.policyEngine.evaluate({ tool, toolArgs });
115
+ const policyCheckResult = await this.policyEngine.evaluate({
116
+ tool,
117
+ toolArgs
118
+ });
116
119
  this.setToolCallCheckState(toolContext, policyCheckResult.outcome);
117
120
  switch (policyCheckResult.outcome) {
118
121
  case "DENY" /* DENY */: