@google/adk 1.3.0 → 1.5.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/a2a/agent_to_a2a.js +18 -2
- package/dist/cjs/a2a/event_converter_utils.js +8 -4
- package/dist/cjs/a2a/metadata_converter_utils.js +1 -1
- package/dist/cjs/agents/active_streaming_tool.js +6 -1
- package/dist/cjs/agents/base_agent.js +39 -0
- package/dist/cjs/agents/context.js +1 -11
- package/dist/cjs/agents/functions.js +39 -35
- package/dist/cjs/agents/instructions.js +23 -5
- package/dist/cjs/agents/invocation_context.js +2 -5
- package/dist/cjs/agents/llm_agent.js +10 -7
- package/dist/cjs/agents/loop_agent.js +15 -3
- package/dist/cjs/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/cjs/agents/processors/content_processor_utils.js +18 -4
- 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/agents/routed_agent.js +31 -0
- package/dist/cjs/agents/run_config.js +3 -2
- 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 +12 -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 +76 -0
- package/dist/cjs/context/agent_controlled_context_compactor.js +109 -0
- package/dist/cjs/context/anchored_context_compactor.js +127 -0
- package/dist/cjs/context/compaction_utils.js +52 -0
- package/dist/cjs/context/token_based_context_compactor.js +52 -33
- package/dist/cjs/context/trajectory_thought_pruning_compactor.js +71 -0
- package/dist/cjs/events/compacted_event.js +9 -3
- package/dist/cjs/events/event.js +52 -0
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- 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/plugins/global_instruction_plugin.js +97 -0
- package/dist/cjs/runner/in_memory_runner.js +13 -2
- package/dist/cjs/runner/runner.js +143 -83
- 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/enterprise_web_search_tool.js +81 -0
- package/dist/cjs/tools/example_tool.js +68 -0
- package/dist/cjs/tools/forwarding_artifact_service.js +16 -28
- package/dist/cjs/tools/load_web_page.js +250 -0
- package/dist/cjs/tools/mcp/load_mcp_resource_tool.js +140 -0
- package/dist/cjs/tools/mcp/mcp_toolset.js +63 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -22
- package/dist/cjs/tools/skill/run_skill_inline_script_tool.js +54 -4
- package/dist/cjs/tools/skill/skill_toolset.js +4 -2
- package/dist/cjs/utils/async_hooks_shim.js +52 -0
- package/dist/cjs/utils/branch_trie.js +41 -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 +15 -9
- package/dist/cjs/utils/task.js +62 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/agent_to_a2a.js +18 -2
- package/dist/esm/a2a/event_converter_utils.js +8 -4
- package/dist/esm/a2a/metadata_converter_utils.js +1 -1
- package/dist/esm/agents/active_streaming_tool.js +6 -1
- package/dist/esm/agents/base_agent.js +39 -0
- package/dist/esm/agents/context.js +1 -11
- package/dist/esm/agents/functions.js +43 -32
- package/dist/esm/agents/instructions.js +23 -5
- package/dist/esm/agents/invocation_context.js +2 -5
- package/dist/esm/agents/llm_agent.js +12 -9
- package/dist/esm/agents/loop_agent.js +15 -3
- package/dist/esm/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/esm/agents/processors/content_processor_utils.js +16 -3
- 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/agents/routed_agent.js +31 -0
- package/dist/esm/agents/run_config.js +3 -2
- 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 +12 -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 +67 -3
- package/dist/esm/context/agent_controlled_context_compactor.js +81 -0
- package/dist/esm/context/anchored_context_compactor.js +99 -0
- package/dist/esm/context/compaction_utils.js +27 -0
- package/dist/esm/context/token_based_context_compactor.js +52 -33
- package/dist/esm/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/esm/events/compacted_event.js +7 -2
- package/dist/esm/events/event.js +46 -0
- package/dist/esm/index.js +6 -1
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- 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/plugins/global_instruction_plugin.js +69 -0
- package/dist/esm/runner/in_memory_runner.js +13 -2
- package/dist/esm/runner/runner.js +141 -84
- 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/enterprise_web_search_tool.js +55 -0
- package/dist/esm/tools/example_tool.js +42 -0
- package/dist/esm/tools/forwarding_artifact_service.js +16 -28
- package/dist/esm/tools/load_web_page.js +221 -0
- package/dist/esm/tools/mcp/load_mcp_resource_tool.js +114 -0
- package/dist/esm/tools/mcp/mcp_toolset.js +63 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -22
- package/dist/esm/tools/skill/run_skill_inline_script_tool.js +53 -4
- package/dist/esm/tools/skill/skill_toolset.js +4 -2
- package/dist/esm/utils/async_hooks_shim.js +24 -0
- package/dist/esm/utils/branch_trie.js +13 -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 +11 -5
- package/dist/esm/utils/task.js +34 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +5 -1
- package/dist/types/a2a/agent_to_a2a.d.ts +38 -0
- package/dist/types/agents/active_streaming_tool.d.ts +3 -4
- package/dist/types/agents/base_agent.d.ts +29 -1
- package/dist/types/agents/functions.d.ts +12 -17
- package/dist/types/agents/invocation_context.d.ts +7 -3
- package/dist/types/agents/llm_agent.d.ts +5 -1
- package/dist/types/agents/loop_agent.d.ts +2 -2
- 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/agents/routed_agent.d.ts +24 -1
- package/dist/types/agents/run_config.d.ts +1 -1
- 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 +29 -5
- package/dist/types/context/agent_controlled_context_compactor.d.ts +24 -0
- package/dist/types/context/anchored_context_compactor.d.ts +35 -0
- package/dist/types/context/base_context_compactor.d.ts +3 -0
- package/dist/types/context/compaction_utils.d.ts +15 -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/compacted_event.d.ts +10 -0
- package/dist/types/events/event.d.ts +21 -0
- package/dist/types/index.d.ts +3 -2
- 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/plugins/global_instruction_plugin.d.ts +38 -0
- package/dist/types/runner/in_memory_runner.d.ts +7 -1
- package/dist/types/runner/runner.d.ts +44 -10
- 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/enterprise_web_search_tool.d.ts +26 -0
- package/dist/types/tools/example_tool.d.ts +21 -0
- package/dist/types/tools/forwarding_artifact_service.d.ts +3 -2
- package/dist/types/tools/load_web_page.d.ts +33 -0
- package/dist/types/tools/mcp/load_mcp_resource_tool.d.ts +26 -0
- package/dist/types/tools/mcp/mcp_toolset.d.ts +27 -0
- package/dist/types/tools/skill/run_skill_inline_script_tool.d.ts +25 -0
- package/dist/types/tools/skill/skill_toolset.d.ts +9 -0
- package/dist/types/utils/async_hooks_shim.d.ts +10 -0
- package/dist/types/utils/branch_trie.d.ts +14 -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/a2a/agent_to_a2a.js +18 -2
- package/dist/web/a2a/event_converter_utils.js +8 -4
- package/dist/web/a2a/metadata_converter_utils.js +1 -1
- package/dist/web/agents/active_streaming_tool.js +6 -1
- package/dist/web/agents/base_agent.js +39 -0
- package/dist/web/agents/context.js +1 -11
- package/dist/web/agents/functions.js +43 -32
- package/dist/web/agents/instructions.js +23 -5
- package/dist/web/agents/invocation_context.js +2 -5
- package/dist/web/agents/llm_agent.js +12 -9
- package/dist/web/agents/loop_agent.js +27 -3
- package/dist/web/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/web/agents/processors/content_processor_utils.js +16 -3
- 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/agents/routed_agent.js +31 -0
- package/dist/web/agents/run_config.js +8 -3
- 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 +12 -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 +67 -3
- package/dist/web/context/agent_controlled_context_compactor.js +81 -0
- package/dist/web/context/anchored_context_compactor.js +117 -0
- package/dist/web/context/compaction_utils.js +27 -0
- package/dist/web/context/token_based_context_compactor.js +52 -33
- package/dist/web/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/web/events/compacted_event.js +7 -2
- package/dist/web/events/event.js +44 -0
- package/dist/web/index.js +6 -1
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- 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/plugins/global_instruction_plugin.js +67 -0
- package/dist/web/runner/in_memory_runner.js +13 -2
- package/dist/web/runner/runner.js +157 -84
- 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/enterprise_web_search_tool.js +55 -0
- package/dist/web/tools/example_tool.js +42 -0
- package/dist/web/tools/forwarding_artifact_service.js +16 -28
- package/dist/web/tools/load_web_page.js +221 -0
- package/dist/web/tools/mcp/load_mcp_resource_tool.js +107 -0
- package/dist/web/tools/mcp/mcp_toolset.js +63 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -22
- package/dist/web/tools/skill/run_skill_inline_script_tool.js +51 -4
- package/dist/web/tools/skill/skill_toolset.js +4 -2
- package/dist/web/utils/async_hooks_shim.js +24 -0
- package/dist/web/utils/branch_trie.js +13 -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 +11 -5
- package/dist/web/utils/task.js +34 -0
- package/dist/web/version.js +1 -1
- package/package.json +2 -2
|
@@ -27,13 +27,15 @@ __export(token_based_context_compactor_exports, {
|
|
|
27
27
|
TokenBasedContextCompactor: () => TokenBasedContextCompactor
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(token_based_context_compactor_exports);
|
|
30
|
+
var import_content_processor_utils = require("../agents/processors/content_processor_utils.js");
|
|
30
31
|
var import_compacted_event = require("../events/compacted_event.js");
|
|
31
|
-
var
|
|
32
|
+
var import_compaction_utils = require("./compaction_utils.js");
|
|
32
33
|
/**
|
|
33
34
|
* @license
|
|
34
35
|
* Copyright 2026 Google LLC
|
|
35
36
|
* SPDX-License-Identifier: Apache-2.0
|
|
36
37
|
*/
|
|
38
|
+
const CHARS_PER_TOKEN = 4;
|
|
37
39
|
class TokenBasedContextCompactor {
|
|
38
40
|
constructor(options) {
|
|
39
41
|
this.tokenThreshold = options.tokenThreshold;
|
|
@@ -65,11 +67,21 @@ class TokenBasedContextCompactor {
|
|
|
65
67
|
if (rawEvents.length <= this.eventRetentionSize) {
|
|
66
68
|
return false;
|
|
67
69
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
const retainStartIndex = (0, import_compaction_utils.calculateRetainStartIndex)(
|
|
71
|
+
rawEvents,
|
|
72
|
+
this.eventRetentionSize
|
|
73
|
+
);
|
|
74
|
+
if (retainStartIndex === 0) {
|
|
75
|
+
return false;
|
|
71
76
|
}
|
|
72
|
-
|
|
77
|
+
const promptTokenCount = latestPromptTokenCount(
|
|
78
|
+
activeEvents,
|
|
79
|
+
invocationContext
|
|
80
|
+
);
|
|
81
|
+
if (promptTokenCount === void 0) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
return promptTokenCount > this.tokenThreshold;
|
|
73
85
|
}
|
|
74
86
|
async compact(invocationContext) {
|
|
75
87
|
const events = invocationContext.session.events;
|
|
@@ -78,19 +90,10 @@ class TokenBasedContextCompactor {
|
|
|
78
90
|
if (rawEvents.length <= this.eventRetentionSize) {
|
|
79
91
|
return;
|
|
80
92
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
93
|
+
const retainStartIndex = (0, import_compaction_utils.calculateRetainStartIndex)(
|
|
94
|
+
rawEvents,
|
|
95
|
+
this.eventRetentionSize
|
|
84
96
|
);
|
|
85
|
-
while (retainStartIndex > 0) {
|
|
86
|
-
const eventToRetain = rawEvents[retainStartIndex];
|
|
87
|
-
const previousEvent = rawEvents[retainStartIndex - 1];
|
|
88
|
-
if (hasFunctionResponse(eventToRetain) && hasFunctionCall(previousEvent)) {
|
|
89
|
-
retainStartIndex--;
|
|
90
|
-
} else {
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
97
|
if (retainStartIndex === 0) {
|
|
95
98
|
return;
|
|
96
99
|
}
|
|
@@ -109,25 +112,41 @@ class TokenBasedContextCompactor {
|
|
|
109
112
|
invocationContext.session.events.push(compactedEvent);
|
|
110
113
|
}
|
|
111
114
|
}
|
|
112
|
-
function
|
|
115
|
+
function latestPromptTokenCount(activeEvents, invocationContext) {
|
|
113
116
|
var _a;
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
for (let i = activeEvents.length - 1; i >= 0; i--) {
|
|
118
|
+
const count = (_a = activeEvents[i].usageMetadata) == null ? void 0 : _a.promptTokenCount;
|
|
119
|
+
if (count !== void 0) {
|
|
120
|
+
return count;
|
|
121
|
+
}
|
|
116
122
|
}
|
|
117
|
-
|
|
118
|
-
return Math.ceil(contentStr.length / 4);
|
|
123
|
+
return estimatePromptTokenCount(activeEvents, invocationContext);
|
|
119
124
|
}
|
|
120
|
-
function
|
|
121
|
-
var _a
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
(part
|
|
130
|
-
|
|
125
|
+
function estimatePromptTokenCount(activeEvents, invocationContext) {
|
|
126
|
+
var _a;
|
|
127
|
+
const contents = (0, import_content_processor_utils.getContents)(
|
|
128
|
+
activeEvents,
|
|
129
|
+
invocationContext.agent.name,
|
|
130
|
+
invocationContext.branch
|
|
131
|
+
);
|
|
132
|
+
let totalChars = 0;
|
|
133
|
+
for (const content of contents) {
|
|
134
|
+
for (const part of (_a = content.parts) != null ? _a : []) {
|
|
135
|
+
if (part.text) {
|
|
136
|
+
totalChars += part.text.length;
|
|
137
|
+
}
|
|
138
|
+
if (part.functionCall) {
|
|
139
|
+
totalChars += JSON.stringify(part.functionCall).length;
|
|
140
|
+
}
|
|
141
|
+
if (part.functionResponse) {
|
|
142
|
+
totalChars += JSON.stringify(part.functionResponse).length;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (totalChars <= 0) {
|
|
147
|
+
return void 0;
|
|
148
|
+
}
|
|
149
|
+
return Math.ceil(totalChars / CHARS_PER_TOKEN);
|
|
131
150
|
}
|
|
132
151
|
// Annotate the CommonJS export names for ESM import in node:
|
|
133
152
|
0 && (module.exports = {
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 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 trajectory_thought_pruning_compactor_exports = {};
|
|
26
|
+
__export(trajectory_thought_pruning_compactor_exports, {
|
|
27
|
+
TrajectoryThoughtPruningCompactor: () => TrajectoryThoughtPruningCompactor
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(trajectory_thought_pruning_compactor_exports);
|
|
30
|
+
var import_event = require("../events/event.js");
|
|
31
|
+
/**
|
|
32
|
+
* @license
|
|
33
|
+
* Copyright 2026 Google LLC
|
|
34
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
35
|
+
*/
|
|
36
|
+
class TrajectoryThoughtPruningCompactor {
|
|
37
|
+
constructor(options) {
|
|
38
|
+
if (options.eventRetentionSize < 0) {
|
|
39
|
+
throw new Error("eventRetentionSize must be a non-negative integer.");
|
|
40
|
+
}
|
|
41
|
+
this.eventRetentionSize = options.eventRetentionSize;
|
|
42
|
+
}
|
|
43
|
+
shouldCompact(invocationContext) {
|
|
44
|
+
const events = invocationContext.session.events;
|
|
45
|
+
if (events.length <= this.eventRetentionSize) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
const olderEvents = events.slice(
|
|
49
|
+
0,
|
|
50
|
+
events.length - this.eventRetentionSize
|
|
51
|
+
);
|
|
52
|
+
return olderEvents.some((event) => (0, import_event.hasThoughts)(event));
|
|
53
|
+
}
|
|
54
|
+
compact(invocationContext) {
|
|
55
|
+
const events = invocationContext.session.events;
|
|
56
|
+
if (events.length <= this.eventRetentionSize) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const pruneLimit = events.length - this.eventRetentionSize;
|
|
60
|
+
for (let i = 0; i < pruneLimit; i++) {
|
|
61
|
+
const event = events[i];
|
|
62
|
+
if ((0, import_event.hasThoughts)(event)) {
|
|
63
|
+
events[i] = (0, import_event.pruneThoughts)(event);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
TrajectoryThoughtPruningCompactor
|
|
71
|
+
});
|
|
@@ -25,7 +25,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
25
25
|
var compacted_event_exports = {};
|
|
26
26
|
__export(compacted_event_exports, {
|
|
27
27
|
createCompactedEvent: () => createCompactedEvent,
|
|
28
|
-
isCompactedEvent: () => isCompactedEvent
|
|
28
|
+
isCompactedEvent: () => isCompactedEvent,
|
|
29
|
+
isScratchpadEvent: () => isScratchpadEvent
|
|
29
30
|
});
|
|
30
31
|
module.exports = __toCommonJS(compacted_event_exports);
|
|
31
32
|
var import_event = require("./event.js");
|
|
@@ -37,17 +38,22 @@ var import_event = require("./event.js");
|
|
|
37
38
|
function isCompactedEvent(event) {
|
|
38
39
|
return "isCompacted" in event && event.isCompacted === true;
|
|
39
40
|
}
|
|
41
|
+
function isScratchpadEvent(event) {
|
|
42
|
+
return isCompactedEvent(event) && event.isScratchpad === true;
|
|
43
|
+
}
|
|
40
44
|
function createCompactedEvent(params = {}) {
|
|
41
45
|
return {
|
|
42
46
|
...(0, import_event.createEvent)(params),
|
|
43
47
|
isCompacted: params.isCompacted || true,
|
|
44
48
|
startTime: params.startTime,
|
|
45
49
|
endTime: params.endTime,
|
|
46
|
-
compactedContent: params.compactedContent
|
|
50
|
+
compactedContent: params.compactedContent,
|
|
51
|
+
isScratchpad: params.isScratchpad
|
|
47
52
|
};
|
|
48
53
|
}
|
|
49
54
|
// Annotate the CommonJS export names for ESM import in node:
|
|
50
55
|
0 && (module.exports = {
|
|
51
56
|
createCompactedEvent,
|
|
52
|
-
isCompactedEvent
|
|
57
|
+
isCompactedEvent,
|
|
58
|
+
isScratchpadEvent
|
|
53
59
|
});
|
package/dist/cjs/events/event.js
CHANGED
|
@@ -24,17 +24,24 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var event_exports = {};
|
|
26
26
|
__export(event_exports, {
|
|
27
|
+
AF_FUNCTION_CALL_ID_PREFIX: () => AF_FUNCTION_CALL_ID_PREFIX,
|
|
27
28
|
createEvent: () => createEvent,
|
|
28
29
|
createNewEventId: () => createNewEventId,
|
|
30
|
+
generateClientFunctionCallId: () => generateClientFunctionCallId,
|
|
31
|
+
getEventTokens: () => getEventTokens,
|
|
29
32
|
getFunctionCalls: () => getFunctionCalls,
|
|
30
33
|
getFunctionResponses: () => getFunctionResponses,
|
|
34
|
+
hasThoughts: () => hasThoughts,
|
|
31
35
|
hasTrailingCodeExecutionResult: () => hasTrailingCodeExecutionResult,
|
|
32
36
|
isFinalResponse: () => isFinalResponse,
|
|
37
|
+
populateClientFunctionCallId: () => populateClientFunctionCallId,
|
|
38
|
+
pruneThoughts: () => pruneThoughts,
|
|
33
39
|
stringifyContent: () => stringifyContent,
|
|
34
40
|
transformToCamelCaseEvent: () => transformToCamelCaseEvent,
|
|
35
41
|
transformToSnakeCaseEvent: () => transformToSnakeCaseEvent
|
|
36
42
|
});
|
|
37
43
|
module.exports = __toCommonJS(event_exports);
|
|
44
|
+
var import_env_aware_utils = require("../utils/env_aware_utils.js");
|
|
38
45
|
var import_object_notation_utils = require("../utils/object_notation_utils.js");
|
|
39
46
|
var import_event_actions = require("./event_actions.js");
|
|
40
47
|
/**
|
|
@@ -71,6 +78,17 @@ function getFunctionCalls(event) {
|
|
|
71
78
|
}
|
|
72
79
|
return funcCalls;
|
|
73
80
|
}
|
|
81
|
+
const AF_FUNCTION_CALL_ID_PREFIX = "adk-";
|
|
82
|
+
function generateClientFunctionCallId() {
|
|
83
|
+
return `${AF_FUNCTION_CALL_ID_PREFIX}${(0, import_env_aware_utils.randomUUID)()}`;
|
|
84
|
+
}
|
|
85
|
+
function populateClientFunctionCallId(modelResponseEvent) {
|
|
86
|
+
for (const functionCall of getFunctionCalls(modelResponseEvent)) {
|
|
87
|
+
if (!functionCall.id) {
|
|
88
|
+
functionCall.id = generateClientFunctionCallId();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
74
92
|
function getFunctionResponses(event) {
|
|
75
93
|
const funcResponses = [];
|
|
76
94
|
if (event.content && event.content.parts) {
|
|
@@ -100,6 +118,34 @@ function stringifyContent(event) {
|
|
|
100
118
|
return (_a2 = part.text) != null ? _a2 : "";
|
|
101
119
|
}).join("");
|
|
102
120
|
}
|
|
121
|
+
function getEventTokens(event) {
|
|
122
|
+
var _a;
|
|
123
|
+
if (((_a = event.usageMetadata) == null ? void 0 : _a.promptTokenCount) !== void 0) {
|
|
124
|
+
return event.usageMetadata.promptTokenCount;
|
|
125
|
+
}
|
|
126
|
+
const contentStr = stringifyContent(event);
|
|
127
|
+
return Math.ceil(contentStr.length / 4);
|
|
128
|
+
}
|
|
129
|
+
function hasThoughts(event) {
|
|
130
|
+
var _a, _b;
|
|
131
|
+
return !!((_b = (_a = event.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.some((part) => part.thought === true));
|
|
132
|
+
}
|
|
133
|
+
function pruneThoughts(event) {
|
|
134
|
+
var _a;
|
|
135
|
+
if (!((_a = event.content) == null ? void 0 : _a.parts)) {
|
|
136
|
+
return event;
|
|
137
|
+
}
|
|
138
|
+
const prunedParts = event.content.parts.filter(
|
|
139
|
+
(part) => part.thought !== true
|
|
140
|
+
);
|
|
141
|
+
return {
|
|
142
|
+
...event,
|
|
143
|
+
content: {
|
|
144
|
+
...event.content,
|
|
145
|
+
parts: prunedParts
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
}
|
|
103
149
|
const ASCII_LETTERS_AND_NUMBERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
104
150
|
function createNewEventId() {
|
|
105
151
|
let id = "";
|
|
@@ -136,12 +182,18 @@ function transformToSnakeCaseEvent(event) {
|
|
|
136
182
|
}
|
|
137
183
|
// Annotate the CommonJS export names for ESM import in node:
|
|
138
184
|
0 && (module.exports = {
|
|
185
|
+
AF_FUNCTION_CALL_ID_PREFIX,
|
|
139
186
|
createEvent,
|
|
140
187
|
createNewEventId,
|
|
188
|
+
generateClientFunctionCallId,
|
|
189
|
+
getEventTokens,
|
|
141
190
|
getFunctionCalls,
|
|
142
191
|
getFunctionResponses,
|
|
192
|
+
hasThoughts,
|
|
143
193
|
hasTrailingCodeExecutionResult,
|
|
144
194
|
isFinalResponse,
|
|
195
|
+
populateClientFunctionCallId,
|
|
196
|
+
pruneThoughts,
|
|
145
197
|
stringifyContent,
|
|
146
198
|
transformToCamelCaseEvent,
|
|
147
199
|
transformToSnakeCaseEvent
|
package/dist/cjs/index.js
CHANGED
|
@@ -34,6 +34,7 @@ __export(index_exports, {
|
|
|
34
34
|
GcsArtifactService: () => import_gcs_artifact_service.GcsArtifactService,
|
|
35
35
|
InvocationContext: () => import_invocation_context.InvocationContext,
|
|
36
36
|
RemoteA2AAgent: () => import_a2a_remote_agent.RemoteA2AAgent,
|
|
37
|
+
RunSkillInlineScriptErrorCode: () => import_run_skill_inline_script_tool.RunSkillInlineScriptErrorCode,
|
|
37
38
|
RunSkillInlineScriptTool: () => import_run_skill_inline_script_tool.RunSkillInlineScriptTool,
|
|
38
39
|
RunSkillScriptTool: () => import_run_skill_script_tool.RunSkillScriptTool,
|
|
39
40
|
UnsafeLocalCodeExecutor: () => import_unsafe_local_code_executor.UnsafeLocalCodeExecutor,
|
|
@@ -68,6 +69,7 @@ var import_run_skill_script_tool = require("./tools/skill/run_skill_script_tool.
|
|
|
68
69
|
__reExport(index_exports, require("./integrations/agent_registry/agent_registry.js"), module.exports);
|
|
69
70
|
__reExport(index_exports, require("./telemetry/google_cloud.js"), module.exports);
|
|
70
71
|
__reExport(index_exports, require("./telemetry/setup.js"), module.exports);
|
|
72
|
+
__reExport(index_exports, require("./tools/mcp/load_mcp_resource_tool.js"), module.exports);
|
|
71
73
|
__reExport(index_exports, require("./tools/mcp/mcp_session_manager.js"), module.exports);
|
|
72
74
|
__reExport(index_exports, require("./tools/mcp/mcp_tool.js"), module.exports);
|
|
73
75
|
__reExport(index_exports, require("./tools/mcp/mcp_toolset.js"), module.exports);
|
|
@@ -87,6 +89,7 @@ __reExport(index_exports, require("./tools/mcp/mcp_toolset.js"), module.exports)
|
|
|
87
89
|
GcsArtifactService,
|
|
88
90
|
InvocationContext,
|
|
89
91
|
RemoteA2AAgent,
|
|
92
|
+
RunSkillInlineScriptErrorCode,
|
|
90
93
|
RunSkillInlineScriptTool,
|
|
91
94
|
RunSkillScriptTool,
|
|
92
95
|
UnsafeLocalCodeExecutor,
|
|
@@ -102,6 +105,7 @@ __reExport(index_exports, require("./tools/mcp/mcp_toolset.js"), module.exports)
|
|
|
102
105
|
...require("./integrations/agent_registry/agent_registry.js"),
|
|
103
106
|
...require("./telemetry/google_cloud.js"),
|
|
104
107
|
...require("./telemetry/setup.js"),
|
|
108
|
+
...require("./tools/mcp/load_mcp_resource_tool.js"),
|
|
105
109
|
...require("./tools/mcp/mcp_session_manager.js"),
|
|
106
110
|
...require("./tools/mcp/mcp_tool.js"),
|
|
107
111
|
...require("./tools/mcp/mcp_toolset.js")
|
|
@@ -30,6 +30,7 @@ module.exports = __toCommonJS(agent_registry_mcp_toolset_exports);
|
|
|
30
30
|
var import_base_toolset = require("../../tools/base_toolset.js");
|
|
31
31
|
var import_mcp_session_manager = require("../../tools/mcp/mcp_session_manager.js");
|
|
32
32
|
var import_mcp_tool = require("../../tools/mcp/mcp_tool.js");
|
|
33
|
+
var import_logger = require("../../utils/logger.js");
|
|
33
34
|
var import_types2 = require("./types.js");
|
|
34
35
|
/**
|
|
35
36
|
* @license
|
|
@@ -90,7 +91,14 @@ class AgentRegistrySingleMCPToolset extends import_base_toolset.BaseToolset {
|
|
|
90
91
|
};
|
|
91
92
|
const sessionManager = new import_mcp_session_manager.MCPSessionManager(connectionParamsCopy);
|
|
92
93
|
const session = await sessionManager.createSession();
|
|
93
|
-
|
|
94
|
+
let listResult;
|
|
95
|
+
try {
|
|
96
|
+
listResult = await session.listTools();
|
|
97
|
+
} finally {
|
|
98
|
+
await sessionManager.closeSession(session).catch((e) => {
|
|
99
|
+
import_logger.logger.warn("Failed to close MCP discovery session", e);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
94
102
|
const tools = listResult.tools.map((tool) => {
|
|
95
103
|
const prefixedName = this.prefix ? `${this.prefix}_${tool.name}` : tool.name;
|
|
96
104
|
const mcpTool = new import_mcp_tool.MCPTool(
|
|
@@ -25,7 +25,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
25
25
|
var google_llm_exports = {};
|
|
26
26
|
__export(google_llm_exports, {
|
|
27
27
|
Gemini: () => Gemini,
|
|
28
|
-
geminiInitParams: () => geminiInitParams
|
|
28
|
+
geminiInitParams: () => geminiInitParams,
|
|
29
|
+
isGemini: () => isGemini
|
|
29
30
|
});
|
|
30
31
|
module.exports = __toCommonJS(google_llm_exports);
|
|
31
32
|
var import_genai = require("@google/genai");
|
|
@@ -36,13 +37,19 @@ var import_async_queue = require("../utils/async_queue.js");
|
|
|
36
37
|
var import_streaming_utils = require("../utils/streaming_utils.js");
|
|
37
38
|
var import_base_llm = require("./base_llm.js");
|
|
38
39
|
var import_gemini_llm_connection = require("./gemini_llm_connection.js");
|
|
40
|
+
var import_interactions_utils = require("./interactions_utils.js");
|
|
39
41
|
var import_llm_response = require("./llm_response.js");
|
|
40
42
|
/**
|
|
41
43
|
* @license
|
|
42
44
|
* Copyright 2025 Google LLC
|
|
43
45
|
* SPDX-License-Identifier: Apache-2.0
|
|
44
46
|
*/
|
|
45
|
-
|
|
47
|
+
var _a, _b;
|
|
48
|
+
const GEMINI_MODEL_SYMBOL = Symbol.for("google.adk.geminiModel");
|
|
49
|
+
function isGemini(obj) {
|
|
50
|
+
return typeof obj === "object" && obj !== null && GEMINI_MODEL_SYMBOL in obj && obj[GEMINI_MODEL_SYMBOL] === true;
|
|
51
|
+
}
|
|
52
|
+
class Gemini extends (_b = import_base_llm.BaseLlm, _a = GEMINI_MODEL_SYMBOL, _b) {
|
|
46
53
|
/**
|
|
47
54
|
* @param params The parameters for creating a Gemini instance.
|
|
48
55
|
*/
|
|
@@ -52,12 +59,14 @@ class Gemini extends import_base_llm.BaseLlm {
|
|
|
52
59
|
vertexai,
|
|
53
60
|
project,
|
|
54
61
|
location,
|
|
55
|
-
headers
|
|
62
|
+
headers,
|
|
63
|
+
useInteractionsApi
|
|
56
64
|
}) {
|
|
57
65
|
if (!model) {
|
|
58
66
|
model = "gemini-2.5-flash";
|
|
59
67
|
}
|
|
60
68
|
super({ model });
|
|
69
|
+
this[_a] = true;
|
|
61
70
|
const params = geminiInitParams({
|
|
62
71
|
model,
|
|
63
72
|
vertexai,
|
|
@@ -75,6 +84,7 @@ class Gemini extends import_base_llm.BaseLlm {
|
|
|
75
84
|
this.apiKey = params.apiKey;
|
|
76
85
|
this.headers = headers;
|
|
77
86
|
this.vertexai = !!params.vertexai;
|
|
87
|
+
this.useInteractionsApi = !!useInteractionsApi;
|
|
78
88
|
}
|
|
79
89
|
/**
|
|
80
90
|
* Sends a request to the Gemini model.
|
|
@@ -84,11 +94,15 @@ class Gemini extends import_base_llm.BaseLlm {
|
|
|
84
94
|
* @yields LlmResponse: The model response.
|
|
85
95
|
*/
|
|
86
96
|
async *generateContentAsync(llmRequest, stream = false, abortSignal) {
|
|
87
|
-
var
|
|
97
|
+
var _a2, _b2, _c;
|
|
98
|
+
if (this.useInteractionsApi) {
|
|
99
|
+
yield* (0, import_interactions_utils.generateContentViaInteractions)(this.apiClient, llmRequest, stream);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
88
102
|
this.preprocessRequest(llmRequest);
|
|
89
103
|
this.maybeAppendUserContent(llmRequest);
|
|
90
104
|
import_logger.logger.info(
|
|
91
|
-
`Sending out request, model: ${(
|
|
105
|
+
`Sending out request, model: ${(_a2 = llmRequest.model) != null ? _a2 : this.model}, backend: ${this.apiBackend}, stream: ${stream}`
|
|
92
106
|
);
|
|
93
107
|
if (!llmRequest.config) {
|
|
94
108
|
llmRequest.config = {};
|
|
@@ -104,7 +118,7 @@ class Gemini extends import_base_llm.BaseLlm {
|
|
|
104
118
|
}
|
|
105
119
|
if (stream) {
|
|
106
120
|
const streamResult = await this.apiClient.models.generateContentStream({
|
|
107
|
-
model: (
|
|
121
|
+
model: (_b2 = llmRequest.model) != null ? _b2 : this.model,
|
|
108
122
|
contents: llmRequest.contents,
|
|
109
123
|
config: llmRequest.config
|
|
110
124
|
});
|
|
@@ -192,8 +206,8 @@ class Gemini extends import_base_llm.BaseLlm {
|
|
|
192
206
|
* @returns BaseLlmConnection, the connection to the Gemini model.
|
|
193
207
|
*/
|
|
194
208
|
async connect(llmRequest) {
|
|
195
|
-
var
|
|
196
|
-
if ((
|
|
209
|
+
var _a2, _b2, _c, _d;
|
|
210
|
+
if ((_a2 = llmRequest.liveConnectConfig) == null ? void 0 : _a2.httpOptions) {
|
|
197
211
|
if (!llmRequest.liveConnectConfig.httpOptions.headers) {
|
|
198
212
|
llmRequest.liveConnectConfig.httpOptions.headers = {};
|
|
199
213
|
}
|
|
@@ -203,7 +217,7 @@ class Gemini extends import_base_llm.BaseLlm {
|
|
|
203
217
|
);
|
|
204
218
|
llmRequest.liveConnectConfig.httpOptions.apiVersion = this.liveApiVersion;
|
|
205
219
|
}
|
|
206
|
-
if ((
|
|
220
|
+
if ((_b2 = llmRequest.config) == null ? void 0 : _b2.systemInstruction) {
|
|
207
221
|
llmRequest.liveConnectConfig.systemInstruction = {
|
|
208
222
|
role: "system",
|
|
209
223
|
// TODO - b/425992518: validate type casting works well.
|
|
@@ -305,5 +319,6 @@ function geminiInitParams({
|
|
|
305
319
|
// Annotate the CommonJS export names for ESM import in node:
|
|
306
320
|
0 && (module.exports = {
|
|
307
321
|
Gemini,
|
|
308
|
-
geminiInitParams
|
|
322
|
+
geminiInitParams,
|
|
323
|
+
isGemini
|
|
309
324
|
});
|