@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
|
@@ -19,6 +19,7 @@ import { experimental } from "../utils/experimental.js";
|
|
|
19
19
|
var ContextCompactionTrigger = /* @__PURE__ */ ((ContextCompactionTrigger2) => {
|
|
20
20
|
ContextCompactionTrigger2["Manual"] = "Manual";
|
|
21
21
|
ContextCompactionTrigger2["Auto"] = "Auto";
|
|
22
|
+
ContextCompactionTrigger2["AgentControlled"] = "AgentControlled";
|
|
22
23
|
return ContextCompactionTrigger2;
|
|
23
24
|
})(ContextCompactionTrigger || {});
|
|
24
25
|
class BasePlugin {
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2026 Google LLC
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
import { injectSessionState } from "../agents/instructions.js";
|
|
9
|
+
import { ReadonlyContext } from "../agents/readonly_context.js";
|
|
10
|
+
import { BasePlugin } from "./base_plugin.js";
|
|
11
|
+
class GlobalInstructionPlugin extends BasePlugin {
|
|
12
|
+
/**
|
|
13
|
+
* Initializes the GlobalInstructionPlugin.
|
|
14
|
+
*
|
|
15
|
+
* @param globalInstruction The instruction to apply globally. Can be a string
|
|
16
|
+
* or an InstructionProvider function that takes ReadonlyContext and
|
|
17
|
+
* returns a string (sync or async).
|
|
18
|
+
* @param name The name of the plugin (defaults to 'global_instruction').
|
|
19
|
+
*/
|
|
20
|
+
constructor(globalInstruction, name = "global_instruction") {
|
|
21
|
+
super(name);
|
|
22
|
+
this.globalInstruction = globalInstruction;
|
|
23
|
+
}
|
|
24
|
+
async beforeModelCallback(params) {
|
|
25
|
+
if (!this.globalInstruction) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const readonlyContext = new ReadonlyContext(
|
|
29
|
+
params.callbackContext.invocationContext
|
|
30
|
+
);
|
|
31
|
+
const finalGlobalInstruction = await this.resolveGlobalInstruction(readonlyContext);
|
|
32
|
+
if (!finalGlobalInstruction) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (!params.llmRequest.config) {
|
|
36
|
+
params.llmRequest.config = {};
|
|
37
|
+
}
|
|
38
|
+
const existingInstruction = params.llmRequest.config.systemInstruction;
|
|
39
|
+
if (!existingInstruction || Array.isArray(existingInstruction) && existingInstruction.length === 0) {
|
|
40
|
+
params.llmRequest.config.systemInstruction = finalGlobalInstruction;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (typeof existingInstruction === "string") {
|
|
44
|
+
params.llmRequest.config.systemInstruction = "".concat(finalGlobalInstruction, "\n\n").concat(existingInstruction);
|
|
45
|
+
} else if (Array.isArray(existingInstruction)) {
|
|
46
|
+
params.llmRequest.config.systemInstruction = [
|
|
47
|
+
finalGlobalInstruction,
|
|
48
|
+
...existingInstruction
|
|
49
|
+
];
|
|
50
|
+
} else {
|
|
51
|
+
params.llmRequest.config.systemInstruction = [
|
|
52
|
+
finalGlobalInstruction,
|
|
53
|
+
existingInstruction
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
async resolveGlobalInstruction(readonlyContext) {
|
|
59
|
+
if (typeof this.globalInstruction === "string") {
|
|
60
|
+
return await injectSessionState(this.globalInstruction, readonlyContext);
|
|
61
|
+
}
|
|
62
|
+
return await this.globalInstruction(readonlyContext);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
GlobalInstructionPlugin
|
|
67
|
+
};
|
|
@@ -14,19 +14,30 @@ class InMemoryRunner extends Runner {
|
|
|
14
14
|
* Creates a new InMemoryRunner instance.
|
|
15
15
|
*
|
|
16
16
|
* @param params The configuration for the runner.
|
|
17
|
+
* @param params.app An optional application instance to run.
|
|
17
18
|
* @param params.agent The root agent to run.
|
|
18
19
|
* @param params.appName The application name. Defaults to `'InMemoryRunner'`.
|
|
19
20
|
* @param params.plugins An optional list of plugins.
|
|
21
|
+
* @param params.resumabilityConfig An optional resumability configuration.
|
|
20
22
|
*/
|
|
21
23
|
constructor(params) {
|
|
22
|
-
|
|
24
|
+
var _a;
|
|
25
|
+
const {
|
|
26
|
+
agent,
|
|
27
|
+
appName = "InMemoryRunner",
|
|
28
|
+
plugins = [],
|
|
29
|
+
app,
|
|
30
|
+
resumabilityConfig
|
|
31
|
+
} = params;
|
|
23
32
|
super({
|
|
33
|
+
app,
|
|
24
34
|
appName,
|
|
25
35
|
agent,
|
|
26
36
|
plugins,
|
|
27
37
|
artifactService: new InMemoryArtifactService(),
|
|
28
38
|
sessionService: new InMemorySessionService(),
|
|
29
|
-
memoryService: new InMemoryMemoryService()
|
|
39
|
+
memoryService: new InMemoryMemoryService(),
|
|
40
|
+
resumabilityConfig: (_a = app == null ? void 0 : app.resumabilityConfig) != null ? _a : resumabilityConfig
|
|
30
41
|
});
|
|
31
42
|
}
|
|
32
43
|
}
|
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
2
|
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
3
9
|
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
4
10
|
var __typeError = (msg) => {
|
|
5
11
|
throw TypeError(msg);
|
|
6
12
|
};
|
|
13
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
+
var __spreadValues = (a, b) => {
|
|
15
|
+
for (var prop in b || (b = {}))
|
|
16
|
+
if (__hasOwnProp.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
if (__getOwnPropSymbols)
|
|
19
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
+
if (__propIsEnum.call(b, prop))
|
|
21
|
+
__defNormalProp(a, prop, b[prop]);
|
|
22
|
+
}
|
|
23
|
+
return a;
|
|
24
|
+
};
|
|
25
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
7
26
|
var __await = function(promise, isYieldStar) {
|
|
8
27
|
this[0] = promise;
|
|
9
28
|
this[1] = isYieldStar;
|
|
@@ -56,17 +75,19 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
|
|
|
56
75
|
var _a;
|
|
57
76
|
import { createPartFromText } from "@google/genai";
|
|
58
77
|
import { context, trace } from "@opentelemetry/api";
|
|
78
|
+
import { findMatchingFunctionCall } from "../agents/functions.js";
|
|
59
79
|
import {
|
|
60
80
|
InvocationContext,
|
|
61
81
|
newInvocationContextId
|
|
62
82
|
} from "../agents/invocation_context.js";
|
|
63
83
|
import { isLlmAgent } from "../agents/llm_agent.js";
|
|
64
84
|
import { createRunConfig } from "../agents/run_config.js";
|
|
85
|
+
import { ScopedArtifactService } from "../artifacts/scoped_artifact_service.js";
|
|
65
86
|
import {
|
|
66
87
|
BuiltInCodeExecutor,
|
|
67
88
|
isBuiltInCodeExecutor
|
|
68
89
|
} from "../code_executors/built_in_code_executor.js";
|
|
69
|
-
import { createEvent
|
|
90
|
+
import { createEvent } from "../events/event.js";
|
|
70
91
|
import { createEventActions } from "../events/event_actions.js";
|
|
71
92
|
import { PluginManager } from "../plugins/plugin_manager.js";
|
|
72
93
|
import {
|
|
@@ -89,14 +110,24 @@ class Runner {
|
|
|
89
110
|
*/
|
|
90
111
|
constructor(input) {
|
|
91
112
|
this[_a] = true;
|
|
92
|
-
var _a2;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
113
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
114
|
+
const appName = (_b = (_a2 = input.app) == null ? void 0 : _a2.name) != null ? _b : input.appName;
|
|
115
|
+
const agent = (_d = (_c = input.app) == null ? void 0 : _c.rootAgent) != null ? _d : input.agent;
|
|
116
|
+
if (!agent) {
|
|
117
|
+
throw new Error(
|
|
118
|
+
"agent must be provided in runner constructor (or via app.rootAgent)"
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
this.appName = appName;
|
|
122
|
+
this.agent = agent;
|
|
123
|
+
const appPlugins = (_f = (_e = input.app) == null ? void 0 : _e.plugins) != null ? _f : [];
|
|
124
|
+
const configPlugins = (_g = input.plugins) != null ? _g : [];
|
|
125
|
+
this.pluginManager = new PluginManager([...appPlugins, ...configPlugins]);
|
|
96
126
|
this.artifactService = input.artifactService;
|
|
97
127
|
this.sessionService = input.sessionService;
|
|
98
128
|
this.memoryService = input.memoryService;
|
|
99
129
|
this.credentialService = input.credentialService;
|
|
130
|
+
this.resumabilityConfig = (_i = (_h = input.app) == null ? void 0 : _h.resumabilityConfig) != null ? _i : input.resumabilityConfig;
|
|
100
131
|
}
|
|
101
132
|
/**
|
|
102
133
|
* Runs the agent with a new, ephemeral session.
|
|
@@ -149,6 +180,9 @@ class Runner {
|
|
|
149
180
|
const { userId, sessionId, stateDelta } = params;
|
|
150
181
|
const runConfig = createRunConfig(params.runConfig);
|
|
151
182
|
let newMessage = params.newMessage;
|
|
183
|
+
if (newMessage && !newMessage.role) {
|
|
184
|
+
newMessage.role = "user";
|
|
185
|
+
}
|
|
152
186
|
const span = tracer.startSpan("invocation");
|
|
153
187
|
const ctx = trace.setSpan(context.active(), span);
|
|
154
188
|
try {
|
|
@@ -169,7 +203,7 @@ class Runner {
|
|
|
169
203
|
if (!session) {
|
|
170
204
|
if (!this.appName) {
|
|
171
205
|
throw new Error(
|
|
172
|
-
"Session lookup failed: appName must be provided in runner constructor"
|
|
206
|
+
"Session lookup failed: appName must be provided in runner constructor (or via app.name)"
|
|
173
207
|
);
|
|
174
208
|
}
|
|
175
209
|
throw new Error("Session not found: ".concat(sessionId));
|
|
@@ -186,7 +220,12 @@ class Runner {
|
|
|
186
220
|
}
|
|
187
221
|
}
|
|
188
222
|
const invocationContext = new InvocationContext({
|
|
189
|
-
artifactService: this.artifactService
|
|
223
|
+
artifactService: this.artifactService ? new ScopedArtifactService(
|
|
224
|
+
this.artifactService,
|
|
225
|
+
this.appName,
|
|
226
|
+
userId,
|
|
227
|
+
sessionId
|
|
228
|
+
) : void 0,
|
|
190
229
|
sessionService: this.sessionService,
|
|
191
230
|
memoryService: this.memoryService,
|
|
192
231
|
credentialService: this.credentialService,
|
|
@@ -213,7 +252,7 @@ class Runner {
|
|
|
213
252
|
throw new Error("No parts in the newMessage.");
|
|
214
253
|
}
|
|
215
254
|
if (runConfig.saveInputBlobsAsArtifacts) {
|
|
216
|
-
yield new __await(this.saveArtifacts(
|
|
255
|
+
newMessage = yield new __await(this.saveArtifacts(
|
|
217
256
|
invocationContext.invocationId,
|
|
218
257
|
session.userId,
|
|
219
258
|
session.id,
|
|
@@ -315,7 +354,7 @@ class Runner {
|
|
|
315
354
|
}
|
|
316
355
|
/**
|
|
317
356
|
* Saves artifacts from the message parts and replaces the inline data with
|
|
318
|
-
* a file name placeholder.
|
|
357
|
+
* a file name placeholder and optional file reference.
|
|
319
358
|
*
|
|
320
359
|
* @param invocationId The current invocation ID.
|
|
321
360
|
* @param userId The user ID of the session.
|
|
@@ -325,110 +364,141 @@ class Runner {
|
|
|
325
364
|
async saveArtifacts(invocationId, userId, sessionId, message) {
|
|
326
365
|
var _a2;
|
|
327
366
|
if (!this.artifactService || !((_a2 = message.parts) == null ? void 0 : _a2.length)) {
|
|
328
|
-
return;
|
|
367
|
+
return message;
|
|
329
368
|
}
|
|
369
|
+
const sessionKey = {
|
|
370
|
+
appName: this.appName,
|
|
371
|
+
userId,
|
|
372
|
+
sessionId
|
|
373
|
+
};
|
|
374
|
+
const newParts = [];
|
|
375
|
+
let modified = false;
|
|
330
376
|
for (let i = 0; i < message.parts.length; i++) {
|
|
331
377
|
const part = message.parts[i];
|
|
332
378
|
if (!part.inlineData) {
|
|
379
|
+
newParts.push(part);
|
|
333
380
|
continue;
|
|
334
381
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
382
|
+
try {
|
|
383
|
+
const inlineData = part.inlineData;
|
|
384
|
+
const fileName = inlineData.displayName || "artifact_".concat(invocationId, "_").concat(i);
|
|
385
|
+
const version = await this.artifactService.saveArtifact(__spreadProps(__spreadValues({}, sessionKey), {
|
|
386
|
+
filename: fileName,
|
|
387
|
+
artifact: part
|
|
388
|
+
}));
|
|
389
|
+
newParts.push(createPartFromText('[Uploaded Artifact: "'.concat(fileName, '"]')));
|
|
390
|
+
try {
|
|
391
|
+
const artifactVersion = await this.artifactService.getArtifactVersion(
|
|
392
|
+
__spreadProps(__spreadValues({}, sessionKey), {
|
|
393
|
+
filename: fileName,
|
|
394
|
+
version
|
|
395
|
+
})
|
|
396
|
+
);
|
|
397
|
+
if ((artifactVersion == null ? void 0 : artifactVersion.canonicalUri) && /^(gs|https?):/i.test(artifactVersion.canonicalUri)) {
|
|
398
|
+
newParts.push({
|
|
399
|
+
fileData: {
|
|
400
|
+
fileUri: artifactVersion.canonicalUri,
|
|
401
|
+
mimeType: artifactVersion.mimeType || inlineData.mimeType || "",
|
|
402
|
+
displayName: fileName
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
} catch (error) {
|
|
407
|
+
logger.warn(
|
|
408
|
+
"Failed to resolve artifact version for ".concat(fileName, ":"),
|
|
409
|
+
error
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
modified = true;
|
|
413
|
+
logger.info("Successfully saved artifact: ".concat(fileName));
|
|
414
|
+
} catch (error) {
|
|
415
|
+
logger.error("Failed to save artifact for part ".concat(i, ":"), error);
|
|
416
|
+
newParts.push(part);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
if (!modified) {
|
|
420
|
+
return message;
|
|
346
421
|
}
|
|
422
|
+
return __spreadProps(__spreadValues({}, message), {
|
|
423
|
+
parts: newParts
|
|
424
|
+
});
|
|
347
425
|
}
|
|
348
426
|
/**
|
|
349
427
|
* Determines the next agent to run to continue the session. This is primarily
|
|
350
428
|
* used for session resumption.
|
|
351
429
|
*/
|
|
352
|
-
|
|
353
|
-
|
|
430
|
+
/**
|
|
431
|
+
* Determines the next agent to run to continue the session. This is primarily
|
|
432
|
+
* used for session resumption across tool and LRO boundaries.
|
|
433
|
+
*/
|
|
354
434
|
determineAgentForResumption(session, rootAgent) {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
logger.info("event:", JSON.stringify(session.events[i]));
|
|
361
|
-
const event2 = session.events[i];
|
|
362
|
-
if (event2.author === "user" || !event2.author) {
|
|
363
|
-
continue;
|
|
364
|
-
}
|
|
365
|
-
if (event2.author === rootAgent.name) {
|
|
366
|
-
return rootAgent;
|
|
367
|
-
}
|
|
368
|
-
const agent = rootAgent.findSubAgent(event2.author);
|
|
369
|
-
if (!agent) {
|
|
370
|
-
logger.warn(
|
|
371
|
-
"Event from an unknown agent: ".concat(event2.author, ", event id: ").concat(event2.id)
|
|
372
|
-
);
|
|
373
|
-
continue;
|
|
374
|
-
}
|
|
375
|
-
if (this.isRoutableLlmAgent(agent)) {
|
|
376
|
-
return agent;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
return rootAgent;
|
|
435
|
+
return determineAgentForResumption(
|
|
436
|
+
session,
|
|
437
|
+
rootAgent,
|
|
438
|
+
this.resumabilityConfig
|
|
439
|
+
);
|
|
380
440
|
}
|
|
381
441
|
/**
|
|
382
442
|
* Whether the agent to run can transfer to any other agent in the agent tree.
|
|
383
443
|
*
|
|
384
|
-
* An agent is transferable if:
|
|
385
|
-
* - It is an instance of `LlmAgent`.
|
|
386
|
-
* - All its ancestors are also transferable (i.e., they have
|
|
387
|
-
* `disallowTransferToParent` set to false).
|
|
388
|
-
*
|
|
389
444
|
* @param agentToRun The agent to check for transferability.
|
|
390
445
|
* @returns True if the agent can transfer, False otherwise.
|
|
391
446
|
*/
|
|
392
447
|
isRoutableLlmAgent(agentToRun) {
|
|
393
|
-
|
|
394
|
-
while (agent) {
|
|
395
|
-
if (!isLlmAgent(agent)) {
|
|
396
|
-
return false;
|
|
397
|
-
}
|
|
398
|
-
if (agent.disallowTransferToParent) {
|
|
399
|
-
return false;
|
|
400
|
-
}
|
|
401
|
-
agent = agent.parentAgent;
|
|
402
|
-
}
|
|
403
|
-
return true;
|
|
448
|
+
return isRoutableLlmAgent(agentToRun);
|
|
404
449
|
}
|
|
405
450
|
// TODO - b/425992518: Implement runLive and related methods.
|
|
406
451
|
}
|
|
407
|
-
function
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
452
|
+
function determineAgentForResumption(session, rootAgent, resumabilityConfig) {
|
|
453
|
+
const event = findEventByLastFunctionResponseId(session.events);
|
|
454
|
+
const isResumable = Boolean(resumabilityConfig == null ? void 0 : resumabilityConfig.isResumable);
|
|
455
|
+
if (event && event.author && isResumable) {
|
|
456
|
+
const resumedAgent = rootAgent.findAgent(event.author);
|
|
457
|
+
if (resumedAgent) {
|
|
458
|
+
return resumedAgent;
|
|
459
|
+
}
|
|
460
|
+
logger.warn(
|
|
461
|
+
"Function response from an unknown agent: ".concat(event.author, ", event id: ").concat(event.id)
|
|
462
|
+
);
|
|
418
463
|
}
|
|
419
|
-
for (let i = events.length -
|
|
420
|
-
|
|
421
|
-
const
|
|
422
|
-
if (!
|
|
464
|
+
for (let i = session.events.length - 1; i >= 0; i--) {
|
|
465
|
+
logger.debug("event:", JSON.stringify(session.events[i]));
|
|
466
|
+
const event2 = session.events[i];
|
|
467
|
+
if (event2.author === "user" || !event2.author) {
|
|
423
468
|
continue;
|
|
424
469
|
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
470
|
+
if (event2.author === rootAgent.name) {
|
|
471
|
+
return rootAgent;
|
|
472
|
+
}
|
|
473
|
+
const agent = rootAgent.findSubAgent(event2.author);
|
|
474
|
+
if (!agent) {
|
|
475
|
+
logger.warn(
|
|
476
|
+
"Event from an unknown agent: ".concat(event2.author, ", event id: ").concat(event2.id)
|
|
477
|
+
);
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
if (isRoutableLlmAgent(agent)) {
|
|
481
|
+
return agent;
|
|
429
482
|
}
|
|
430
483
|
}
|
|
431
|
-
return
|
|
484
|
+
return rootAgent;
|
|
485
|
+
}
|
|
486
|
+
function isRoutableLlmAgent(agentToRun) {
|
|
487
|
+
let agent = agentToRun;
|
|
488
|
+
while (agent) {
|
|
489
|
+
if (!isLlmAgent(agent)) {
|
|
490
|
+
return false;
|
|
491
|
+
}
|
|
492
|
+
if (agent.disallowTransferToParent) {
|
|
493
|
+
return false;
|
|
494
|
+
}
|
|
495
|
+
agent = agent.parentAgent;
|
|
496
|
+
}
|
|
497
|
+
return true;
|
|
498
|
+
}
|
|
499
|
+
function findEventByLastFunctionResponseId(events) {
|
|
500
|
+
var _a2;
|
|
501
|
+
return (_a2 = findMatchingFunctionCall(events)) != null ? _a2 : null;
|
|
432
502
|
}
|
|
433
503
|
function getAllToolsets(agent) {
|
|
434
504
|
const toolsets = [];
|
|
@@ -452,5 +522,8 @@ function getAllToolsets(agent) {
|
|
|
452
522
|
}
|
|
453
523
|
export {
|
|
454
524
|
Runner,
|
|
525
|
+
determineAgentForResumption,
|
|
526
|
+
findEventByLastFunctionResponseId,
|
|
527
|
+
isRoutableLlmAgent,
|
|
455
528
|
isRunner
|
|
456
529
|
};
|
|
@@ -40,7 +40,12 @@ class BaseSessionService {
|
|
|
40
40
|
}
|
|
41
41
|
event = trimTempDeltaState(event);
|
|
42
42
|
this.updateSessionState({ session, event });
|
|
43
|
-
session.events.
|
|
43
|
+
const index = session.events.findIndex((e) => e.id === event.id);
|
|
44
|
+
if (index >= 0) {
|
|
45
|
+
session.events[index] = event;
|
|
46
|
+
} else {
|
|
47
|
+
session.events.push(event);
|
|
48
|
+
}
|
|
44
49
|
return event;
|
|
45
50
|
}
|
|
46
51
|
/**
|
|
@@ -389,16 +389,28 @@ class DatabaseSessionService extends BaseSessionService {
|
|
|
389
389
|
storageSession.state = __spreadValues(__spreadValues({}, storageSession.state), sessionDelta);
|
|
390
390
|
}
|
|
391
391
|
}
|
|
392
|
-
const
|
|
392
|
+
const existingStorageEvent = await txEm.findOne(StorageEvent, {
|
|
393
393
|
id: trimmedEvent.id,
|
|
394
394
|
appName: session.appName,
|
|
395
395
|
userId: session.userId,
|
|
396
|
-
sessionId: session.id
|
|
397
|
-
invocationId: trimmedEvent.invocationId,
|
|
398
|
-
timestamp: new Date(trimmedEvent.timestamp),
|
|
399
|
-
eventData: trimmedEvent
|
|
396
|
+
sessionId: session.id
|
|
400
397
|
});
|
|
401
|
-
|
|
398
|
+
if (existingStorageEvent) {
|
|
399
|
+
existingStorageEvent.eventData = trimmedEvent;
|
|
400
|
+
existingStorageEvent.timestamp = new Date(trimmedEvent.timestamp);
|
|
401
|
+
txEm.persist(existingStorageEvent);
|
|
402
|
+
} else {
|
|
403
|
+
const newStorageEvent = txEm.create(StorageEvent, {
|
|
404
|
+
id: trimmedEvent.id,
|
|
405
|
+
appName: session.appName,
|
|
406
|
+
userId: session.userId,
|
|
407
|
+
sessionId: session.id,
|
|
408
|
+
invocationId: trimmedEvent.invocationId,
|
|
409
|
+
timestamp: new Date(trimmedEvent.timestamp),
|
|
410
|
+
eventData: trimmedEvent
|
|
411
|
+
});
|
|
412
|
+
txEm.persist(newStorageEvent);
|
|
413
|
+
}
|
|
402
414
|
await txEm.commit();
|
|
403
415
|
storageSession.updateTime = new Date(event.timestamp);
|
|
404
416
|
const newMergedState = mergeStates(
|
|
@@ -407,7 +419,12 @@ class DatabaseSessionService extends BaseSessionService {
|
|
|
407
419
|
storageSession.state
|
|
408
420
|
);
|
|
409
421
|
session.state = newMergedState;
|
|
410
|
-
session.events.
|
|
422
|
+
const index = session.events.findIndex((e) => e.id === event.id);
|
|
423
|
+
if (index >= 0) {
|
|
424
|
+
session.events[index] = event;
|
|
425
|
+
} else {
|
|
426
|
+
session.events.push(event);
|
|
427
|
+
}
|
|
411
428
|
session.lastUpdateTime = storageSession.updateTime.getTime();
|
|
412
429
|
});
|
|
413
430
|
return event;
|
|
@@ -50,6 +50,10 @@ const HTTP_NOT_FOUND = 404;
|
|
|
50
50
|
function isVertexAiConnectionString(uri) {
|
|
51
51
|
return (uri == null ? void 0 : uri.startsWith("vertexai://")) || false;
|
|
52
52
|
}
|
|
53
|
+
function quoteFilterLiteral(value) {
|
|
54
|
+
const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
55
|
+
return '"'.concat(escaped, '"');
|
|
56
|
+
}
|
|
53
57
|
let VertexAiSessionService = class extends BaseSessionService {
|
|
54
58
|
constructor(options) {
|
|
55
59
|
super();
|
|
@@ -213,7 +217,7 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
213
217
|
do {
|
|
214
218
|
const response = await this.sessions.listInternal({
|
|
215
219
|
name: "reasoningEngines/".concat(reasoningEngineId),
|
|
216
|
-
config: __spreadValues(__spreadValues({}, userId ? { filter:
|
|
220
|
+
config: __spreadValues(__spreadValues({}, userId ? { filter: "user_id=".concat(quoteFilterLiteral(userId)) } : {}), pageToken ? { pageToken } : {})
|
|
217
221
|
});
|
|
218
222
|
const sessions = response.sessions || [];
|
|
219
223
|
for (const sessionObj of sessions) {
|
|
@@ -272,10 +276,19 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
272
276
|
}
|
|
273
277
|
async deleteSession({
|
|
274
278
|
appName,
|
|
275
|
-
userId
|
|
279
|
+
userId,
|
|
276
280
|
sessionId
|
|
277
281
|
}) {
|
|
278
282
|
const reasoningEngineId = this.getReasoningEngineId(appName);
|
|
283
|
+
const session = await this.getSession({
|
|
284
|
+
appName,
|
|
285
|
+
userId,
|
|
286
|
+
sessionId,
|
|
287
|
+
config: { numRecentEvents: 0 }
|
|
288
|
+
});
|
|
289
|
+
if (!session) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
279
292
|
await this.sessions.delete({
|
|
280
293
|
name: "reasoningEngines/".concat(reasoningEngineId, "/sessions/").concat(sessionId)
|
|
281
294
|
});
|
|
@@ -412,5 +425,6 @@ function _fromApiEvent(apiEventObj) {
|
|
|
412
425
|
}
|
|
413
426
|
export {
|
|
414
427
|
VertexAiSessionService,
|
|
415
|
-
isVertexAiConnectionString
|
|
428
|
+
isVertexAiConnectionString,
|
|
429
|
+
quoteFilterLiteral
|
|
416
430
|
};
|
|
@@ -103,12 +103,12 @@ function parseSkillMdContent(content) {
|
|
|
103
103
|
if (!content.startsWith("---")) {
|
|
104
104
|
throw new Error("SKILL.md must start with YAML frontmatter (---)");
|
|
105
105
|
}
|
|
106
|
-
const parts = content.split("---"
|
|
106
|
+
const parts = content.split("---");
|
|
107
107
|
if (parts.length < 3) {
|
|
108
108
|
throw new Error("SKILL.md frontmatter not properly closed with ---");
|
|
109
109
|
}
|
|
110
110
|
const frontmatterStr = parts[1];
|
|
111
|
-
const body = parts
|
|
111
|
+
const body = parts.filter((_, i) => i >= 2).join("---").trim();
|
|
112
112
|
try {
|
|
113
113
|
const parsed = yaml.load(frontmatterStr);
|
|
114
114
|
if (typeof parsed !== "object" || parsed === null) {
|
|
@@ -25,7 +25,7 @@ class BaseToolset {
|
|
|
25
25
|
* @return Whether the tool should be exposed to LLM.
|
|
26
26
|
*/
|
|
27
27
|
isToolSelected(tool, context) {
|
|
28
|
-
if (!this.toolFilter) {
|
|
28
|
+
if (!this.toolFilter || Array.isArray(this.toolFilter) && this.toolFilter.length === 0) {
|
|
29
29
|
return true;
|
|
30
30
|
}
|
|
31
31
|
if (typeof this.toolFilter === "function") {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2026 Google LLC
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
import { Type } from "@google/genai";
|
|
9
|
+
import { BaseTool } from "./base_tool.js";
|
|
10
|
+
class ConsolidateContextTool extends BaseTool {
|
|
11
|
+
constructor() {
|
|
12
|
+
super({
|
|
13
|
+
name: "consolidate_context",
|
|
14
|
+
description: "Requests context consolidation (compaction) to manage history size. Use this when a subtask is complete and you want to summarize progress and clear detailed history."
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
_getDeclaration() {
|
|
18
|
+
return {
|
|
19
|
+
name: this.name,
|
|
20
|
+
description: this.description,
|
|
21
|
+
parameters: {
|
|
22
|
+
type: Type.OBJECT,
|
|
23
|
+
properties: {
|
|
24
|
+
detail: {
|
|
25
|
+
type: Type.STRING,
|
|
26
|
+
description: "Optional description of what has been accomplished so far. This detail will be used to guide the summarization of the history."
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
async runAsync({
|
|
33
|
+
args,
|
|
34
|
+
toolContext
|
|
35
|
+
}) {
|
|
36
|
+
toolContext.state.set("temp:consolidate_context", true);
|
|
37
|
+
if (args["detail"] !== void 0) {
|
|
38
|
+
toolContext.state.set(
|
|
39
|
+
"temp:consolidate_context_detail",
|
|
40
|
+
args["detail"]
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
status: "success",
|
|
45
|
+
message: "Context consolidation requested."
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
ConsolidateContextTool
|
|
51
|
+
};
|