@google/adk 0.1.1 → 0.1.3
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/functions.js +23 -32
- package/dist/cjs/agents/invocation_context.js +1 -3
- package/dist/cjs/agents/llm_agent.js +7 -2
- package/dist/cjs/agents/run_config.js +13 -17
- package/dist/cjs/artifacts/gcs_artifact_service.js +140 -0
- package/dist/cjs/common.js +3 -2
- package/dist/cjs/index.js +5 -5
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/runner/runner.js +2 -1
- package/dist/cjs/sessions/database_session_service.js +52 -0
- package/dist/esm/agents/functions.js +23 -32
- package/dist/esm/agents/invocation_context.js +1 -3
- package/dist/esm/agents/llm_agent.js +7 -2
- package/dist/esm/agents/run_config.js +11 -15
- package/dist/esm/artifacts/gcs_artifact_service.js +110 -0
- package/dist/esm/common.js +3 -2
- package/dist/esm/index.js +5 -5
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/runner/runner.js +3 -2
- package/dist/esm/sessions/database_session_service.js +22 -0
- package/dist/types/agents/run_config.d.ts +19 -7
- package/dist/types/artifacts/gcs_artifact_service.d.ts +16 -0
- package/dist/types/common.d.ts +4 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/models/base_llm.d.ts +7 -4
- package/dist/types/models/google_llm.d.ts +1 -1
- package/dist/types/models/registry.d.ts +6 -2
- package/dist/types/sessions/database_session_service.d.ts +10 -0
- package/dist/web/agents/functions.js +23 -32
- package/dist/web/agents/invocation_context.js +1 -3
- package/dist/web/agents/llm_agent.js +7 -2
- package/dist/web/agents/run_config.js +26 -15
- package/dist/web/artifacts/gcs_artifact_service.js +126 -0
- package/dist/web/common.js +3 -2
- package/dist/web/index.js +1 -1
- package/dist/web/index.js.map +4 -4
- package/dist/web/runner/runner.js +3 -2
- package/dist/web/sessions/database_session_service.js +22 -0
- package/package.json +2 -1
|
@@ -38,6 +38,7 @@ __export(functions_exports, {
|
|
|
38
38
|
removeClientFunctionCallId: () => removeClientFunctionCallId
|
|
39
39
|
});
|
|
40
40
|
module.exports = __toCommonJS(functions_exports);
|
|
41
|
+
var import_genai = require("@google/genai");
|
|
41
42
|
var import_event = require("../events/event.js");
|
|
42
43
|
var import_event_actions = require("../events/event_actions.js");
|
|
43
44
|
var import_tool_context = require("../tools/tool_context.js");
|
|
@@ -166,30 +167,6 @@ async function callToolAsync(tool, args, toolContext) {
|
|
|
166
167
|
import_logger.logger.debug(`callToolAsync ${tool.name}`);
|
|
167
168
|
return await tool.runAsync({ args, toolContext });
|
|
168
169
|
}
|
|
169
|
-
function buildResponseEvent(tool, functionResult, toolContext, invocationContext) {
|
|
170
|
-
let responseResult = functionResult;
|
|
171
|
-
if (typeof functionResult !== "object" || functionResult == null) {
|
|
172
|
-
responseResult = { result: functionResult };
|
|
173
|
-
}
|
|
174
|
-
const partFunctionResponse = {
|
|
175
|
-
functionResponse: {
|
|
176
|
-
name: tool.name,
|
|
177
|
-
response: responseResult,
|
|
178
|
-
id: toolContext.functionCallId
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
const content = {
|
|
182
|
-
role: "user",
|
|
183
|
-
parts: [partFunctionResponse]
|
|
184
|
-
};
|
|
185
|
-
return (0, import_event.createEvent)({
|
|
186
|
-
invocationId: invocationContext.invocationId,
|
|
187
|
-
author: invocationContext.agent.name,
|
|
188
|
-
content,
|
|
189
|
-
actions: toolContext.actions,
|
|
190
|
-
branch: invocationContext.branch
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
170
|
async function handleFunctionCallsAsync({
|
|
194
171
|
invocationContext,
|
|
195
172
|
functionCallEvent,
|
|
@@ -240,6 +217,7 @@ async function handleFunctionCallList({
|
|
|
240
217
|
import_logger.logger.debug(`execute_tool ${tool.name}`);
|
|
241
218
|
const functionArgs = (_a = functionCall.args) != null ? _a : {};
|
|
242
219
|
let functionResponse = null;
|
|
220
|
+
let functionResponseError;
|
|
243
221
|
functionResponse = await invocationContext.pluginManager.runBeforeToolCallback({
|
|
244
222
|
tool,
|
|
245
223
|
toolArgs: functionArgs,
|
|
@@ -276,10 +254,11 @@ async function handleFunctionCallList({
|
|
|
276
254
|
);
|
|
277
255
|
if (onToolErrorResponse) {
|
|
278
256
|
functionResponse = onToolErrorResponse;
|
|
257
|
+
} else {
|
|
258
|
+
functionResponseError = e.message;
|
|
279
259
|
}
|
|
280
260
|
} else {
|
|
281
|
-
|
|
282
|
-
throw e;
|
|
261
|
+
functionResponseError = e;
|
|
283
262
|
}
|
|
284
263
|
}
|
|
285
264
|
}
|
|
@@ -308,12 +287,24 @@ async function handleFunctionCallList({
|
|
|
308
287
|
if (tool.isLongRunning && !functionResponse) {
|
|
309
288
|
continue;
|
|
310
289
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
)
|
|
290
|
+
if (functionResponseError) {
|
|
291
|
+
functionResponse = { error: functionResponseError };
|
|
292
|
+
} else if (typeof functionResponse !== "object" || functionResponse == null) {
|
|
293
|
+
functionResponse = { result: functionResponse };
|
|
294
|
+
}
|
|
295
|
+
const functionResponseEvent = (0, import_event.createEvent)({
|
|
296
|
+
invocationId: invocationContext.invocationId,
|
|
297
|
+
author: invocationContext.agent.name,
|
|
298
|
+
content: (0, import_genai.createUserContent)({
|
|
299
|
+
functionResponse: {
|
|
300
|
+
id: toolContext.functionCallId,
|
|
301
|
+
name: tool.name,
|
|
302
|
+
response: functionResponse
|
|
303
|
+
}
|
|
304
|
+
}),
|
|
305
|
+
actions: toolContext.actions,
|
|
306
|
+
branch: invocationContext.branch
|
|
307
|
+
});
|
|
317
308
|
import_logger.logger.debug("traceToolCall", {
|
|
318
309
|
tool: tool.name,
|
|
319
310
|
args: functionArgs,
|
|
@@ -47,9 +47,7 @@ class InvocationCostManager {
|
|
|
47
47
|
incrementAndEnforceLlmCallsLimit(runConfig) {
|
|
48
48
|
this.numberOfLlmCalls++;
|
|
49
49
|
if (runConfig && runConfig.maxLlmCalls > 0 && this.numberOfLlmCalls > runConfig.maxLlmCalls) {
|
|
50
|
-
throw new Error(
|
|
51
|
-
`Max number of llm calls limit of ${runConfig.maxLlmCalls} exceeded`
|
|
52
|
-
);
|
|
50
|
+
throw new Error(`Max number of llm calls limit of ${runConfig.maxLlmCalls} exceeded`);
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
53
|
}
|
|
@@ -45,6 +45,7 @@ var import_content_processor_utils = require("./content_processor_utils.js");
|
|
|
45
45
|
var import_functions = require("./functions.js");
|
|
46
46
|
var import_instructions = require("./instructions.js");
|
|
47
47
|
var import_readonly_context = require("./readonly_context.js");
|
|
48
|
+
var import_run_config = require("./run_config.js");
|
|
48
49
|
/**
|
|
49
50
|
* @license
|
|
50
51
|
* Copyright 2025 Google LLC
|
|
@@ -743,7 +744,7 @@ class LlmAgent extends import_base_agent.BaseAgent {
|
|
|
743
744
|
return agentToRun;
|
|
744
745
|
}
|
|
745
746
|
async *callLlmAsync(invocationContext, llmRequest, modelResponseEvent) {
|
|
746
|
-
var _a, _b, _c, _d;
|
|
747
|
+
var _a, _b, _c, _d, _e;
|
|
747
748
|
const beforeModelResponse = await this.handleBeforeModelCallback(
|
|
748
749
|
invocationContext,
|
|
749
750
|
llmRequest,
|
|
@@ -763,7 +764,11 @@ class LlmAgent extends import_base_agent.BaseAgent {
|
|
|
763
764
|
throw new Error("CFC is not yet supported in callLlmAsync");
|
|
764
765
|
} else {
|
|
765
766
|
invocationContext.incrementLlmCallCount();
|
|
766
|
-
const responsesGenerator = llm.generateContentAsync(
|
|
767
|
+
const responsesGenerator = llm.generateContentAsync(
|
|
768
|
+
llmRequest,
|
|
769
|
+
/* stream= */
|
|
770
|
+
((_e = invocationContext.runConfig) == null ? void 0 : _e.streamingMode) === import_run_config.StreamingMode.SSE
|
|
771
|
+
);
|
|
767
772
|
for await (const llmResponse of this.runAndHandleError(
|
|
768
773
|
responsesGenerator,
|
|
769
774
|
invocationContext,
|
|
@@ -24,8 +24,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var run_config_exports = {};
|
|
26
26
|
__export(run_config_exports, {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
StreamingMode: () => StreamingMode,
|
|
28
|
+
createRunConfig: () => createRunConfig
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(run_config_exports);
|
|
31
31
|
var import_logger = require("../utils/logger.js");
|
|
@@ -40,19 +40,15 @@ var StreamingMode = /* @__PURE__ */ ((StreamingMode2) => {
|
|
|
40
40
|
StreamingMode2["BIDI"] = "bidi";
|
|
41
41
|
return StreamingMode2;
|
|
42
42
|
})(StreamingMode || {});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.enableAffectiveDialog = params.enableAffectiveDialog || false;
|
|
53
|
-
this.realtimeInputConfig = params.realtimeInputConfig;
|
|
54
|
-
this.maxLlmCalls = validateMaxLlmCalls(params.maxLlmCalls || 500);
|
|
55
|
-
}
|
|
43
|
+
function createRunConfig(params = {}) {
|
|
44
|
+
return {
|
|
45
|
+
saveInputBlobsAsArtifacts: false,
|
|
46
|
+
supportCfc: false,
|
|
47
|
+
enableAffectiveDialog: false,
|
|
48
|
+
streamingMode: "none" /* NONE */,
|
|
49
|
+
maxLlmCalls: validateMaxLlmCalls(params.maxLlmCalls || 500),
|
|
50
|
+
...params
|
|
51
|
+
};
|
|
56
52
|
}
|
|
57
53
|
function validateMaxLlmCalls(value) {
|
|
58
54
|
if (value > Number.MAX_SAFE_INTEGER) {
|
|
@@ -69,6 +65,6 @@ function validateMaxLlmCalls(value) {
|
|
|
69
65
|
}
|
|
70
66
|
// Annotate the CommonJS export names for ESM import in node:
|
|
71
67
|
0 && (module.exports = {
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
StreamingMode,
|
|
69
|
+
createRunConfig
|
|
74
70
|
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var gcs_artifact_service_exports = {};
|
|
26
|
+
__export(gcs_artifact_service_exports, {
|
|
27
|
+
GcsArtifactService: () => GcsArtifactService
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(gcs_artifact_service_exports);
|
|
30
|
+
var import_storage = require("@google-cloud/storage");
|
|
31
|
+
var import_genai = require("@google/genai");
|
|
32
|
+
/**
|
|
33
|
+
* @license
|
|
34
|
+
* Copyright 2025 Google LLC
|
|
35
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
36
|
+
*/
|
|
37
|
+
class GcsArtifactService {
|
|
38
|
+
constructor(bucket) {
|
|
39
|
+
this.bucket = new import_storage.Storage().bucket(bucket);
|
|
40
|
+
}
|
|
41
|
+
async saveArtifact(request) {
|
|
42
|
+
const versions = await this.listVersions(request);
|
|
43
|
+
const version = versions.length > 0 ? Math.max(...versions) + 1 : 0;
|
|
44
|
+
const file = this.bucket.file(getFileName({
|
|
45
|
+
...request,
|
|
46
|
+
version
|
|
47
|
+
}));
|
|
48
|
+
if (request.artifact.inlineData) {
|
|
49
|
+
await file.save(JSON.stringify(request.artifact.inlineData.data), {
|
|
50
|
+
contentType: request.artifact.inlineData.mimeType
|
|
51
|
+
});
|
|
52
|
+
return version;
|
|
53
|
+
}
|
|
54
|
+
if (request.artifact.text) {
|
|
55
|
+
await file.save(request.artifact.text, {
|
|
56
|
+
contentType: "text/plain"
|
|
57
|
+
});
|
|
58
|
+
return version;
|
|
59
|
+
}
|
|
60
|
+
throw new Error("Artifact must have either inlineData or text.");
|
|
61
|
+
}
|
|
62
|
+
async loadArtifact(request) {
|
|
63
|
+
let version = request.version;
|
|
64
|
+
if (version === void 0) {
|
|
65
|
+
const versions = await this.listVersions(request);
|
|
66
|
+
if (versions.length === 0) {
|
|
67
|
+
return void 0;
|
|
68
|
+
}
|
|
69
|
+
version = Math.max(...versions);
|
|
70
|
+
}
|
|
71
|
+
const file = this.bucket.file(getFileName({
|
|
72
|
+
...request,
|
|
73
|
+
version
|
|
74
|
+
}));
|
|
75
|
+
const [[metadata], [rawDataBuffer]] = await Promise.all([file.getMetadata(), file.download()]);
|
|
76
|
+
if (metadata.contentType === "text/plain") {
|
|
77
|
+
return (0, import_genai.createPartFromText)(rawDataBuffer.toString("utf-8"));
|
|
78
|
+
}
|
|
79
|
+
return (0, import_genai.createPartFromBase64)(
|
|
80
|
+
rawDataBuffer.toString("base64"),
|
|
81
|
+
metadata.contentType
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
async listArtifactKeys(request) {
|
|
85
|
+
const fileNames = [];
|
|
86
|
+
const sessionPrefix = `${request.appName}/${request.userId}/${request.sessionId}/`;
|
|
87
|
+
const usernamePrefix = `${request.appName}/${request.userId}/user/`;
|
|
88
|
+
const [
|
|
89
|
+
[sessionFiles],
|
|
90
|
+
[userSessionFiles]
|
|
91
|
+
] = await Promise.all([
|
|
92
|
+
this.bucket.getFiles({ prefix: sessionPrefix }),
|
|
93
|
+
this.bucket.getFiles({ prefix: usernamePrefix })
|
|
94
|
+
]);
|
|
95
|
+
for (const file of sessionFiles) {
|
|
96
|
+
fileNames.push(file.name.split("/").pop());
|
|
97
|
+
}
|
|
98
|
+
for (const file of userSessionFiles) {
|
|
99
|
+
fileNames.push(file.name.split("/").pop());
|
|
100
|
+
}
|
|
101
|
+
return fileNames.sort((a, b) => a.localeCompare(b));
|
|
102
|
+
}
|
|
103
|
+
async deleteArtifact(request) {
|
|
104
|
+
const versions = await this.listVersions(request);
|
|
105
|
+
await Promise.all(versions.map((version) => {
|
|
106
|
+
const file = this.bucket.file(getFileName({
|
|
107
|
+
...request,
|
|
108
|
+
version
|
|
109
|
+
}));
|
|
110
|
+
return file.delete();
|
|
111
|
+
}));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
async listVersions(request) {
|
|
115
|
+
const prefix = getFileName(request);
|
|
116
|
+
const [files] = await this.bucket.getFiles({ prefix });
|
|
117
|
+
const versions = [];
|
|
118
|
+
for (const file of files) {
|
|
119
|
+
const version = file.name.split("/").pop();
|
|
120
|
+
versions.push(parseInt(version, 10));
|
|
121
|
+
}
|
|
122
|
+
return versions;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function getFileName({
|
|
126
|
+
appName,
|
|
127
|
+
userId,
|
|
128
|
+
sessionId,
|
|
129
|
+
filename,
|
|
130
|
+
version
|
|
131
|
+
}) {
|
|
132
|
+
if (filename.startsWith("user:")) {
|
|
133
|
+
return `${appName}/${userId}/user/${filename}/${version}`;
|
|
134
|
+
}
|
|
135
|
+
return `${appName}/${userId}/${sessionId}/${filename}/${version}`;
|
|
136
|
+
}
|
|
137
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
138
|
+
0 && (module.exports = {
|
|
139
|
+
GcsArtifactService
|
|
140
|
+
});
|
package/dist/cjs/common.js
CHANGED
|
@@ -51,7 +51,6 @@ __export(common_exports, {
|
|
|
51
51
|
PluginManager: () => import_plugin_manager.PluginManager,
|
|
52
52
|
PolicyOutcome: () => import_security_plugin.PolicyOutcome,
|
|
53
53
|
REQUEST_CONFIRMATION_FUNCTION_CALL_NAME: () => import_security_plugin.REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
|
|
54
|
-
RunConfig: () => import_run_config.RunConfig,
|
|
55
54
|
Runner: () => import_runner.Runner,
|
|
56
55
|
SecurityPlugin: () => import_security_plugin.SecurityPlugin,
|
|
57
56
|
SequentialAgent: () => import_sequential_agent.SequentialAgent,
|
|
@@ -59,6 +58,7 @@ __export(common_exports, {
|
|
|
59
58
|
ToolConfirmation: () => import_tool_confirmation.ToolConfirmation,
|
|
60
59
|
ToolContext: () => import_tool_context.ToolContext,
|
|
61
60
|
createEvent: () => import_event.createEvent,
|
|
61
|
+
createEventActions: () => import_event_actions.createEventActions,
|
|
62
62
|
createSession: () => import_session.createSession,
|
|
63
63
|
functionsExportedForTestingOnly: () => import_functions.functionsExportedForTestingOnly,
|
|
64
64
|
getAskUserConfirmationFunctionCalls: () => import_security_plugin.getAskUserConfirmationFunctionCalls,
|
|
@@ -83,6 +83,7 @@ var import_run_config = require("./agents/run_config.js");
|
|
|
83
83
|
var import_sequential_agent = require("./agents/sequential_agent.js");
|
|
84
84
|
var import_in_memory_artifact_service = require("./artifacts/in_memory_artifact_service.js");
|
|
85
85
|
var import_event = require("./events/event.js");
|
|
86
|
+
var import_event_actions = require("./events/event_actions.js");
|
|
86
87
|
var import_in_memory_memory_service = require("./memory/in_memory_memory_service.js");
|
|
87
88
|
var import_base_llm = require("./models/base_llm.js");
|
|
88
89
|
var import_google_llm = require("./models/google_llm.js");
|
|
@@ -141,7 +142,6 @@ __reExport(common_exports, require("./tools/base_tool.js"), module.exports);
|
|
|
141
142
|
PluginManager,
|
|
142
143
|
PolicyOutcome,
|
|
143
144
|
REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
|
|
144
|
-
RunConfig,
|
|
145
145
|
Runner,
|
|
146
146
|
SecurityPlugin,
|
|
147
147
|
SequentialAgent,
|
|
@@ -149,6 +149,7 @@ __reExport(common_exports, require("./tools/base_tool.js"), module.exports);
|
|
|
149
149
|
ToolConfirmation,
|
|
150
150
|
ToolContext,
|
|
151
151
|
createEvent,
|
|
152
|
+
createEventActions,
|
|
152
153
|
createSession,
|
|
153
154
|
functionsExportedForTestingOnly,
|
|
154
155
|
getAskUserConfirmationFunctionCalls,
|