@google/adk 0.1.2 → 0.2.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/content_processor_utils.js +20 -8
- package/dist/cjs/agents/functions.js +23 -32
- package/dist/cjs/agents/llm_agent.js +1 -0
- package/dist/cjs/artifacts/gcs_artifact_service.js +140 -0
- package/dist/cjs/common.js +12 -0
- package/dist/cjs/index.js +5 -5
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/models/base_llm.js +12 -3
- package/dist/cjs/models/google_llm.js +6 -20
- package/dist/cjs/models/registry.js +1 -1
- package/dist/cjs/telemetry/google_cloud.js +85 -0
- package/dist/cjs/telemetry/setup.js +97 -0
- package/dist/cjs/telemetry/tracing.js +231 -0
- package/dist/cjs/utils/client_labels.js +56 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/content_processor_utils.js +20 -8
- package/dist/esm/agents/functions.js +23 -32
- package/dist/esm/agents/llm_agent.js +1 -0
- package/dist/esm/artifacts/gcs_artifact_service.js +110 -0
- package/dist/esm/common.js +8 -0
- package/dist/esm/index.js +5 -5
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/models/base_llm.js +12 -3
- package/dist/esm/models/google_llm.js +6 -20
- package/dist/esm/models/registry.js +1 -1
- package/dist/esm/telemetry/google_cloud.js +54 -0
- package/dist/esm/telemetry/setup.js +67 -0
- package/dist/esm/telemetry/tracing.js +195 -0
- package/dist/esm/utils/client_labels.js +26 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/artifacts/gcs_artifact_service.d.ts +16 -0
- package/dist/types/common.d.ts +4 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/models/base_llm.d.ts +6 -3
- package/dist/types/models/google_llm.d.ts +1 -2
- package/dist/types/models/registry.d.ts +6 -2
- package/dist/types/telemetry/google_cloud.d.ts +9 -0
- package/dist/types/telemetry/setup.d.ts +48 -0
- package/dist/types/telemetry/tracing.d.ts +111 -0
- package/dist/types/utils/client_labels.d.ts +9 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/content_processor_utils.js +20 -8
- package/dist/web/agents/functions.js +23 -32
- package/dist/web/agents/llm_agent.js +1 -0
- package/dist/web/artifacts/gcs_artifact_service.js +126 -0
- package/dist/web/common.js +8 -0
- package/dist/web/index.js +1 -1
- package/dist/web/index.js.map +4 -4
- package/dist/web/models/base_llm.js +12 -3
- package/dist/web/models/google_llm.js +6 -20
- package/dist/web/models/registry.js +1 -1
- package/dist/web/telemetry/google_cloud.js +54 -0
- package/dist/web/telemetry/setup.js +67 -0
- package/dist/web/telemetry/tracing.js +210 -0
- package/dist/web/utils/client_labels.js +26 -0
- package/dist/web/version.js +1 -1
- package/package.json +20 -4
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import { createUserContent } from "@google/genai";
|
|
6
7
|
import { createEvent, getFunctionCalls } from "../events/event.js";
|
|
7
8
|
import { mergeEventActions } from "../events/event_actions.js";
|
|
8
9
|
import { ToolContext } from "../tools/tool_context.js";
|
|
@@ -126,30 +127,6 @@ async function callToolAsync(tool, args, toolContext) {
|
|
|
126
127
|
logger.debug(`callToolAsync ${tool.name}`);
|
|
127
128
|
return await tool.runAsync({ args, toolContext });
|
|
128
129
|
}
|
|
129
|
-
function buildResponseEvent(tool, functionResult, toolContext, invocationContext) {
|
|
130
|
-
let responseResult = functionResult;
|
|
131
|
-
if (typeof functionResult !== "object" || functionResult == null) {
|
|
132
|
-
responseResult = { result: functionResult };
|
|
133
|
-
}
|
|
134
|
-
const partFunctionResponse = {
|
|
135
|
-
functionResponse: {
|
|
136
|
-
name: tool.name,
|
|
137
|
-
response: responseResult,
|
|
138
|
-
id: toolContext.functionCallId
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
const content = {
|
|
142
|
-
role: "user",
|
|
143
|
-
parts: [partFunctionResponse]
|
|
144
|
-
};
|
|
145
|
-
return createEvent({
|
|
146
|
-
invocationId: invocationContext.invocationId,
|
|
147
|
-
author: invocationContext.agent.name,
|
|
148
|
-
content,
|
|
149
|
-
actions: toolContext.actions,
|
|
150
|
-
branch: invocationContext.branch
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
130
|
async function handleFunctionCallsAsync({
|
|
154
131
|
invocationContext,
|
|
155
132
|
functionCallEvent,
|
|
@@ -200,6 +177,7 @@ async function handleFunctionCallList({
|
|
|
200
177
|
logger.debug(`execute_tool ${tool.name}`);
|
|
201
178
|
const functionArgs = (_a = functionCall.args) != null ? _a : {};
|
|
202
179
|
let functionResponse = null;
|
|
180
|
+
let functionResponseError;
|
|
203
181
|
functionResponse = await invocationContext.pluginManager.runBeforeToolCallback({
|
|
204
182
|
tool,
|
|
205
183
|
toolArgs: functionArgs,
|
|
@@ -236,10 +214,11 @@ async function handleFunctionCallList({
|
|
|
236
214
|
);
|
|
237
215
|
if (onToolErrorResponse) {
|
|
238
216
|
functionResponse = onToolErrorResponse;
|
|
217
|
+
} else {
|
|
218
|
+
functionResponseError = e.message;
|
|
239
219
|
}
|
|
240
220
|
} else {
|
|
241
|
-
|
|
242
|
-
throw e;
|
|
221
|
+
functionResponseError = e;
|
|
243
222
|
}
|
|
244
223
|
}
|
|
245
224
|
}
|
|
@@ -268,12 +247,24 @@ async function handleFunctionCallList({
|
|
|
268
247
|
if (tool.isLongRunning && !functionResponse) {
|
|
269
248
|
continue;
|
|
270
249
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
250
|
+
if (functionResponseError) {
|
|
251
|
+
functionResponse = { error: functionResponseError };
|
|
252
|
+
} else if (typeof functionResponse !== "object" || functionResponse == null) {
|
|
253
|
+
functionResponse = { result: functionResponse };
|
|
254
|
+
}
|
|
255
|
+
const functionResponseEvent = createEvent({
|
|
256
|
+
invocationId: invocationContext.invocationId,
|
|
257
|
+
author: invocationContext.agent.name,
|
|
258
|
+
content: createUserContent({
|
|
259
|
+
functionResponse: {
|
|
260
|
+
id: toolContext.functionCallId,
|
|
261
|
+
name: tool.name,
|
|
262
|
+
response: functionResponse
|
|
263
|
+
}
|
|
264
|
+
}),
|
|
265
|
+
actions: toolContext.actions,
|
|
266
|
+
branch: invocationContext.branch
|
|
267
|
+
});
|
|
277
268
|
logger.debug("traceToolCall", {
|
|
278
269
|
tool: tool.name,
|
|
279
270
|
args: functionArgs,
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Storage } from "@google-cloud/storage";
|
|
7
|
+
import { createPartFromBase64, createPartFromText } from "@google/genai";
|
|
8
|
+
class GcsArtifactService {
|
|
9
|
+
constructor(bucket) {
|
|
10
|
+
this.bucket = new Storage().bucket(bucket);
|
|
11
|
+
}
|
|
12
|
+
async saveArtifact(request) {
|
|
13
|
+
const versions = await this.listVersions(request);
|
|
14
|
+
const version = versions.length > 0 ? Math.max(...versions) + 1 : 0;
|
|
15
|
+
const file = this.bucket.file(getFileName({
|
|
16
|
+
...request,
|
|
17
|
+
version
|
|
18
|
+
}));
|
|
19
|
+
if (request.artifact.inlineData) {
|
|
20
|
+
await file.save(JSON.stringify(request.artifact.inlineData.data), {
|
|
21
|
+
contentType: request.artifact.inlineData.mimeType
|
|
22
|
+
});
|
|
23
|
+
return version;
|
|
24
|
+
}
|
|
25
|
+
if (request.artifact.text) {
|
|
26
|
+
await file.save(request.artifact.text, {
|
|
27
|
+
contentType: "text/plain"
|
|
28
|
+
});
|
|
29
|
+
return version;
|
|
30
|
+
}
|
|
31
|
+
throw new Error("Artifact must have either inlineData or text.");
|
|
32
|
+
}
|
|
33
|
+
async loadArtifact(request) {
|
|
34
|
+
let version = request.version;
|
|
35
|
+
if (version === void 0) {
|
|
36
|
+
const versions = await this.listVersions(request);
|
|
37
|
+
if (versions.length === 0) {
|
|
38
|
+
return void 0;
|
|
39
|
+
}
|
|
40
|
+
version = Math.max(...versions);
|
|
41
|
+
}
|
|
42
|
+
const file = this.bucket.file(getFileName({
|
|
43
|
+
...request,
|
|
44
|
+
version
|
|
45
|
+
}));
|
|
46
|
+
const [[metadata], [rawDataBuffer]] = await Promise.all([file.getMetadata(), file.download()]);
|
|
47
|
+
if (metadata.contentType === "text/plain") {
|
|
48
|
+
return createPartFromText(rawDataBuffer.toString("utf-8"));
|
|
49
|
+
}
|
|
50
|
+
return createPartFromBase64(
|
|
51
|
+
rawDataBuffer.toString("base64"),
|
|
52
|
+
metadata.contentType
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
async listArtifactKeys(request) {
|
|
56
|
+
const fileNames = [];
|
|
57
|
+
const sessionPrefix = `${request.appName}/${request.userId}/${request.sessionId}/`;
|
|
58
|
+
const usernamePrefix = `${request.appName}/${request.userId}/user/`;
|
|
59
|
+
const [
|
|
60
|
+
[sessionFiles],
|
|
61
|
+
[userSessionFiles]
|
|
62
|
+
] = await Promise.all([
|
|
63
|
+
this.bucket.getFiles({ prefix: sessionPrefix }),
|
|
64
|
+
this.bucket.getFiles({ prefix: usernamePrefix })
|
|
65
|
+
]);
|
|
66
|
+
for (const file of sessionFiles) {
|
|
67
|
+
fileNames.push(file.name.split("/").pop());
|
|
68
|
+
}
|
|
69
|
+
for (const file of userSessionFiles) {
|
|
70
|
+
fileNames.push(file.name.split("/").pop());
|
|
71
|
+
}
|
|
72
|
+
return fileNames.sort((a, b) => a.localeCompare(b));
|
|
73
|
+
}
|
|
74
|
+
async deleteArtifact(request) {
|
|
75
|
+
const versions = await this.listVersions(request);
|
|
76
|
+
await Promise.all(versions.map((version) => {
|
|
77
|
+
const file = this.bucket.file(getFileName({
|
|
78
|
+
...request,
|
|
79
|
+
version
|
|
80
|
+
}));
|
|
81
|
+
return file.delete();
|
|
82
|
+
}));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
async listVersions(request) {
|
|
86
|
+
const prefix = getFileName(request);
|
|
87
|
+
const [files] = await this.bucket.getFiles({ prefix });
|
|
88
|
+
const versions = [];
|
|
89
|
+
for (const file of files) {
|
|
90
|
+
const version = file.name.split("/").pop();
|
|
91
|
+
versions.push(parseInt(version, 10));
|
|
92
|
+
}
|
|
93
|
+
return versions;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function getFileName({
|
|
97
|
+
appName,
|
|
98
|
+
userId,
|
|
99
|
+
sessionId,
|
|
100
|
+
filename,
|
|
101
|
+
version
|
|
102
|
+
}) {
|
|
103
|
+
if (filename.startsWith("user:")) {
|
|
104
|
+
return `${appName}/${userId}/user/${filename}/${version}`;
|
|
105
|
+
}
|
|
106
|
+
return `${appName}/${userId}/${sessionId}/${filename}/${version}`;
|
|
107
|
+
}
|
|
108
|
+
export {
|
|
109
|
+
GcsArtifactService
|
|
110
|
+
};
|
package/dist/esm/common.js
CHANGED
|
@@ -15,9 +15,11 @@ import { StreamingMode } from "./agents/run_config.js";
|
|
|
15
15
|
import { SequentialAgent } from "./agents/sequential_agent.js";
|
|
16
16
|
import { InMemoryArtifactService } from "./artifacts/in_memory_artifact_service.js";
|
|
17
17
|
import { createEvent, getFunctionCalls, getFunctionResponses, hasTrailingCodeExecutionResult, isFinalResponse, stringifyContent } from "./events/event.js";
|
|
18
|
+
import { createEventActions } from "./events/event_actions.js";
|
|
18
19
|
import { InMemoryMemoryService } from "./memory/in_memory_memory_service.js";
|
|
19
20
|
import { BaseLlm } from "./models/base_llm.js";
|
|
20
21
|
import { Gemini } from "./models/google_llm.js";
|
|
22
|
+
import { LLMRegistry } from "./models/registry.js";
|
|
21
23
|
import { BasePlugin } from "./plugins/base_plugin.js";
|
|
22
24
|
import { LoggingPlugin } from "./plugins/logging_plugin.js";
|
|
23
25
|
import { PluginManager } from "./plugins/plugin_manager.js";
|
|
@@ -26,6 +28,7 @@ import { InMemoryRunner } from "./runner/in_memory_runner.js";
|
|
|
26
28
|
import { Runner } from "./runner/runner.js";
|
|
27
29
|
import { InMemorySessionService } from "./sessions/in_memory_session_service.js";
|
|
28
30
|
import { createSession } from "./sessions/session.js";
|
|
31
|
+
import { State } from "./sessions/state.js";
|
|
29
32
|
import { AgentTool } from "./tools/agent_tool.js";
|
|
30
33
|
import { BaseTool } from "./tools/base_tool.js";
|
|
31
34
|
import { BaseToolset } from "./tools/base_toolset.js";
|
|
@@ -36,6 +39,7 @@ import { ToolConfirmation } from "./tools/tool_confirmation.js";
|
|
|
36
39
|
import { ToolContext } from "./tools/tool_context.js";
|
|
37
40
|
import { LogLevel, setLogLevel } from "./utils/logger.js";
|
|
38
41
|
import { zodObjectToSchema } from "./utils/simple_zod_to_json.js";
|
|
42
|
+
import { version } from "./version.js";
|
|
39
43
|
export * from "./artifacts/base_artifact_service.js";
|
|
40
44
|
export * from "./memory/base_memory_service.js";
|
|
41
45
|
export * from "./sessions/base_session_service.js";
|
|
@@ -57,6 +61,7 @@ export {
|
|
|
57
61
|
InMemoryRunner,
|
|
58
62
|
InMemorySessionService,
|
|
59
63
|
InvocationContext,
|
|
64
|
+
LLMRegistry,
|
|
60
65
|
LiveRequestQueue,
|
|
61
66
|
LlmAgent,
|
|
62
67
|
LogLevel,
|
|
@@ -70,10 +75,12 @@ export {
|
|
|
70
75
|
Runner,
|
|
71
76
|
SecurityPlugin,
|
|
72
77
|
SequentialAgent,
|
|
78
|
+
State,
|
|
73
79
|
StreamingMode,
|
|
74
80
|
ToolConfirmation,
|
|
75
81
|
ToolContext,
|
|
76
82
|
createEvent,
|
|
83
|
+
createEventActions,
|
|
77
84
|
createSession,
|
|
78
85
|
functionsExportedForTestingOnly,
|
|
79
86
|
getAskUserConfirmationFunctionCalls,
|
|
@@ -83,5 +90,6 @@ export {
|
|
|
83
90
|
isFinalResponse,
|
|
84
91
|
setLogLevel,
|
|
85
92
|
stringifyContent,
|
|
93
|
+
version,
|
|
86
94
|
zodObjectToSchema
|
|
87
95
|
};
|