@google/adk 0.2.5 → 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.
- package/dist/cjs/agents/base_agent.js +43 -21
- package/dist/cjs/agents/callback_context.js +4 -1
- package/dist/cjs/agents/content_processor_utils.js +15 -7
- package/dist/cjs/agents/functions.js +79 -29
- package/dist/cjs/agents/llm_agent.js +59 -33
- package/dist/cjs/agents/loop_agent.js +2 -1
- package/dist/cjs/agents/parallel_agent.js +3 -4
- package/dist/cjs/artifacts/gcs_artifact_service.js +28 -20
- package/dist/cjs/artifacts/in_memory_artifact_service.js +18 -4
- package/dist/cjs/auth/auth_handler.js +3 -1
- package/dist/cjs/code_executors/base_code_executor.js +3 -1
- package/dist/cjs/code_executors/built_in_code_executor.js +7 -3
- package/dist/cjs/code_executors/code_executor_context.js +5 -5
- package/dist/cjs/common.js +4 -0
- package/dist/cjs/events/event.js +1 -3
- package/dist/cjs/index.js +19 -19
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/memory/in_memory_memory_service.js +3 -1
- package/dist/cjs/models/base_llm.js +8 -4
- package/dist/cjs/models/gemini_llm_connection.js +1 -0
- package/dist/cjs/models/google_llm.js +3 -3
- package/dist/cjs/plugins/base_plugin.js +12 -0
- package/dist/cjs/plugins/logging_plugin.js +50 -13
- package/dist/cjs/plugins/plugin_manager.js +56 -24
- package/dist/cjs/plugins/security_plugin.js +1 -1
- package/dist/cjs/runner/runner.js +110 -95
- package/dist/cjs/sessions/in_memory_session_service.js +38 -14
- package/dist/cjs/telemetry/google_cloud.js +7 -9
- package/dist/cjs/telemetry/setup.js +15 -7
- package/dist/cjs/telemetry/tracing.js +37 -15
- package/dist/cjs/tools/agent_tool.js +8 -4
- package/dist/cjs/tools/base_tool.js +4 -2
- package/dist/cjs/tools/forwarding_artifact_service.js +1 -1
- package/dist/cjs/tools/function_tool.js +1 -2
- package/dist/cjs/tools/google_search_tool.js +1 -2
- package/dist/cjs/tools/mcp/mcp_session_manager.js +16 -10
- package/dist/cjs/tools/mcp/mcp_tool.js +1 -3
- package/dist/cjs/tools/mcp/mcp_toolset.js +1 -1
- package/dist/cjs/utils/env_aware_utils.js +1 -1
- package/dist/cjs/utils/gemini_schema_util.js +9 -4
- package/dist/cjs/utils/logger.js +47 -3
- package/dist/cjs/utils/simple_zod_to_json.js +100 -141
- package/dist/cjs/utils/variant_utils.js +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/base_agent.js +48 -22
- package/dist/esm/agents/callback_context.js +4 -1
- package/dist/esm/agents/content_processor_utils.js +25 -9
- package/dist/esm/agents/functions.js +83 -29
- package/dist/esm/agents/llm_agent.js +63 -33
- package/dist/esm/agents/loop_agent.js +2 -1
- package/dist/esm/agents/parallel_agent.js +3 -4
- package/dist/esm/artifacts/gcs_artifact_service.js +28 -20
- package/dist/esm/artifacts/in_memory_artifact_service.js +18 -4
- package/dist/esm/auth/auth_handler.js +3 -1
- package/dist/esm/code_executors/base_code_executor.js +3 -1
- package/dist/esm/code_executors/built_in_code_executor.js +7 -3
- package/dist/esm/code_executors/code_executor_context.js +5 -5
- package/dist/esm/common.js +3 -1
- package/dist/esm/events/event.js +1 -3
- package/dist/esm/index.js +19 -19
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/memory/in_memory_memory_service.js +3 -1
- package/dist/esm/models/base_llm.js +8 -4
- package/dist/esm/models/gemini_llm_connection.js +1 -0
- package/dist/esm/models/google_llm.js +8 -4
- package/dist/esm/plugins/base_plugin.js +12 -0
- package/dist/esm/plugins/logging_plugin.js +55 -14
- package/dist/esm/plugins/plugin_manager.js +56 -24
- package/dist/esm/plugins/security_plugin.js +1 -1
- package/dist/esm/runner/runner.js +114 -96
- package/dist/esm/sessions/in_memory_session_service.js +41 -15
- package/dist/esm/telemetry/google_cloud.js +7 -9
- package/dist/esm/telemetry/setup.js +23 -9
- package/dist/esm/telemetry/tracing.js +37 -15
- package/dist/esm/tools/agent_tool.js +8 -4
- package/dist/esm/tools/base_tool.js +4 -2
- package/dist/esm/tools/forwarding_artifact_service.js +1 -1
- package/dist/esm/tools/function_tool.js +1 -2
- package/dist/esm/tools/google_search_tool.js +2 -5
- package/dist/esm/tools/long_running_tool.js +3 -1
- package/dist/esm/tools/mcp/mcp_session_manager.js +22 -12
- package/dist/esm/tools/mcp/mcp_tool.js +1 -3
- package/dist/esm/tools/mcp/mcp_toolset.js +1 -1
- package/dist/esm/utils/env_aware_utils.js +1 -1
- package/dist/esm/utils/gemini_schema_util.js +9 -4
- package/dist/esm/utils/logger.js +43 -2
- package/dist/esm/utils/simple_zod_to_json.js +102 -141
- package/dist/esm/utils/variant_utils.js +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/agents/base_agent.d.ts +2 -1
- package/dist/types/agents/callback_context.d.ts +1 -1
- package/dist/types/agents/llm_agent.d.ts +1 -1
- package/dist/types/agents/loop_agent.d.ts +1 -1
- package/dist/types/agents/parallel_agent.d.ts +1 -1
- package/dist/types/artifacts/in_memory_artifact_service.d.ts +3 -3
- package/dist/types/code_executors/built_in_code_executor.d.ts +1 -1
- package/dist/types/code_executors/code_executor_context.d.ts +2 -4
- package/dist/types/common.d.ts +2 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/models/base_llm_connection.d.ts +1 -1
- package/dist/types/models/llm_response.d.ts +1 -1
- package/dist/types/plugins/logging_plugin.d.ts +12 -12
- package/dist/types/plugins/plugin_manager.d.ts +12 -12
- package/dist/types/plugins/security_plugin.d.ts +1 -1
- package/dist/types/runner/runner.d.ts +1 -1
- package/dist/types/sessions/in_memory_session_service.d.ts +5 -5
- package/dist/types/telemetry/setup.d.ts +1 -1
- package/dist/types/telemetry/tracing.d.ts +7 -6
- package/dist/types/tools/agent_tool.d.ts +1 -1
- package/dist/types/tools/base_tool.d.ts +1 -1
- package/dist/types/tools/base_toolset.d.ts +2 -1
- package/dist/types/tools/forwarding_artifact_service.d.ts +2 -2
- package/dist/types/tools/function_tool.d.ts +4 -3
- package/dist/types/tools/google_search_tool.d.ts +3 -3
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +10 -3
- package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -2
- package/dist/types/utils/gemini_schema_util.d.ts +4 -12
- package/dist/types/utils/logger.d.ts +11 -10
- package/dist/types/utils/simple_zod_to_json.d.ts +5 -4
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/base_agent.js +94 -33
- package/dist/web/agents/callback_context.js +4 -1
- package/dist/web/agents/content_processor_utils.js +25 -9
- package/dist/web/agents/functions.js +83 -29
- package/dist/web/agents/llm_agent.js +117 -54
- package/dist/web/agents/loop_agent.js +2 -1
- package/dist/web/agents/parallel_agent.js +3 -4
- package/dist/web/artifacts/gcs_artifact_service.js +25 -17
- package/dist/web/artifacts/in_memory_artifact_service.js +18 -4
- package/dist/web/auth/auth_handler.js +3 -1
- package/dist/web/code_executors/base_code_executor.js +3 -1
- package/dist/web/code_executors/built_in_code_executor.js +7 -3
- package/dist/web/code_executors/code_executor_context.js +5 -5
- package/dist/web/common.js +3 -1
- package/dist/web/events/event.js +1 -3
- package/dist/web/index.js +1 -1
- package/dist/web/index.js.map +4 -4
- package/dist/web/memory/in_memory_memory_service.js +3 -1
- package/dist/web/models/base_llm.js +8 -4
- package/dist/web/models/gemini_llm_connection.js +1 -0
- package/dist/web/models/google_llm.js +8 -4
- package/dist/web/plugins/base_plugin.js +12 -0
- package/dist/web/plugins/logging_plugin.js +55 -14
- package/dist/web/plugins/plugin_manager.js +56 -24
- package/dist/web/plugins/security_plugin.js +1 -1
- package/dist/web/runner/runner.js +159 -108
- package/dist/web/sessions/in_memory_session_service.js +41 -15
- package/dist/web/telemetry/google_cloud.js +7 -9
- package/dist/web/telemetry/setup.js +23 -9
- package/dist/web/telemetry/tracing.js +37 -15
- package/dist/web/tools/agent_tool.js +8 -4
- package/dist/web/tools/base_tool.js +4 -2
- package/dist/web/tools/forwarding_artifact_service.js +1 -1
- package/dist/web/tools/function_tool.js +1 -2
- package/dist/web/tools/google_search_tool.js +2 -5
- package/dist/web/tools/long_running_tool.js +3 -1
- package/dist/web/tools/mcp/mcp_session_manager.js +22 -12
- package/dist/web/tools/mcp/mcp_tool.js +1 -3
- package/dist/web/tools/mcp/mcp_toolset.js +1 -1
- package/dist/web/utils/env_aware_utils.js +1 -1
- package/dist/web/utils/gemini_schema_util.js +9 -4
- package/dist/web/utils/logger.js +43 -2
- package/dist/web/utils/simple_zod_to_json.js +102 -155
- package/dist/web/utils/variant_utils.js +1 -1
- package/dist/web/version.js +1 -1
- package/package.json +4 -2
|
@@ -67,7 +67,9 @@ class InMemoryMemoryService {
|
|
|
67
67
|
if (!wordsInEvent.size) {
|
|
68
68
|
continue;
|
|
69
69
|
}
|
|
70
|
-
const matchQuery = wordsInQuery.some(
|
|
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
|
-
{
|
|
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
|
-
|
|
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
|
}
|
|
@@ -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: [
|
|
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;
|
|
@@ -54,6 +54,7 @@ class BasePlugin {
|
|
|
54
54
|
* value to replace the user message. Returning `undefined` to proceed
|
|
55
55
|
* normally.
|
|
56
56
|
*/
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
57
58
|
async onUserMessageCallback(params) {
|
|
58
59
|
return;
|
|
59
60
|
}
|
|
@@ -69,6 +70,7 @@ class BasePlugin {
|
|
|
69
70
|
* to halt execution of the runner and ends the runner with that event.
|
|
70
71
|
* Return `undefined` to proceed normally.
|
|
71
72
|
*/
|
|
73
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
72
74
|
async beforeRunCallback(params) {
|
|
73
75
|
return;
|
|
74
76
|
}
|
|
@@ -84,6 +86,7 @@ class BasePlugin {
|
|
|
84
86
|
* framework to modify or replace the response. Returning `undefined`
|
|
85
87
|
* allows the original response to be used.
|
|
86
88
|
*/
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
87
90
|
async onEventCallback(params) {
|
|
88
91
|
return;
|
|
89
92
|
}
|
|
@@ -96,6 +99,7 @@ class BasePlugin {
|
|
|
96
99
|
* @param params.invocationContext The context for the entire invocation.
|
|
97
100
|
* @returns undefined
|
|
98
101
|
*/
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
99
103
|
async afterRunCallback(params) {
|
|
100
104
|
return;
|
|
101
105
|
}
|
|
@@ -111,6 +115,7 @@ class BasePlugin {
|
|
|
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
|
*/
|
|
118
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
114
119
|
async beforeAgentCallback(params) {
|
|
115
120
|
return;
|
|
116
121
|
}
|
|
@@ -126,6 +131,7 @@ class BasePlugin {
|
|
|
126
131
|
* replace the agent's original result. Returning `undefined` uses the
|
|
127
132
|
* original, unmodified result.
|
|
128
133
|
*/
|
|
134
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
129
135
|
async afterAgentCallback(params) {
|
|
130
136
|
return;
|
|
131
137
|
}
|
|
@@ -142,6 +148,7 @@ class BasePlugin {
|
|
|
142
148
|
* trigger an early exit and returns the response immediately. Returning
|
|
143
149
|
* `undefined` allows the LLM request to proceed normally.
|
|
144
150
|
*/
|
|
151
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
145
152
|
async beforeModelCallback(params) {
|
|
146
153
|
return;
|
|
147
154
|
}
|
|
@@ -157,6 +164,7 @@ class BasePlugin {
|
|
|
157
164
|
* framework to modify or replace the response. Returning `undefined`
|
|
158
165
|
* allows the original response to be used.
|
|
159
166
|
*/
|
|
167
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
160
168
|
async afterModelCallback(params) {
|
|
161
169
|
return;
|
|
162
170
|
}
|
|
@@ -174,6 +182,7 @@ class BasePlugin {
|
|
|
174
182
|
* used instead of propagating the error. Returning `undefined` allows
|
|
175
183
|
* the original error to be raised.
|
|
176
184
|
*/
|
|
185
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
177
186
|
async onModelErrorCallback(params) {
|
|
178
187
|
return;
|
|
179
188
|
}
|
|
@@ -191,6 +200,7 @@ class BasePlugin {
|
|
|
191
200
|
* the tool execution and return this response immediately. Returning
|
|
192
201
|
* `undefined` uses the original, unmodified arguments.
|
|
193
202
|
*/
|
|
203
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
194
204
|
async beforeToolCallback(params) {
|
|
195
205
|
return;
|
|
196
206
|
}
|
|
@@ -209,6 +219,7 @@ class BasePlugin {
|
|
|
209
219
|
* post-processing or altering tool outputs. Returning `undefined` uses
|
|
210
220
|
* the original, unmodified result.
|
|
211
221
|
*/
|
|
222
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
212
223
|
async afterToolCallback(params) {
|
|
213
224
|
return;
|
|
214
225
|
}
|
|
@@ -236,6 +247,7 @@ class BasePlugin {
|
|
|
236
247
|
* used as the tool response instead of propagating the error. Returning
|
|
237
248
|
* `undefined` allows the original error to be raised.
|
|
238
249
|
*/
|
|
250
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
239
251
|
async onToolErrorCallback(params) {
|
|
240
252
|
return;
|
|
241
253
|
}
|
|
@@ -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({
|
|
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({
|
|
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({
|
|
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({
|
|
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({
|
|
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({
|
|
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({
|
|
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({
|
|
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(
|
|
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({
|
|
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({
|
|
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({
|
|
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({
|
|
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({
|
|
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({
|
|
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({
|
|
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({
|
|
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({
|
|
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({
|
|
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({
|
|
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({
|
|
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({
|
|
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({
|
|
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({
|
|
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({
|
|
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(
|
|
50
|
+
async evaluate() {
|
|
51
51
|
return Promise.resolve({
|
|
52
52
|
outcome: "ALLOW" /* ALLOW */,
|
|
53
53
|
reason: "For prototyping purpose, all tool calls are allowed."
|