@google/adk 1.3.0 → 1.4.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/active_streaming_tool.js +6 -1
- package/dist/cjs/agents/context.js +1 -11
- package/dist/cjs/agents/functions.js +35 -16
- package/dist/cjs/agents/instructions.js +23 -5
- package/dist/cjs/agents/invocation_context.js +2 -5
- package/dist/cjs/agents/llm_agent.js +8 -6
- package/dist/cjs/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/cjs/agents/processors/content_processor_utils.js +16 -3
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +4 -2
- package/dist/cjs/agents/processors/interactions_request_processor.js +63 -0
- package/dist/cjs/apps/app.js +79 -0
- package/dist/cjs/apps/resumability_config.js +44 -0
- package/dist/cjs/artifacts/file_artifact_service.js +14 -1
- package/dist/cjs/artifacts/gcs_artifact_service.js +57 -15
- package/dist/cjs/artifacts/in_memory_artifact_service.js +5 -1
- package/dist/cjs/artifacts/scoped_artifact_service.js +101 -0
- package/dist/cjs/artifacts/session_artifact_service.js +27 -0
- package/dist/cjs/auth/oauth2/oauth2_discovery.js +17 -5
- package/dist/cjs/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/cjs/common.js +47 -0
- package/dist/cjs/context/agent_controlled_context_compactor.js +109 -0
- package/dist/cjs/context/token_based_context_compactor.js +42 -10
- package/dist/cjs/context/trajectory_thought_pruning_compactor.js +71 -0
- package/dist/cjs/events/event.js +24 -0
- package/dist/cjs/models/google_llm.js +25 -10
- package/dist/cjs/models/interactions_utils.js +732 -0
- package/dist/cjs/plugins/base_plugin.js +1 -0
- package/dist/cjs/runner/in_memory_runner.js +13 -2
- package/dist/cjs/runner/runner.js +93 -72
- package/dist/cjs/sessions/base_session_service.js +6 -1
- package/dist/cjs/sessions/database_session_service.js +24 -7
- package/dist/cjs/sessions/vertex_ai_session_service.js +19 -4
- package/dist/cjs/skills/loader.js +2 -2
- package/dist/cjs/tools/base_toolset.js +1 -1
- package/dist/cjs/tools/consolidate_context_tool.js +79 -0
- package/dist/cjs/tools/forwarding_artifact_service.js +16 -28
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +2 -12
- package/dist/cjs/utils/async_hooks_shim.js +52 -0
- package/dist/cjs/utils/client_labels.js +41 -3
- package/dist/cjs/utils/env_aware_utils.js +10 -1
- package/dist/cjs/utils/streaming_utils.js +10 -4
- package/dist/cjs/utils/task.js +62 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/active_streaming_tool.js +6 -1
- package/dist/esm/agents/context.js +1 -11
- package/dist/esm/agents/functions.js +36 -15
- package/dist/esm/agents/instructions.js +23 -5
- package/dist/esm/agents/invocation_context.js +2 -5
- package/dist/esm/agents/llm_agent.js +8 -6
- package/dist/esm/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/esm/agents/processors/content_processor_utils.js +14 -2
- package/dist/esm/agents/processors/context_compactor_request_processor.js +4 -2
- package/dist/esm/agents/processors/interactions_request_processor.js +34 -0
- package/dist/esm/apps/app.js +49 -0
- package/dist/esm/apps/resumability_config.js +16 -0
- package/dist/esm/artifacts/file_artifact_service.js +14 -1
- package/dist/esm/artifacts/gcs_artifact_service.js +57 -15
- package/dist/esm/artifacts/in_memory_artifact_service.js +5 -1
- package/dist/esm/artifacts/scoped_artifact_service.js +73 -0
- package/dist/esm/artifacts/session_artifact_service.js +7 -0
- package/dist/esm/auth/oauth2/oauth2_discovery.js +14 -4
- package/dist/esm/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/esm/common.js +42 -2
- package/dist/esm/context/agent_controlled_context_compactor.js +81 -0
- package/dist/esm/context/token_based_context_compactor.js +42 -10
- package/dist/esm/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/esm/events/event.js +22 -0
- package/dist/esm/models/google_llm.js +23 -9
- package/dist/esm/models/interactions_utils.js +697 -0
- package/dist/esm/plugins/base_plugin.js +1 -0
- package/dist/esm/runner/in_memory_runner.js +13 -2
- package/dist/esm/runner/runner.js +91 -73
- package/dist/esm/sessions/base_session_service.js +6 -1
- package/dist/esm/sessions/database_session_service.js +24 -7
- package/dist/esm/sessions/vertex_ai_session_service.js +17 -3
- package/dist/esm/skills/loader.js +2 -2
- package/dist/esm/tools/base_toolset.js +1 -1
- package/dist/esm/tools/consolidate_context_tool.js +51 -0
- package/dist/esm/tools/forwarding_artifact_service.js +16 -28
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +2 -12
- package/dist/esm/utils/async_hooks_shim.js +24 -0
- package/dist/esm/utils/client_labels.js +38 -2
- package/dist/esm/utils/env_aware_utils.js +10 -1
- package/dist/esm/utils/streaming_utils.js +10 -4
- package/dist/esm/utils/task.js +34 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/agents/active_streaming_tool.d.ts +3 -4
- package/dist/types/agents/functions.d.ts +12 -9
- package/dist/types/agents/invocation_context.d.ts +7 -3
- package/dist/types/agents/processors/content_processor_utils.d.ts +8 -0
- package/dist/types/agents/processors/interactions_request_processor.d.ts +17 -0
- package/dist/types/apps/app.d.ts +52 -0
- package/dist/types/apps/resumability_config.d.ts +27 -0
- package/dist/types/artifacts/base_artifact_service.d.ts +6 -36
- package/dist/types/artifacts/gcs_artifact_service.d.ts +2 -1
- package/dist/types/artifacts/scoped_artifact_service.d.ts +25 -0
- package/dist/types/artifacts/session_artifact_service.d.ts +25 -0
- package/dist/types/auth/oauth2/oauth2_discovery.d.ts +11 -0
- package/dist/types/common.d.ts +20 -3
- package/dist/types/context/agent_controlled_context_compactor.d.ts +24 -0
- package/dist/types/context/base_context_compactor.d.ts +3 -0
- package/dist/types/context/token_based_context_compactor.d.ts +6 -1
- package/dist/types/context/trajectory_thought_pruning_compactor.d.ts +27 -0
- package/dist/types/events/event.d.ts +8 -0
- package/dist/types/models/google_llm.d.ts +15 -1
- package/dist/types/models/interactions_utils.d.ts +92 -0
- package/dist/types/models/llm_request.d.ts +4 -0
- package/dist/types/models/llm_response.d.ts +4 -0
- package/dist/types/plugins/base_plugin.d.ts +2 -1
- package/dist/types/runner/in_memory_runner.d.ts +7 -1
- package/dist/types/runner/runner.d.ts +43 -9
- package/dist/types/sessions/base_session_service.d.ts +3 -16
- package/dist/types/sessions/session.d.ts +11 -0
- package/dist/types/sessions/vertex_ai_session_service.d.ts +9 -1
- package/dist/types/tools/consolidate_context_tool.d.ts +19 -0
- package/dist/types/tools/forwarding_artifact_service.d.ts +3 -2
- package/dist/types/utils/async_hooks_shim.d.ts +10 -0
- package/dist/types/utils/client_labels.d.ts +10 -0
- package/dist/types/utils/env_aware_utils.d.ts +3 -3
- package/dist/types/utils/task.d.ts +24 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/active_streaming_tool.js +6 -1
- package/dist/web/agents/context.js +1 -11
- package/dist/web/agents/functions.js +36 -15
- package/dist/web/agents/instructions.js +23 -5
- package/dist/web/agents/invocation_context.js +2 -5
- package/dist/web/agents/llm_agent.js +8 -6
- package/dist/web/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/web/agents/processors/content_processor_utils.js +14 -2
- package/dist/web/agents/processors/context_compactor_request_processor.js +4 -2
- package/dist/web/agents/processors/interactions_request_processor.js +52 -0
- package/dist/web/apps/app.js +49 -0
- package/dist/web/apps/resumability_config.js +31 -0
- package/dist/web/artifacts/file_artifact_service.js +14 -1
- package/dist/web/artifacts/gcs_artifact_service.js +55 -15
- package/dist/web/artifacts/in_memory_artifact_service.js +5 -1
- package/dist/web/artifacts/scoped_artifact_service.js +86 -0
- package/dist/web/artifacts/session_artifact_service.js +7 -0
- package/dist/web/auth/oauth2/oauth2_discovery.js +14 -4
- package/dist/web/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/web/common.js +42 -2
- package/dist/web/context/agent_controlled_context_compactor.js +81 -0
- package/dist/web/context/token_based_context_compactor.js +42 -10
- package/dist/web/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/web/events/event.js +20 -0
- package/dist/web/models/google_llm.js +54 -9
- package/dist/web/models/interactions_utils.js +728 -0
- package/dist/web/plugins/base_plugin.js +1 -0
- package/dist/web/runner/in_memory_runner.js +13 -2
- package/dist/web/runner/runner.js +111 -75
- package/dist/web/sessions/base_session_service.js +6 -1
- package/dist/web/sessions/database_session_service.js +24 -7
- package/dist/web/sessions/vertex_ai_session_service.js +17 -3
- package/dist/web/skills/loader.js +2 -2
- package/dist/web/tools/base_toolset.js +1 -1
- package/dist/web/tools/consolidate_context_tool.js +51 -0
- package/dist/web/tools/forwarding_artifact_service.js +16 -28
- package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +2 -12
- package/dist/web/utils/async_hooks_shim.js +24 -0
- package/dist/web/utils/client_labels.js +38 -2
- package/dist/web/utils/env_aware_utils.js +10 -1
- package/dist/web/utils/streaming_utils.js +10 -4
- package/dist/web/utils/task.js +34 -0
- package/dist/web/version.js +1 -1
- package/package.json +2 -2
package/dist/esm/events/event.js
CHANGED
|
@@ -65,6 +65,26 @@ function stringifyContent(event) {
|
|
|
65
65
|
return (_a2 = part.text) != null ? _a2 : "";
|
|
66
66
|
}).join("");
|
|
67
67
|
}
|
|
68
|
+
function hasThoughts(event) {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
return !!((_b = (_a = event.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.some((part) => part.thought === true));
|
|
71
|
+
}
|
|
72
|
+
function pruneThoughts(event) {
|
|
73
|
+
var _a;
|
|
74
|
+
if (!((_a = event.content) == null ? void 0 : _a.parts)) {
|
|
75
|
+
return event;
|
|
76
|
+
}
|
|
77
|
+
const prunedParts = event.content.parts.filter(
|
|
78
|
+
(part) => part.thought !== true
|
|
79
|
+
);
|
|
80
|
+
return {
|
|
81
|
+
...event,
|
|
82
|
+
content: {
|
|
83
|
+
...event.content,
|
|
84
|
+
parts: prunedParts
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
68
88
|
const ASCII_LETTERS_AND_NUMBERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
69
89
|
function createNewEventId() {
|
|
70
90
|
let id = "";
|
|
@@ -104,8 +124,10 @@ export {
|
|
|
104
124
|
createNewEventId,
|
|
105
125
|
getFunctionCalls,
|
|
106
126
|
getFunctionResponses,
|
|
127
|
+
hasThoughts,
|
|
107
128
|
hasTrailingCodeExecutionResult,
|
|
108
129
|
isFinalResponse,
|
|
130
|
+
pruneThoughts,
|
|
109
131
|
stringifyContent,
|
|
110
132
|
transformToCamelCaseEvent,
|
|
111
133
|
transformToSnakeCaseEvent
|
|
@@ -5,6 +5,7 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
5
5
|
* Copyright 2025 Google LLC
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
|
+
var _a, _b;
|
|
8
9
|
import {
|
|
9
10
|
createPartFromText,
|
|
10
11
|
GoogleGenAI
|
|
@@ -16,8 +17,13 @@ import { AsyncQueue } from "../utils/async_queue.js";
|
|
|
16
17
|
import { StreamingResponseAggregator } from "../utils/streaming_utils.js";
|
|
17
18
|
import { BaseLlm } from "./base_llm.js";
|
|
18
19
|
import { GeminiLlmConnection } from "./gemini_llm_connection.js";
|
|
20
|
+
import { generateContentViaInteractions } from "./interactions_utils.js";
|
|
19
21
|
import { createLlmResponse } from "./llm_response.js";
|
|
20
|
-
|
|
22
|
+
const GEMINI_MODEL_SYMBOL = Symbol.for("google.adk.geminiModel");
|
|
23
|
+
function isGemini(obj) {
|
|
24
|
+
return typeof obj === "object" && obj !== null && GEMINI_MODEL_SYMBOL in obj && obj[GEMINI_MODEL_SYMBOL] === true;
|
|
25
|
+
}
|
|
26
|
+
class Gemini extends (_b = BaseLlm, _a = GEMINI_MODEL_SYMBOL, _b) {
|
|
21
27
|
/**
|
|
22
28
|
* @param params The parameters for creating a Gemini instance.
|
|
23
29
|
*/
|
|
@@ -27,12 +33,14 @@ class Gemini extends BaseLlm {
|
|
|
27
33
|
vertexai,
|
|
28
34
|
project,
|
|
29
35
|
location,
|
|
30
|
-
headers
|
|
36
|
+
headers,
|
|
37
|
+
useInteractionsApi
|
|
31
38
|
}) {
|
|
32
39
|
if (!model) {
|
|
33
40
|
model = "gemini-2.5-flash";
|
|
34
41
|
}
|
|
35
42
|
super({ model });
|
|
43
|
+
this[_a] = true;
|
|
36
44
|
const params = geminiInitParams({
|
|
37
45
|
model,
|
|
38
46
|
vertexai,
|
|
@@ -50,6 +58,7 @@ class Gemini extends BaseLlm {
|
|
|
50
58
|
this.apiKey = params.apiKey;
|
|
51
59
|
this.headers = headers;
|
|
52
60
|
this.vertexai = !!params.vertexai;
|
|
61
|
+
this.useInteractionsApi = !!useInteractionsApi;
|
|
53
62
|
}
|
|
54
63
|
/**
|
|
55
64
|
* Sends a request to the Gemini model.
|
|
@@ -59,11 +68,15 @@ class Gemini extends BaseLlm {
|
|
|
59
68
|
* @yields LlmResponse: The model response.
|
|
60
69
|
*/
|
|
61
70
|
async *generateContentAsync(llmRequest, stream = false, abortSignal) {
|
|
62
|
-
var
|
|
71
|
+
var _a2, _b2, _c;
|
|
72
|
+
if (this.useInteractionsApi) {
|
|
73
|
+
yield* generateContentViaInteractions(this.apiClient, llmRequest, stream);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
63
76
|
this.preprocessRequest(llmRequest);
|
|
64
77
|
this.maybeAppendUserContent(llmRequest);
|
|
65
78
|
logger.info(
|
|
66
|
-
`Sending out request, model: ${(
|
|
79
|
+
`Sending out request, model: ${(_a2 = llmRequest.model) != null ? _a2 : this.model}, backend: ${this.apiBackend}, stream: ${stream}`
|
|
67
80
|
);
|
|
68
81
|
if (!llmRequest.config) {
|
|
69
82
|
llmRequest.config = {};
|
|
@@ -79,7 +92,7 @@ class Gemini extends BaseLlm {
|
|
|
79
92
|
}
|
|
80
93
|
if (stream) {
|
|
81
94
|
const streamResult = await this.apiClient.models.generateContentStream({
|
|
82
|
-
model: (
|
|
95
|
+
model: (_b2 = llmRequest.model) != null ? _b2 : this.model,
|
|
83
96
|
contents: llmRequest.contents,
|
|
84
97
|
config: llmRequest.config
|
|
85
98
|
});
|
|
@@ -167,8 +180,8 @@ class Gemini extends BaseLlm {
|
|
|
167
180
|
* @returns BaseLlmConnection, the connection to the Gemini model.
|
|
168
181
|
*/
|
|
169
182
|
async connect(llmRequest) {
|
|
170
|
-
var
|
|
171
|
-
if ((
|
|
183
|
+
var _a2, _b2, _c, _d;
|
|
184
|
+
if ((_a2 = llmRequest.liveConnectConfig) == null ? void 0 : _a2.httpOptions) {
|
|
172
185
|
if (!llmRequest.liveConnectConfig.httpOptions.headers) {
|
|
173
186
|
llmRequest.liveConnectConfig.httpOptions.headers = {};
|
|
174
187
|
}
|
|
@@ -178,7 +191,7 @@ class Gemini extends BaseLlm {
|
|
|
178
191
|
);
|
|
179
192
|
llmRequest.liveConnectConfig.httpOptions.apiVersion = this.liveApiVersion;
|
|
180
193
|
}
|
|
181
|
-
if ((
|
|
194
|
+
if ((_b2 = llmRequest.config) == null ? void 0 : _b2.systemInstruction) {
|
|
182
195
|
llmRequest.liveConnectConfig.systemInstruction = {
|
|
183
196
|
role: "system",
|
|
184
197
|
// TODO - b/425992518: validate type casting works well.
|
|
@@ -279,5 +292,6 @@ function geminiInitParams({
|
|
|
279
292
|
}
|
|
280
293
|
export {
|
|
281
294
|
Gemini,
|
|
282
|
-
geminiInitParams
|
|
295
|
+
geminiInitParams,
|
|
296
|
+
isGemini
|
|
283
297
|
};
|