@google/adk 0.2.4 → 0.2.5
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 +9 -3
- package/dist/cjs/agents/invocation_context.js +3 -1
- package/dist/cjs/agents/llm_agent.js +129 -75
- package/dist/cjs/agents/loop_agent.js +16 -5
- package/dist/cjs/agents/parallel_agent.js +17 -3
- package/dist/cjs/agents/readonly_context.js +4 -1
- package/dist/cjs/agents/sequential_agent.js +34 -12
- package/dist/cjs/code_executors/base_code_executor.js +12 -2
- package/dist/cjs/code_executors/built_in_code_executor.js +15 -3
- package/dist/cjs/common.js +41 -0
- package/dist/cjs/examples/base_example_provider.js +18 -2
- package/dist/cjs/examples/example_util.js +1 -1
- package/dist/cjs/index.js +11 -11
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/plugins/base_plugin.js +59 -49
- package/dist/cjs/plugins/security_plugin.js +4 -1
- package/dist/cjs/runner/runner.js +34 -24
- package/dist/cjs/tools/agent_tool.js +18 -9
- package/dist/cjs/tools/base_tool.js +16 -6
- package/dist/cjs/tools/function_tool.js +14 -5
- package/dist/cjs/tools/google_search_tool.js +8 -3
- package/dist/cjs/tools/tool_context.js +4 -9
- package/dist/cjs/utils/gemini_schema_util.js +1 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/base_agent.js +9 -3
- package/dist/esm/agents/invocation_context.js +3 -1
- package/dist/esm/agents/llm_agent.js +165 -83
- package/dist/esm/agents/loop_agent.js +14 -4
- package/dist/esm/agents/parallel_agent.js +15 -2
- package/dist/esm/agents/readonly_context.js +4 -1
- package/dist/esm/agents/sequential_agent.js +33 -12
- package/dist/esm/code_executors/base_code_executor.js +10 -1
- package/dist/esm/code_executors/built_in_code_executor.js +13 -2
- package/dist/esm/common.js +53 -10
- package/dist/esm/examples/base_example_provider.js +16 -1
- package/dist/esm/examples/example_util.js +4 -2
- package/dist/esm/index.js +11 -11
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/plugins/base_plugin.js +59 -49
- package/dist/esm/plugins/security_plugin.js +4 -1
- package/dist/esm/runner/runner.js +43 -27
- package/dist/esm/tools/agent_tool.js +17 -9
- package/dist/esm/tools/base_tool.js +14 -5
- package/dist/esm/tools/function_tool.js +13 -7
- package/dist/esm/tools/google_search_tool.js +9 -3
- package/dist/esm/tools/tool_context.js +4 -9
- package/dist/esm/utils/gemini_schema_util.js +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/agents/base_agent.d.ts +14 -3
- package/dist/types/agents/invocation_context.d.ts +4 -2
- package/dist/types/agents/llm_agent.d.ts +42 -30
- package/dist/types/agents/loop_agent.d.ts +16 -0
- package/dist/types/agents/parallel_agent.d.ts +16 -0
- package/dist/types/agents/sequential_agent.d.ts +17 -1
- package/dist/types/auth/auth_schemes.d.ts +5 -2
- package/dist/types/code_executors/base_code_executor.d.ts +14 -0
- package/dist/types/code_executors/built_in_code_executor.d.ts +19 -0
- package/dist/types/common.d.ts +38 -14
- package/dist/types/examples/base_example_provider.d.ts +16 -0
- package/dist/types/plugins/base_plugin.d.ts +50 -40
- package/dist/types/runner/runner.d.ts +17 -9
- package/dist/types/tools/agent_tool.d.ts +14 -0
- package/dist/types/tools/base_tool.d.ts +14 -0
- package/dist/types/tools/function_tool.d.ts +14 -1
- package/dist/types/tools/google_search_tool.d.ts +3 -4
- package/dist/types/tools/tool_context.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/base_agent.js +9 -3
- package/dist/web/agents/invocation_context.js +3 -1
- package/dist/web/agents/llm_agent.js +165 -83
- package/dist/web/agents/loop_agent.js +14 -4
- package/dist/web/agents/parallel_agent.js +15 -2
- package/dist/web/agents/readonly_context.js +4 -1
- package/dist/web/agents/sequential_agent.js +33 -12
- package/dist/web/code_executors/base_code_executor.js +10 -1
- package/dist/web/code_executors/built_in_code_executor.js +13 -2
- package/dist/web/common.js +53 -10
- package/dist/web/examples/base_example_provider.js +16 -1
- package/dist/web/examples/example_util.js +4 -2
- package/dist/web/index.js +1 -1
- package/dist/web/index.js.map +4 -4
- package/dist/web/plugins/base_plugin.js +59 -49
- package/dist/web/plugins/security_plugin.js +4 -1
- package/dist/web/runner/runner.js +44 -28
- package/dist/web/tools/agent_tool.js +17 -9
- package/dist/web/tools/base_tool.js +14 -5
- package/dist/web/tools/function_tool.js +13 -7
- package/dist/web/tools/google_search_tool.js +9 -3
- package/dist/web/tools/tool_context.js +4 -9
- package/dist/web/utils/gemini_schema_util.js +1 -0
- package/dist/web/version.js +1 -1
- package/package.json +2 -2
|
@@ -48,13 +48,13 @@ 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(
|
|
57
|
+
async onUserMessageCallback(params) {
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
@@ -63,13 +63,13 @@ class BasePlugin {
|
|
|
63
63
|
* This is the first callback to be called in the lifecycle, ideal for global
|
|
64
64
|
* setup or initialization tasks.
|
|
65
65
|
*
|
|
66
|
-
* @param invocationContext The context for the entire invocation, containing
|
|
66
|
+
* @param params.invocationContext The context for the entire invocation, containing
|
|
67
67
|
* session information, the root agent, etc.
|
|
68
68
|
* @returns An optional `Event` to be returned to the ADK. Returning a value
|
|
69
69
|
* to halt execution of the runner and ends the runner with that event.
|
|
70
70
|
* Return `undefined` to proceed normally.
|
|
71
71
|
*/
|
|
72
|
-
async beforeRunCallback(
|
|
72
|
+
async beforeRunCallback(params) {
|
|
73
73
|
return;
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
@@ -78,13 +78,13 @@ class BasePlugin {
|
|
|
78
78
|
* This is the ideal place to make modification to the event before the event
|
|
79
79
|
* is handled by the underlying agent app.
|
|
80
80
|
*
|
|
81
|
-
* @param invocationContext The context for the entire invocation.
|
|
82
|
-
* @param event The event raised by the runner.
|
|
81
|
+
* @param params.invocationContext The context for the entire invocation.
|
|
82
|
+
* @param params.event The event raised by the runner.
|
|
83
83
|
* @returns An optional value. A non-`undefined` return may be used by the
|
|
84
84
|
* framework to modify or replace the response. Returning `undefined`
|
|
85
85
|
* allows the original response to be used.
|
|
86
86
|
*/
|
|
87
|
-
async onEventCallback(
|
|
87
|
+
async onEventCallback(params) {
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
@@ -93,10 +93,10 @@ class BasePlugin {
|
|
|
93
93
|
* This is the final callback in the ADK lifecycle, suitable for cleanup,
|
|
94
94
|
* final logging, or reporting tasks.
|
|
95
95
|
*
|
|
96
|
-
* @param invocationContext The context for the entire invocation.
|
|
96
|
+
* @param params.invocationContext The context for the entire invocation.
|
|
97
97
|
* @returns undefined
|
|
98
98
|
*/
|
|
99
|
-
async afterRunCallback(
|
|
99
|
+
async afterRunCallback(params) {
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
@@ -105,13 +105,13 @@ class BasePlugin {
|
|
|
105
105
|
* This callback can be used for logging, setup, or to short-circuit the
|
|
106
106
|
* agent's execution by returning a value.
|
|
107
107
|
*
|
|
108
|
-
* @param agent The agent that is about to run.
|
|
109
|
-
* @param callbackContext The context for the agent invocation.
|
|
108
|
+
* @param params.agent The agent that is about to run.
|
|
109
|
+
* @param params.callbackContext The context for the agent invocation.
|
|
110
110
|
* @returns An optional `Content` object. If a value is returned, it will
|
|
111
111
|
* bypass the agent's callbacks and its execution, and return this value
|
|
112
112
|
* directly. Returning `undefined` allows the agent to proceed normally.
|
|
113
113
|
*/
|
|
114
|
-
async beforeAgentCallback(
|
|
114
|
+
async beforeAgentCallback(params) {
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
@@ -120,13 +120,13 @@ class BasePlugin {
|
|
|
120
120
|
* This callback can be used to inspect, log, or modify the agent's final
|
|
121
121
|
* result before it is returned.
|
|
122
122
|
*
|
|
123
|
-
* @param agent The agent that has just run.
|
|
124
|
-
* @param callbackContext The context for the agent invocation.
|
|
123
|
+
* @param params.agent The agent that has just run.
|
|
124
|
+
* @param params.callbackContext The context for the agent invocation.
|
|
125
125
|
* @returns An optional `Content` object. If a value is returned, it will
|
|
126
126
|
* replace the agent's original result. Returning `undefined` uses the
|
|
127
127
|
* original, unmodified result.
|
|
128
128
|
*/
|
|
129
|
-
async afterAgentCallback(
|
|
129
|
+
async afterAgentCallback(params) {
|
|
130
130
|
return;
|
|
131
131
|
}
|
|
132
132
|
/**
|
|
@@ -136,13 +136,13 @@ class BasePlugin {
|
|
|
136
136
|
* object. It can also be used to implement caching by returning a cached
|
|
137
137
|
* `LlmResponse`, which would skip the actual model call.
|
|
138
138
|
*
|
|
139
|
-
* @param callbackContext The context for the current agent call.
|
|
140
|
-
* @param llmRequest The prepared request object to be sent to the model.
|
|
139
|
+
* @param params.callbackContext The context for the current agent call.
|
|
140
|
+
* @param params.llmRequest The prepared request object to be sent to the model.
|
|
141
141
|
* @returns An optional value. The interpretation of a non-`undefined`
|
|
142
142
|
* trigger an early exit and returns the response immediately. Returning
|
|
143
143
|
* `undefined` allows the LLM request to proceed normally.
|
|
144
144
|
*/
|
|
145
|
-
async beforeModelCallback(
|
|
145
|
+
async beforeModelCallback(params) {
|
|
146
146
|
return;
|
|
147
147
|
}
|
|
148
148
|
/**
|
|
@@ -151,13 +151,13 @@ class BasePlugin {
|
|
|
151
151
|
* This is the ideal place to log model responses, collect metrics on token
|
|
152
152
|
* usage, or perform post-processing on the raw `LlmResponse`.
|
|
153
153
|
*
|
|
154
|
-
* @param callbackContext The context for the current agent call.
|
|
155
|
-
* @param llmResponse The response object received from the model.
|
|
154
|
+
* @param params.callbackContext The context for the current agent call.
|
|
155
|
+
* @param params.llmResponse The response object received from the model.
|
|
156
156
|
* @returns An optional value. A non-`undefined` return may be used by the
|
|
157
157
|
* framework to modify or replace the response. Returning `undefined`
|
|
158
158
|
* allows the original response to be used.
|
|
159
159
|
*/
|
|
160
|
-
async afterModelCallback(
|
|
160
|
+
async afterModelCallback(params) {
|
|
161
161
|
return;
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
@@ -166,15 +166,15 @@ class BasePlugin {
|
|
|
166
166
|
* This callback provides an opportunity to handle model errors gracefully,
|
|
167
167
|
* potentially providing alternative responses or recovery mechanisms.
|
|
168
168
|
*
|
|
169
|
-
* @param callbackContext The context for the current agent call.
|
|
170
|
-
* @param llmRequest The request that was sent to the model when the error
|
|
169
|
+
* @param params.callbackContext The context for the current agent call.
|
|
170
|
+
* @param params.llmRequest The request that was sent to the model when the error
|
|
171
171
|
* occurred.
|
|
172
|
-
* @param error The exception that was raised during model execution.
|
|
172
|
+
* @param params.error The exception that was raised during model execution.
|
|
173
173
|
* @returns An optional LlmResponse. If an LlmResponse is returned, it will be
|
|
174
174
|
* used instead of propagating the error. Returning `undefined` allows
|
|
175
175
|
* the original error to be raised.
|
|
176
176
|
*/
|
|
177
|
-
async onModelErrorCallback(
|
|
177
|
+
async onModelErrorCallback(params) {
|
|
178
178
|
return;
|
|
179
179
|
}
|
|
180
180
|
/**
|
|
@@ -183,15 +183,15 @@ class BasePlugin {
|
|
|
183
183
|
* This callback is useful for logging tool usage, input validation, or
|
|
184
184
|
* modifying the arguments before they are passed to the tool.
|
|
185
185
|
*
|
|
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
|
|
186
|
+
* @param params.tool The tool instance that is about to be executed.
|
|
187
|
+
* @param params.toolArgs The dictionary of arguments to be used for invoking the
|
|
188
188
|
* tool.
|
|
189
|
-
* @param toolContext The context specific to the tool execution.
|
|
189
|
+
* @param params.toolContext The context specific to the tool execution.
|
|
190
190
|
* @returns An optional dictionary. If a dictionary is returned, it will stop
|
|
191
191
|
* the tool execution and return this response immediately. Returning
|
|
192
192
|
* `undefined` uses the original, unmodified arguments.
|
|
193
193
|
*/
|
|
194
|
-
async beforeToolCallback(
|
|
194
|
+
async beforeToolCallback(params) {
|
|
195
195
|
return;
|
|
196
196
|
}
|
|
197
197
|
/**
|
|
@@ -200,33 +200,43 @@ class BasePlugin {
|
|
|
200
200
|
* This callback allows for inspecting, logging, or modifying the result
|
|
201
201
|
* returned by a tool.
|
|
202
202
|
*
|
|
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.
|
|
203
|
+
* @param params.tool The tool instance that has just been executed.
|
|
204
|
+
* @param params.toolArgs The original arguments that were passed to the tool.
|
|
205
|
+
* @param params.toolContext The context specific to the tool execution.
|
|
206
|
+
* @param params.result The dictionary returned by the tool invocation.
|
|
207
207
|
* @returns An optional dictionary. If a dictionary is returned, it will
|
|
208
208
|
* **replace** the original result from the tool. This allows for
|
|
209
209
|
* post-processing or altering tool outputs. Returning `undefined` uses
|
|
210
210
|
* the original, unmodified result.
|
|
211
211
|
*/
|
|
212
|
-
async afterToolCallback(
|
|
212
|
+
async afterToolCallback(params) {
|
|
213
213
|
return;
|
|
214
214
|
}
|
|
215
215
|
/**
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
216
|
+
* Callback executed when a tool call encounters an error.
|
|
217
|
+
tool: BaseTool;
|
|
218
|
+
toolArgs: Record<string, unknown>;
|
|
219
|
+
toolContext: ToolContext;
|
|
220
|
+
result: Record<string, unknown>;
|
|
221
|
+
}): Promise<Record<string, unknown> | undefined> {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Callback executed when a tool call encounters an error.
|
|
227
|
+
*
|
|
228
|
+
* This callback provides an opportunity to handle tool errors gracefully,
|
|
229
|
+
* potentially providing alternative responses or recovery mechanisms.
|
|
230
|
+
*
|
|
231
|
+
* @param params.tool The tool instance that encountered an error.
|
|
232
|
+
* @param params.toolArgs The arguments that were passed to the tool.
|
|
233
|
+
* @param params.toolContext The context specific to the tool execution.
|
|
234
|
+
* @param params.error The exception that was raised during tool execution.
|
|
235
|
+
* @returns An optional dictionary. If a dictionary is returned, it will be
|
|
236
|
+
* used as the tool response instead of propagating the error. Returning
|
|
237
|
+
* `undefined` allows the original error to be raised.
|
|
238
|
+
*/
|
|
239
|
+
async onToolErrorCallback(params) {
|
|
230
240
|
return;
|
|
231
241
|
}
|
|
232
242
|
}
|
|
@@ -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({
|
|
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 */:
|
|
@@ -58,26 +58,26 @@ class Runner {
|
|
|
58
58
|
* Runs the agent with the given message, and returns an async generator of
|
|
59
59
|
* events.
|
|
60
60
|
*
|
|
61
|
-
* @param userId The user ID of the session.
|
|
62
|
-
* @param sessionId The session ID of the session.
|
|
63
|
-
* @param newMessage A new message to append to the session.
|
|
64
|
-
* @param stateDelta An optional state delta to apply to the session.
|
|
65
|
-
* @param runConfig The run config for the agent.
|
|
61
|
+
* @param params.userId The user ID of the session.
|
|
62
|
+
* @param params.sessionId The session ID of the session.
|
|
63
|
+
* @param params.newMessage A new message to append to the session.
|
|
64
|
+
* @param params.stateDelta An optional state delta to apply to the session.
|
|
65
|
+
* @param params.runConfig The run config for the agent.
|
|
66
66
|
* @yields The events generated by the agent.
|
|
67
67
|
*/
|
|
68
68
|
// TODO - b/425992518: user, sessionId, and runConfig can be internalized.
|
|
69
|
-
async *runAsync({
|
|
70
|
-
userId,
|
|
71
|
-
sessionId,
|
|
72
|
-
newMessage,
|
|
73
|
-
stateDelta,
|
|
74
|
-
runConfig
|
|
75
|
-
}) {
|
|
69
|
+
async *runAsync(params) {
|
|
76
70
|
var _a;
|
|
77
|
-
|
|
71
|
+
const { userId, sessionId, stateDelta } = params;
|
|
72
|
+
const runConfig = (0, import_run_config.createRunConfig)(params.runConfig);
|
|
73
|
+
let newMessage = params.newMessage;
|
|
78
74
|
const span = import_api.trace.getTracer("gcp.vertex.agent").startSpan("invocation");
|
|
79
75
|
try {
|
|
80
|
-
const session = await this.sessionService.getSession({
|
|
76
|
+
const session = await this.sessionService.getSession({
|
|
77
|
+
appName: this.appName,
|
|
78
|
+
userId,
|
|
79
|
+
sessionId
|
|
80
|
+
});
|
|
81
81
|
if (!session) {
|
|
82
82
|
if (!this.appName) {
|
|
83
83
|
throw new Error(
|
|
@@ -86,12 +86,14 @@ class Runner {
|
|
|
86
86
|
}
|
|
87
87
|
throw new Error(`Session not found: ${sessionId}`);
|
|
88
88
|
}
|
|
89
|
-
if (runConfig.supportCfc &&
|
|
89
|
+
if (runConfig.supportCfc && (0, import_llm_agent.isLlmAgent)(this.agent)) {
|
|
90
90
|
const modelName = this.agent.canonicalModel.model;
|
|
91
91
|
if (!(0, import_model_name.isGemini2OrAbove)(modelName)) {
|
|
92
|
-
throw new Error(
|
|
92
|
+
throw new Error(
|
|
93
|
+
`CFC is not supported for model: ${modelName} in agent: ${this.agent.name}`
|
|
94
|
+
);
|
|
93
95
|
}
|
|
94
|
-
if (!(this.agent.codeExecutor
|
|
96
|
+
if (!(0, import_built_in_code_executor.isBuiltInCodeExecutor)(this.agent.codeExecutor)) {
|
|
95
97
|
this.agent.codeExecutor = new import_built_in_code_executor.BuiltInCodeExecutor();
|
|
96
98
|
}
|
|
97
99
|
}
|
|
@@ -136,7 +138,10 @@ class Runner {
|
|
|
136
138
|
})
|
|
137
139
|
});
|
|
138
140
|
}
|
|
139
|
-
invocationContext.agent = this.determineAgentForResumption(
|
|
141
|
+
invocationContext.agent = this.determineAgentForResumption(
|
|
142
|
+
session,
|
|
143
|
+
this.agent
|
|
144
|
+
);
|
|
140
145
|
const beforeRunCallbackResponse = await this.pluginManager.runBeforeRunCallback({ invocationContext });
|
|
141
146
|
if (beforeRunCallbackResponse) {
|
|
142
147
|
const earlyExitEvent = (0, import_event.createEvent)({
|
|
@@ -153,9 +158,10 @@ class Runner {
|
|
|
153
158
|
if (!event.partial) {
|
|
154
159
|
await this.sessionService.appendEvent({ session, event });
|
|
155
160
|
}
|
|
156
|
-
const modifiedEvent = await this.pluginManager.runOnEventCallback(
|
|
157
|
-
|
|
158
|
-
|
|
161
|
+
const modifiedEvent = await this.pluginManager.runOnEventCallback({
|
|
162
|
+
invocationContext,
|
|
163
|
+
event
|
|
164
|
+
});
|
|
159
165
|
if (modifiedEvent) {
|
|
160
166
|
yield modifiedEvent;
|
|
161
167
|
} else {
|
|
@@ -222,7 +228,9 @@ class Runner {
|
|
|
222
228
|
}
|
|
223
229
|
const agent = rootAgent.findSubAgent(event2.author);
|
|
224
230
|
if (!agent) {
|
|
225
|
-
import_logger.logger.warn(
|
|
231
|
+
import_logger.logger.warn(
|
|
232
|
+
`Event from an unknown agent: ${event2.author}, event id: ${event2.id}`
|
|
233
|
+
);
|
|
226
234
|
continue;
|
|
227
235
|
}
|
|
228
236
|
if (this.isRoutableLlmAgent(agent)) {
|
|
@@ -245,7 +253,7 @@ class Runner {
|
|
|
245
253
|
isRoutableLlmAgent(agentToRun) {
|
|
246
254
|
let agent = agentToRun;
|
|
247
255
|
while (agent) {
|
|
248
|
-
if (!(
|
|
256
|
+
if (!(0, import_llm_agent.isLlmAgent)(agent)) {
|
|
249
257
|
return false;
|
|
250
258
|
}
|
|
251
259
|
if (agent.disallowTransferToParent) {
|
|
@@ -263,7 +271,9 @@ function findEventByLastFunctionResponseId(events) {
|
|
|
263
271
|
return null;
|
|
264
272
|
}
|
|
265
273
|
const lastEvent = events[events.length - 1];
|
|
266
|
-
const functionCallId = (_d = (_c = (_b = (_a = lastEvent.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.find(
|
|
274
|
+
const functionCallId = (_d = (_c = (_b = (_a = lastEvent.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.find(
|
|
275
|
+
(part) => part.functionResponse
|
|
276
|
+
)) == null ? void 0 : _c.functionResponse) == null ? void 0 : _d.id;
|
|
267
277
|
if (!functionCallId) {
|
|
268
278
|
return null;
|
|
269
279
|
}
|
|
@@ -24,7 +24,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var agent_tool_exports = {};
|
|
26
26
|
__export(agent_tool_exports, {
|
|
27
|
-
AgentTool: () => AgentTool
|
|
27
|
+
AgentTool: () => AgentTool,
|
|
28
|
+
isAgentTool: () => isAgentTool
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(agent_tool_exports);
|
|
30
31
|
var import_genai = require("@google/genai");
|
|
@@ -40,17 +41,24 @@ var import_forwarding_artifact_service = require("./forwarding_artifact_service.
|
|
|
40
41
|
* Copyright 2025 Google LLC
|
|
41
42
|
* SPDX-License-Identifier: Apache-2.0
|
|
42
43
|
*/
|
|
43
|
-
|
|
44
|
+
var _a, _b;
|
|
45
|
+
const AGENT_TOOL_SIGNATURE_SYMBOL = Symbol.for("google.adk.agentTool");
|
|
46
|
+
function isAgentTool(obj) {
|
|
47
|
+
return typeof obj === "object" && obj !== null && AGENT_TOOL_SIGNATURE_SYMBOL in obj && obj[AGENT_TOOL_SIGNATURE_SYMBOL] === true;
|
|
48
|
+
}
|
|
49
|
+
class AgentTool extends (_b = import_base_tool.BaseTool, _a = AGENT_TOOL_SIGNATURE_SYMBOL, _b) {
|
|
44
50
|
constructor(config) {
|
|
45
51
|
super(
|
|
46
52
|
{ name: config.agent.name, description: config.agent.description || "" }
|
|
47
53
|
);
|
|
54
|
+
/** A unique symbol to identify ADK agent tool class. */
|
|
55
|
+
this[_a] = true;
|
|
48
56
|
this.agent = config.agent;
|
|
49
57
|
this.skipSummarization = config.skipSummarization || false;
|
|
50
58
|
}
|
|
51
59
|
_getDeclaration() {
|
|
52
60
|
let declaration;
|
|
53
|
-
if (this.agent
|
|
61
|
+
if ((0, import_llm_agent.isLlmAgent)(this.agent) && this.agent.inputSchema) {
|
|
54
62
|
declaration = {
|
|
55
63
|
name: this.name,
|
|
56
64
|
description: this.description,
|
|
@@ -75,17 +83,17 @@ class AgentTool extends import_base_tool.BaseTool {
|
|
|
75
83
|
};
|
|
76
84
|
}
|
|
77
85
|
if (this.apiVariant !== import_variant_utils.GoogleLLMVariant.GEMINI_API) {
|
|
78
|
-
const hasOutputSchema = this.agent
|
|
86
|
+
const hasOutputSchema = (0, import_llm_agent.isLlmAgent)(this.agent) && this.agent.outputSchema;
|
|
79
87
|
declaration.response = hasOutputSchema ? { type: import_genai.Type.OBJECT } : { type: import_genai.Type.STRING };
|
|
80
88
|
}
|
|
81
89
|
return declaration;
|
|
82
90
|
}
|
|
83
91
|
async runAsync({ args, toolContext }) {
|
|
84
|
-
var
|
|
92
|
+
var _a2, _b2;
|
|
85
93
|
if (this.skipSummarization) {
|
|
86
94
|
toolContext.actions.skipSummarization = true;
|
|
87
95
|
}
|
|
88
|
-
const hasInputSchema = this.agent
|
|
96
|
+
const hasInputSchema = (0, import_llm_agent.isLlmAgent)(this.agent) && this.agent.inputSchema;
|
|
89
97
|
const content = {
|
|
90
98
|
role: "user",
|
|
91
99
|
parts: [
|
|
@@ -120,15 +128,16 @@ class AgentTool extends import_base_tool.BaseTool {
|
|
|
120
128
|
}
|
|
121
129
|
lastEvent = event;
|
|
122
130
|
}
|
|
123
|
-
if (!((
|
|
131
|
+
if (!((_b2 = (_a2 = lastEvent == null ? void 0 : lastEvent.content) == null ? void 0 : _a2.parts) == null ? void 0 : _b2.length)) {
|
|
124
132
|
return "";
|
|
125
133
|
}
|
|
126
|
-
const hasOutputSchema = this.agent
|
|
134
|
+
const hasOutputSchema = (0, import_llm_agent.isLlmAgent)(this.agent) && this.agent.outputSchema;
|
|
127
135
|
const mergedText = lastEvent.content.parts.map((part) => part.text).filter((text) => text).join("\n");
|
|
128
136
|
return hasOutputSchema ? JSON.parse(mergedText) : mergedText;
|
|
129
137
|
}
|
|
130
138
|
}
|
|
131
139
|
// Annotate the CommonJS export names for ESM import in node:
|
|
132
140
|
0 && (module.exports = {
|
|
133
|
-
AgentTool
|
|
141
|
+
AgentTool,
|
|
142
|
+
isAgentTool
|
|
134
143
|
});
|
|
@@ -24,7 +24,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var base_tool_exports = {};
|
|
26
26
|
__export(base_tool_exports, {
|
|
27
|
-
BaseTool: () => BaseTool
|
|
27
|
+
BaseTool: () => BaseTool,
|
|
28
|
+
isBaseTool: () => isBaseTool
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(base_tool_exports);
|
|
30
31
|
var import_variant_utils = require("../utils/variant_utils.js");
|
|
@@ -33,6 +34,12 @@ var import_variant_utils = require("../utils/variant_utils.js");
|
|
|
33
34
|
* Copyright 2025 Google LLC
|
|
34
35
|
* SPDX-License-Identifier: Apache-2.0
|
|
35
36
|
*/
|
|
37
|
+
var _a;
|
|
38
|
+
const BASE_TOOL_SIGNATURE_SYMBOL = Symbol.for("google.adk.baseTool");
|
|
39
|
+
function isBaseTool(obj) {
|
|
40
|
+
return typeof obj === "object" && obj !== null && BASE_TOOL_SIGNATURE_SYMBOL in obj && obj[BASE_TOOL_SIGNATURE_SYMBOL] === true;
|
|
41
|
+
}
|
|
42
|
+
_a = BASE_TOOL_SIGNATURE_SYMBOL;
|
|
36
43
|
class BaseTool {
|
|
37
44
|
/**
|
|
38
45
|
* Base constructor for a tool.
|
|
@@ -40,10 +47,12 @@ class BaseTool {
|
|
|
40
47
|
* @param params The parameters for `BaseTool`.
|
|
41
48
|
*/
|
|
42
49
|
constructor(params) {
|
|
43
|
-
|
|
50
|
+
/** A unique symbol to identify ADK base tool class. */
|
|
51
|
+
this[_a] = true;
|
|
52
|
+
var _a2;
|
|
44
53
|
this.name = params.name;
|
|
45
54
|
this.description = params.description;
|
|
46
|
-
this.isLongRunning = (
|
|
55
|
+
this.isLongRunning = (_a2 = params.isLongRunning) != null ? _a2 : false;
|
|
47
56
|
}
|
|
48
57
|
/**
|
|
49
58
|
* Gets the OpenAPI specification of this tool in the form of a
|
|
@@ -98,10 +107,11 @@ class BaseTool {
|
|
|
98
107
|
}
|
|
99
108
|
}
|
|
100
109
|
function findToolWithFunctionDeclarations(llmRequest) {
|
|
101
|
-
var
|
|
102
|
-
return (((
|
|
110
|
+
var _a2;
|
|
111
|
+
return (((_a2 = llmRequest.config) == null ? void 0 : _a2.tools) || []).find((tool) => "functionDeclarations" in tool);
|
|
103
112
|
}
|
|
104
113
|
// Annotate the CommonJS export names for ESM import in node:
|
|
105
114
|
0 && (module.exports = {
|
|
106
|
-
BaseTool
|
|
115
|
+
BaseTool,
|
|
116
|
+
isBaseTool
|
|
107
117
|
});
|
|
@@ -24,7 +24,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var function_tool_exports = {};
|
|
26
26
|
__export(function_tool_exports, {
|
|
27
|
-
FunctionTool: () => FunctionTool
|
|
27
|
+
FunctionTool: () => FunctionTool,
|
|
28
|
+
isFunctionTool: () => isFunctionTool
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(function_tool_exports);
|
|
30
31
|
var import_genai = require("@google/genai");
|
|
@@ -36,6 +37,7 @@ var import_base_tool = require("./base_tool.js");
|
|
|
36
37
|
* Copyright 2025 Google LLC
|
|
37
38
|
* SPDX-License-Identifier: Apache-2.0
|
|
38
39
|
*/
|
|
40
|
+
var _a, _b;
|
|
39
41
|
function toSchema(parameters) {
|
|
40
42
|
if (parameters === void 0) {
|
|
41
43
|
return { type: import_genai.Type.OBJECT, properties: {} };
|
|
@@ -45,14 +47,18 @@ function toSchema(parameters) {
|
|
|
45
47
|
}
|
|
46
48
|
return parameters;
|
|
47
49
|
}
|
|
48
|
-
|
|
50
|
+
const FUNCTION_TOOL_SIGNATURE_SYMBOL = Symbol.for("google.adk.functionTool");
|
|
51
|
+
function isFunctionTool(obj) {
|
|
52
|
+
return typeof obj === "object" && obj !== null && FUNCTION_TOOL_SIGNATURE_SYMBOL in obj && obj[FUNCTION_TOOL_SIGNATURE_SYMBOL] === true;
|
|
53
|
+
}
|
|
54
|
+
class FunctionTool extends (_b = import_base_tool.BaseTool, _a = FUNCTION_TOOL_SIGNATURE_SYMBOL, _b) {
|
|
49
55
|
/**
|
|
50
56
|
* The constructor acts as the user-friendly factory.
|
|
51
57
|
* @param options The configuration for the tool.
|
|
52
58
|
*/
|
|
53
59
|
constructor(options) {
|
|
54
|
-
var
|
|
55
|
-
const name = (
|
|
60
|
+
var _a2;
|
|
61
|
+
const name = (_a2 = options.name) != null ? _a2 : options.execute.name;
|
|
56
62
|
if (!name) {
|
|
57
63
|
throw new Error(
|
|
58
64
|
"Tool name cannot be empty. Either name the `execute` function or provide a `name`."
|
|
@@ -63,6 +69,8 @@ class FunctionTool extends import_base_tool.BaseTool {
|
|
|
63
69
|
description: options.description,
|
|
64
70
|
isLongRunning: options.isLongRunning
|
|
65
71
|
});
|
|
72
|
+
/** A unique symbol to identify ADK function tool class. */
|
|
73
|
+
this[_a] = true;
|
|
66
74
|
this.execute = options.execute;
|
|
67
75
|
this.parameters = options.parameters;
|
|
68
76
|
}
|
|
@@ -97,5 +105,6 @@ class FunctionTool extends import_base_tool.BaseTool {
|
|
|
97
105
|
}
|
|
98
106
|
// Annotate the CommonJS export names for ESM import in node:
|
|
99
107
|
0 && (module.exports = {
|
|
100
|
-
FunctionTool
|
|
108
|
+
FunctionTool,
|
|
109
|
+
isFunctionTool
|
|
101
110
|
});
|
|
@@ -24,7 +24,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var google_search_tool_exports = {};
|
|
26
26
|
__export(google_search_tool_exports, {
|
|
27
|
-
GOOGLE_SEARCH: () => GOOGLE_SEARCH
|
|
27
|
+
GOOGLE_SEARCH: () => GOOGLE_SEARCH,
|
|
28
|
+
GoogleSearchTool: () => GoogleSearchTool
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(google_search_tool_exports);
|
|
30
31
|
var import_model_name = require("../utils/model_name.js");
|
|
@@ -41,7 +42,10 @@ class GoogleSearchTool extends import_base_tool.BaseTool {
|
|
|
41
42
|
runAsync(request) {
|
|
42
43
|
return Promise.resolve();
|
|
43
44
|
}
|
|
44
|
-
async processLlmRequest({
|
|
45
|
+
async processLlmRequest({
|
|
46
|
+
toolContext,
|
|
47
|
+
llmRequest
|
|
48
|
+
}) {
|
|
45
49
|
if (!llmRequest.model) {
|
|
46
50
|
return;
|
|
47
51
|
}
|
|
@@ -72,5 +76,6 @@ class GoogleSearchTool extends import_base_tool.BaseTool {
|
|
|
72
76
|
const GOOGLE_SEARCH = new GoogleSearchTool();
|
|
73
77
|
// Annotate the CommonJS export names for ESM import in node:
|
|
74
78
|
0 && (module.exports = {
|
|
75
|
-
GOOGLE_SEARCH
|
|
79
|
+
GOOGLE_SEARCH,
|
|
80
|
+
GoogleSearchTool
|
|
76
81
|
});
|
|
@@ -47,15 +47,10 @@ class ToolContext extends import_callback_context.CallbackContext {
|
|
|
47
47
|
* @param params.toolConfirmation The tool confirmation of the current tool
|
|
48
48
|
* call.
|
|
49
49
|
*/
|
|
50
|
-
constructor({
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
toolConfirmation
|
|
55
|
-
}) {
|
|
56
|
-
super({ invocationContext, eventActions });
|
|
57
|
-
this.functionCallId = functionCallId;
|
|
58
|
-
this.toolConfirmation = toolConfirmation;
|
|
50
|
+
constructor(params) {
|
|
51
|
+
super(params);
|
|
52
|
+
this.functionCallId = params.functionCallId;
|
|
53
|
+
this.toolConfirmation = params.toolConfirmation;
|
|
59
54
|
}
|
|
60
55
|
get actions() {
|
|
61
56
|
return this.eventActions;
|
|
@@ -40,6 +40,7 @@ const MCPToolSchema = import_zod.z.object({
|
|
|
40
40
|
required: import_zod.z.string().array().optional()
|
|
41
41
|
});
|
|
42
42
|
function toGeminiType(mcpType) {
|
|
43
|
+
if (!mcpType) return import_genai.Type.TYPE_UNSPECIFIED;
|
|
43
44
|
switch (mcpType.toLowerCase()) {
|
|
44
45
|
case "text":
|
|
45
46
|
case "string":
|
package/dist/cjs/version.js
CHANGED
|
@@ -32,7 +32,7 @@ module.exports = __toCommonJS(version_exports);
|
|
|
32
32
|
* Copyright 2025 Google LLC
|
|
33
33
|
* SPDX-License-Identifier: Apache-2.0
|
|
34
34
|
*/
|
|
35
|
-
const version = "0.2.
|
|
35
|
+
const version = "0.2.5";
|
|
36
36
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
37
|
0 && (module.exports = {
|
|
38
38
|
version
|
|
@@ -24,7 +24,9 @@ class BaseAgent {
|
|
|
24
24
|
this.parentAgent = config.parentAgent;
|
|
25
25
|
this.subAgents = config.subAgents || [];
|
|
26
26
|
this.rootAgent = getRootAgent(this);
|
|
27
|
-
this.beforeAgentCallback = getCannonicalCallback(
|
|
27
|
+
this.beforeAgentCallback = getCannonicalCallback(
|
|
28
|
+
config.beforeAgentCallback
|
|
29
|
+
);
|
|
28
30
|
this.afterAgentCallback = getCannonicalCallback(config.afterAgentCallback);
|
|
29
31
|
this.setParentAgentForSubAgents();
|
|
30
32
|
}
|
|
@@ -186,7 +188,9 @@ class BaseAgent {
|
|
|
186
188
|
setParentAgentForSubAgents() {
|
|
187
189
|
for (const subAgent of this.subAgents) {
|
|
188
190
|
if (subAgent.parentAgent) {
|
|
189
|
-
throw new Error(
|
|
191
|
+
throw new Error(
|
|
192
|
+
`Agent "${subAgent.name}" already has a parent agent, current parent: "${subAgent.parentAgent.name}", trying to add: "${this.name}"`
|
|
193
|
+
);
|
|
190
194
|
}
|
|
191
195
|
subAgent.parentAgent = this;
|
|
192
196
|
}
|
|
@@ -194,7 +198,9 @@ class BaseAgent {
|
|
|
194
198
|
}
|
|
195
199
|
function validateAgentName(name) {
|
|
196
200
|
if (!isIdentifier(name)) {
|
|
197
|
-
throw new Error(
|
|
201
|
+
throw new Error(
|
|
202
|
+
`Found invalid agent name: "${name}". Agent name must be a valid identifier. It should start with a letter (a-z, A-Z) or an underscore (_), and can only contain letters, digits (0-9), and underscores.`
|
|
203
|
+
);
|
|
198
204
|
}
|
|
199
205
|
if (name === "user") {
|
|
200
206
|
throw new Error(
|
|
@@ -17,7 +17,9 @@ class InvocationCostManager {
|
|
|
17
17
|
incrementAndEnforceLlmCallsLimit(runConfig) {
|
|
18
18
|
this.numberOfLlmCalls++;
|
|
19
19
|
if (runConfig && runConfig.maxLlmCalls > 0 && this.numberOfLlmCalls > runConfig.maxLlmCalls) {
|
|
20
|
-
throw new Error(
|
|
20
|
+
throw new Error(
|
|
21
|
+
`Max number of llm calls limit of ${runConfig.maxLlmCalls} exceeded`
|
|
22
|
+
);
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
}
|