@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.
- package/dist/cjs/agents/base_agent.js +52 -24
- 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/invocation_context.js +3 -1
- package/dist/cjs/agents/llm_agent.js +188 -108
- package/dist/cjs/agents/loop_agent.js +18 -6
- package/dist/cjs/agents/parallel_agent.js +20 -7
- package/dist/cjs/agents/readonly_context.js +4 -1
- package/dist/cjs/agents/sequential_agent.js +34 -12
- 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 +14 -2
- package/dist/cjs/code_executors/built_in_code_executor.js +21 -5
- package/dist/cjs/code_executors/code_executor_context.js +5 -5
- package/dist/cjs/common.js +45 -0
- package/dist/cjs/events/event.js +1 -3
- package/dist/cjs/examples/base_example_provider.js +18 -2
- package/dist/cjs/examples/example_util.js +1 -1
- 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 +71 -49
- 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 +5 -2
- package/dist/cjs/runner/runner.js +126 -101
- 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 +26 -13
- package/dist/cjs/tools/base_tool.js +19 -7
- package/dist/cjs/tools/forwarding_artifact_service.js +1 -1
- package/dist/cjs/tools/function_tool.js +15 -7
- package/dist/cjs/tools/google_search_tool.js +8 -4
- 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/tools/tool_context.js +4 -9
- package/dist/cjs/utils/env_aware_utils.js +1 -1
- package/dist/cjs/utils/gemini_schema_util.js +10 -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 +57 -25
- 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/invocation_context.js +3 -1
- package/dist/esm/agents/llm_agent.js +228 -116
- package/dist/esm/agents/loop_agent.js +16 -5
- package/dist/esm/agents/parallel_agent.js +18 -6
- package/dist/esm/agents/readonly_context.js +4 -1
- package/dist/esm/agents/sequential_agent.js +33 -12
- 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 +12 -1
- package/dist/esm/code_executors/built_in_code_executor.js +19 -4
- package/dist/esm/code_executors/code_executor_context.js +5 -5
- package/dist/esm/common.js +56 -11
- package/dist/esm/events/event.js +1 -3
- package/dist/esm/examples/base_example_provider.js +16 -1
- package/dist/esm/examples/example_util.js +4 -2
- 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 +71 -49
- 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 +5 -2
- package/dist/esm/runner/runner.js +139 -105
- 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 +25 -13
- package/dist/esm/tools/base_tool.js +17 -6
- package/dist/esm/tools/forwarding_artifact_service.js +1 -1
- package/dist/esm/tools/function_tool.js +13 -8
- package/dist/esm/tools/google_search_tool.js +6 -3
- 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/tools/tool_context.js +4 -9
- package/dist/esm/utils/env_aware_utils.js +1 -1
- package/dist/esm/utils/gemini_schema_util.js +10 -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 +16 -4
- package/dist/types/agents/callback_context.d.ts +1 -1
- package/dist/types/agents/invocation_context.d.ts +4 -2
- package/dist/types/agents/llm_agent.d.ts +43 -31
- package/dist/types/agents/loop_agent.d.ts +17 -1
- package/dist/types/agents/parallel_agent.d.ts +17 -1
- package/dist/types/agents/sequential_agent.d.ts +17 -1
- package/dist/types/artifacts/in_memory_artifact_service.d.ts +3 -3
- 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 +20 -1
- package/dist/types/code_executors/code_executor_context.d.ts +2 -4
- package/dist/types/common.d.ts +40 -15
- package/dist/types/examples/base_example_provider.d.ts +16 -0
- 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/base_plugin.d.ts +50 -40
- 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 +18 -10
- 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 +15 -1
- package/dist/types/tools/base_tool.d.ts +15 -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 +18 -4
- package/dist/types/tools/google_search_tool.d.ts +5 -6
- 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/tools/tool_context.d.ts +1 -1
- 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 +103 -36
- 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/invocation_context.js +3 -1
- package/dist/web/agents/llm_agent.js +282 -137
- package/dist/web/agents/loop_agent.js +16 -5
- package/dist/web/agents/parallel_agent.js +18 -6
- package/dist/web/agents/readonly_context.js +4 -1
- package/dist/web/agents/sequential_agent.js +33 -12
- 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 +12 -1
- package/dist/web/code_executors/built_in_code_executor.js +19 -4
- package/dist/web/code_executors/code_executor_context.js +5 -5
- package/dist/web/common.js +56 -11
- package/dist/web/events/event.js +1 -3
- 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/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 +71 -49
- 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 +5 -2
- package/dist/web/runner/runner.js +186 -119
- 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 +25 -13
- package/dist/web/tools/base_tool.js +17 -6
- package/dist/web/tools/forwarding_artifact_service.js +1 -1
- package/dist/web/tools/function_tool.js +13 -8
- package/dist/web/tools/google_search_tool.js +6 -3
- 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/tools/tool_context.js +4 -9
- package/dist/web/utils/env_aware_utils.js +1 -1
- package/dist/web/utils/gemini_schema_util.js +10 -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 +5 -3
|
@@ -4,8 +4,16 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { cloneDeep } from "lodash-es";
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import {
|
|
8
|
+
createEvent,
|
|
9
|
+
getFunctionCalls,
|
|
10
|
+
getFunctionResponses
|
|
11
|
+
} from "../events/event.js";
|
|
12
|
+
import {
|
|
13
|
+
removeClientFunctionCallId,
|
|
14
|
+
REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
|
|
15
|
+
REQUEST_EUC_FUNCTION_CALL_NAME
|
|
16
|
+
} from "./functions.js";
|
|
9
17
|
function getContents(events, agentName, currentBranch) {
|
|
10
18
|
var _a, _b, _c;
|
|
11
19
|
const filteredEvents = [];
|
|
@@ -79,9 +87,11 @@ function convertForeignEvent(event) {
|
|
|
79
87
|
}
|
|
80
88
|
const content = {
|
|
81
89
|
role: "user",
|
|
82
|
-
parts: [
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
parts: [
|
|
91
|
+
{
|
|
92
|
+
text: "For context:"
|
|
93
|
+
}
|
|
94
|
+
]
|
|
85
95
|
};
|
|
86
96
|
for (const part of event.content.parts) {
|
|
87
97
|
if (part.text && !part.thought) {
|
|
@@ -183,10 +193,14 @@ function rearrangeEventsForLatestFunctionResponse(events) {
|
|
|
183
193
|
const functionCallIds = new Set(
|
|
184
194
|
functionCalls.map((fc) => fc.id).filter((id) => !!id)
|
|
185
195
|
);
|
|
186
|
-
const isSubset = Array.from(functionResponsesIds).every(
|
|
196
|
+
const isSubset = Array.from(functionResponsesIds).every(
|
|
197
|
+
(id) => functionCallIds.has(id)
|
|
198
|
+
);
|
|
187
199
|
if (!isSubset) {
|
|
188
200
|
throw new Error(
|
|
189
|
-
"Last response event should only contain the responses for the function calls in the same function call event. Function" + " call ids found : ".concat(Array.from(functionCallIds).join(
|
|
201
|
+
"Last response event should only contain the responses for the function calls in the same function call event. Function" + " call ids found : ".concat(Array.from(functionCallIds).join(
|
|
202
|
+
", "
|
|
203
|
+
), ", function response") + " ids provided: ".concat(Array.from(functionResponsesIds).join(", "))
|
|
190
204
|
);
|
|
191
205
|
}
|
|
192
206
|
functionResponsesIds = functionCallIds;
|
|
@@ -254,7 +268,9 @@ function rearrangeEventsForAsyncFunctionResponsesInHistory(events) {
|
|
|
254
268
|
const [responseIndex] = [...functionResponseEventsIndices];
|
|
255
269
|
resultEvents.push(events[responseIndex]);
|
|
256
270
|
} else {
|
|
257
|
-
const indicesArray = Array.from(functionResponseEventsIndices).sort(
|
|
271
|
+
const indicesArray = Array.from(functionResponseEventsIndices).sort(
|
|
272
|
+
(a, b) => a - b
|
|
273
|
+
);
|
|
258
274
|
const eventsToMerge = indicesArray.map((index) => events[index]);
|
|
259
275
|
resultEvents.push(mergeFunctionResponseEvents(eventsToMerge));
|
|
260
276
|
}
|
|
@@ -270,7 +286,7 @@ function safeStringify(obj) {
|
|
|
270
286
|
}
|
|
271
287
|
try {
|
|
272
288
|
return JSON.stringify(obj);
|
|
273
|
-
} catch (
|
|
289
|
+
} catch (_e) {
|
|
274
290
|
return String(obj);
|
|
275
291
|
}
|
|
276
292
|
}
|
|
@@ -10,6 +10,11 @@ import { mergeEventActions } from "../events/event_actions.js";
|
|
|
10
10
|
import { ToolContext } from "../tools/tool_context.js";
|
|
11
11
|
import { randomUUID } from "../utils/env_aware_utils.js";
|
|
12
12
|
import { logger } from "../utils/logger.js";
|
|
13
|
+
import {
|
|
14
|
+
traceMergedToolCalls,
|
|
15
|
+
tracer,
|
|
16
|
+
traceToolCall
|
|
17
|
+
} from "../telemetry/tracing.js";
|
|
13
18
|
const AF_FUNCTION_CALL_ID_PREFIX = "adk-";
|
|
14
19
|
const REQUEST_EUC_FUNCTION_CALL_NAME = "adk_request_credential";
|
|
15
20
|
const REQUEST_CONFIRMATION_FUNCTION_CALL_NAME = "adk_request_confirmation";
|
|
@@ -127,8 +132,51 @@ function generateRequestConfirmationEvent({
|
|
|
127
132
|
});
|
|
128
133
|
}
|
|
129
134
|
async function callToolAsync(tool, args, toolContext) {
|
|
130
|
-
|
|
131
|
-
|
|
135
|
+
return tracer.startActiveSpan("execute_tool ".concat(tool.name), async (span) => {
|
|
136
|
+
try {
|
|
137
|
+
logger.debug("callToolAsync ".concat(tool.name));
|
|
138
|
+
const result = await tool.runAsync({ args, toolContext });
|
|
139
|
+
traceToolCall({
|
|
140
|
+
tool,
|
|
141
|
+
args,
|
|
142
|
+
functionResponseEvent: buildResponseEvent(
|
|
143
|
+
tool,
|
|
144
|
+
result,
|
|
145
|
+
toolContext,
|
|
146
|
+
toolContext.invocationContext
|
|
147
|
+
)
|
|
148
|
+
});
|
|
149
|
+
return result;
|
|
150
|
+
} finally {
|
|
151
|
+
span.end();
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
function buildResponseEvent(tool, functionResult, toolContext, invocationContext) {
|
|
156
|
+
let responseResult;
|
|
157
|
+
if (typeof functionResult !== "object" || functionResult == null) {
|
|
158
|
+
responseResult = { result: functionResult };
|
|
159
|
+
} else {
|
|
160
|
+
responseResult = functionResult;
|
|
161
|
+
}
|
|
162
|
+
const partFunctionResponse = {
|
|
163
|
+
functionResponse: {
|
|
164
|
+
name: tool.name,
|
|
165
|
+
response: responseResult,
|
|
166
|
+
id: toolContext.functionCallId
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
const content = {
|
|
170
|
+
role: "user",
|
|
171
|
+
parts: [partFunctionResponse]
|
|
172
|
+
};
|
|
173
|
+
return createEvent({
|
|
174
|
+
invocationId: invocationContext.invocationId,
|
|
175
|
+
author: invocationContext.agent.name,
|
|
176
|
+
content,
|
|
177
|
+
actions: toolContext.actions,
|
|
178
|
+
branch: invocationContext.branch
|
|
179
|
+
});
|
|
132
180
|
}
|
|
133
181
|
async function handleFunctionCallsAsync({
|
|
134
182
|
invocationContext,
|
|
@@ -169,14 +217,12 @@ async function handleFunctionCallList({
|
|
|
169
217
|
if (toolConfirmationDict && functionCall.id) {
|
|
170
218
|
toolConfirmation = toolConfirmationDict[functionCall.id];
|
|
171
219
|
}
|
|
172
|
-
const { tool, toolContext } = getToolAndContext(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
);
|
|
220
|
+
const { tool, toolContext } = getToolAndContext({
|
|
221
|
+
invocationContext,
|
|
222
|
+
functionCall,
|
|
223
|
+
toolsDict,
|
|
224
|
+
toolConfirmation
|
|
225
|
+
});
|
|
180
226
|
logger.debug("execute_tool ".concat(tool.name));
|
|
181
227
|
const functionArgs = (_a = functionCall.args) != null ? _a : {};
|
|
182
228
|
let functionResponse = null;
|
|
@@ -200,21 +246,15 @@ async function handleFunctionCallList({
|
|
|
200
246
|
}
|
|
201
247
|
if (functionResponse == null) {
|
|
202
248
|
try {
|
|
203
|
-
functionResponse = await callToolAsync(
|
|
204
|
-
tool,
|
|
205
|
-
functionArgs,
|
|
206
|
-
toolContext
|
|
207
|
-
);
|
|
249
|
+
functionResponse = await callToolAsync(tool, functionArgs, toolContext);
|
|
208
250
|
} catch (e) {
|
|
209
251
|
if (e instanceof Error) {
|
|
210
|
-
const onToolErrorResponse = await invocationContext.pluginManager.runOnToolErrorCallback(
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
);
|
|
252
|
+
const onToolErrorResponse = await invocationContext.pluginManager.runOnToolErrorCallback({
|
|
253
|
+
tool,
|
|
254
|
+
toolArgs: functionArgs,
|
|
255
|
+
toolContext,
|
|
256
|
+
error: e
|
|
257
|
+
});
|
|
218
258
|
if (onToolErrorResponse) {
|
|
219
259
|
functionResponse = onToolErrorResponse;
|
|
220
260
|
} else {
|
|
@@ -278,12 +318,24 @@ async function handleFunctionCallList({
|
|
|
278
318
|
if (!functionResponseEvents.length) {
|
|
279
319
|
return null;
|
|
280
320
|
}
|
|
281
|
-
const mergedEvent = mergeParallelFunctionResponseEvents(
|
|
321
|
+
const mergedEvent = mergeParallelFunctionResponseEvents(
|
|
322
|
+
functionResponseEvents
|
|
323
|
+
);
|
|
282
324
|
if (functionResponseEvents.length > 1) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
325
|
+
tracer.startActiveSpan("execute_tool (merged)", (span) => {
|
|
326
|
+
try {
|
|
327
|
+
logger.debug("execute_tool (merged)");
|
|
328
|
+
logger.debug("traceMergedToolCalls", {
|
|
329
|
+
responseEventId: mergedEvent.id,
|
|
330
|
+
functionResponseEvent: mergedEvent.id
|
|
331
|
+
});
|
|
332
|
+
traceMergedToolCalls({
|
|
333
|
+
responseEventId: mergedEvent.id,
|
|
334
|
+
functionResponseEvent: mergedEvent
|
|
335
|
+
});
|
|
336
|
+
} finally {
|
|
337
|
+
span.end();
|
|
338
|
+
}
|
|
287
339
|
});
|
|
288
340
|
}
|
|
289
341
|
return mergedEvent;
|
|
@@ -321,7 +373,9 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
|
|
|
321
373
|
}
|
|
322
374
|
}
|
|
323
375
|
const baseEvent = functionResponseEvents[0];
|
|
324
|
-
const actionsList = functionResponseEvents.map(
|
|
376
|
+
const actionsList = functionResponseEvents.map(
|
|
377
|
+
(event) => event.actions || {}
|
|
378
|
+
);
|
|
325
379
|
const mergedActions = mergeEventActions(actionsList);
|
|
326
380
|
return createEvent({
|
|
327
381
|
author: baseEvent.author,
|
|
@@ -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 ".concat(runConfig.maxLlmCalls, " exceeded")
|
|
22
|
+
);
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
}
|