@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
|
@@ -0,0 +1,69 @@
|
|
|
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 = `${finalGlobalInstruction}
|
|
45
|
+
|
|
46
|
+
${existingInstruction}`;
|
|
47
|
+
} else if (Array.isArray(existingInstruction)) {
|
|
48
|
+
params.llmRequest.config.systemInstruction = [
|
|
49
|
+
finalGlobalInstruction,
|
|
50
|
+
...existingInstruction
|
|
51
|
+
];
|
|
52
|
+
} else {
|
|
53
|
+
params.llmRequest.config.systemInstruction = [
|
|
54
|
+
finalGlobalInstruction,
|
|
55
|
+
existingInstruction
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
async resolveGlobalInstruction(readonlyContext) {
|
|
61
|
+
if (typeof this.globalInstruction === "string") {
|
|
62
|
+
return await injectSessionState(this.globalInstruction, readonlyContext);
|
|
63
|
+
}
|
|
64
|
+
return await this.globalInstruction(readonlyContext);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
GlobalInstructionPlugin
|
|
69
|
+
};
|
|
@@ -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
|
}
|
|
@@ -8,17 +8,19 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
8
8
|
var _a;
|
|
9
9
|
import { createPartFromText } from "@google/genai";
|
|
10
10
|
import { context, trace } from "@opentelemetry/api";
|
|
11
|
+
import { findMatchingFunctionCall } from "../agents/functions.js";
|
|
11
12
|
import {
|
|
12
13
|
InvocationContext,
|
|
13
14
|
newInvocationContextId
|
|
14
15
|
} from "../agents/invocation_context.js";
|
|
15
16
|
import { isLlmAgent } from "../agents/llm_agent.js";
|
|
16
17
|
import { createRunConfig } from "../agents/run_config.js";
|
|
18
|
+
import { ScopedArtifactService } from "../artifacts/scoped_artifact_service.js";
|
|
17
19
|
import {
|
|
18
20
|
BuiltInCodeExecutor,
|
|
19
21
|
isBuiltInCodeExecutor
|
|
20
22
|
} from "../code_executors/built_in_code_executor.js";
|
|
21
|
-
import { createEvent
|
|
23
|
+
import { createEvent } from "../events/event.js";
|
|
22
24
|
import { createEventActions } from "../events/event_actions.js";
|
|
23
25
|
import { PluginManager } from "../plugins/plugin_manager.js";
|
|
24
26
|
import {
|
|
@@ -41,14 +43,24 @@ class Runner {
|
|
|
41
43
|
*/
|
|
42
44
|
constructor(input) {
|
|
43
45
|
this[_a] = true;
|
|
44
|
-
var _a2;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
47
|
+
const appName = (_b = (_a2 = input.app) == null ? void 0 : _a2.name) != null ? _b : input.appName;
|
|
48
|
+
const agent = (_d = (_c = input.app) == null ? void 0 : _c.rootAgent) != null ? _d : input.agent;
|
|
49
|
+
if (!agent) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
"agent must be provided in runner constructor (or via app.rootAgent)"
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
this.appName = appName;
|
|
55
|
+
this.agent = agent;
|
|
56
|
+
const appPlugins = (_f = (_e = input.app) == null ? void 0 : _e.plugins) != null ? _f : [];
|
|
57
|
+
const configPlugins = (_g = input.plugins) != null ? _g : [];
|
|
58
|
+
this.pluginManager = new PluginManager([...appPlugins, ...configPlugins]);
|
|
48
59
|
this.artifactService = input.artifactService;
|
|
49
60
|
this.sessionService = input.sessionService;
|
|
50
61
|
this.memoryService = input.memoryService;
|
|
51
62
|
this.credentialService = input.credentialService;
|
|
63
|
+
this.resumabilityConfig = (_i = (_h = input.app) == null ? void 0 : _h.resumabilityConfig) != null ? _i : input.resumabilityConfig;
|
|
52
64
|
}
|
|
53
65
|
/**
|
|
54
66
|
* Runs the agent with a new, ephemeral session.
|
|
@@ -98,6 +110,9 @@ class Runner {
|
|
|
98
110
|
const { userId, sessionId, stateDelta } = params;
|
|
99
111
|
const runConfig = createRunConfig(params.runConfig);
|
|
100
112
|
let newMessage = params.newMessage;
|
|
113
|
+
if (newMessage && !newMessage.role) {
|
|
114
|
+
newMessage.role = "user";
|
|
115
|
+
}
|
|
101
116
|
const span = tracer.startSpan("invocation");
|
|
102
117
|
const ctx = trace.setSpan(context.active(), span);
|
|
103
118
|
try {
|
|
@@ -117,7 +132,7 @@ class Runner {
|
|
|
117
132
|
if (!session) {
|
|
118
133
|
if (!this.appName) {
|
|
119
134
|
throw new Error(
|
|
120
|
-
`Session lookup failed: appName must be provided in runner constructor`
|
|
135
|
+
`Session lookup failed: appName must be provided in runner constructor (or via app.name)`
|
|
121
136
|
);
|
|
122
137
|
}
|
|
123
138
|
throw new Error(`Session not found: ${sessionId}`);
|
|
@@ -134,7 +149,12 @@ class Runner {
|
|
|
134
149
|
}
|
|
135
150
|
}
|
|
136
151
|
const invocationContext = new InvocationContext({
|
|
137
|
-
artifactService: this.artifactService
|
|
152
|
+
artifactService: this.artifactService ? new ScopedArtifactService(
|
|
153
|
+
this.artifactService,
|
|
154
|
+
this.appName,
|
|
155
|
+
userId,
|
|
156
|
+
sessionId
|
|
157
|
+
) : void 0,
|
|
138
158
|
sessionService: this.sessionService,
|
|
139
159
|
memoryService: this.memoryService,
|
|
140
160
|
credentialService: this.credentialService,
|
|
@@ -161,7 +181,7 @@ class Runner {
|
|
|
161
181
|
throw new Error("No parts in the newMessage.");
|
|
162
182
|
}
|
|
163
183
|
if (runConfig.saveInputBlobsAsArtifacts) {
|
|
164
|
-
await this.saveArtifacts(
|
|
184
|
+
newMessage = await this.saveArtifacts(
|
|
165
185
|
invocationContext.invocationId,
|
|
166
186
|
session.userId,
|
|
167
187
|
session.id,
|
|
@@ -249,7 +269,7 @@ class Runner {
|
|
|
249
269
|
}
|
|
250
270
|
/**
|
|
251
271
|
* Saves artifacts from the message parts and replaces the inline data with
|
|
252
|
-
* a file name placeholder.
|
|
272
|
+
* a file name placeholder and optional file reference.
|
|
253
273
|
*
|
|
254
274
|
* @param invocationId The current invocation ID.
|
|
255
275
|
* @param userId The user ID of the session.
|
|
@@ -259,110 +279,144 @@ class Runner {
|
|
|
259
279
|
async saveArtifacts(invocationId, userId, sessionId, message) {
|
|
260
280
|
var _a2;
|
|
261
281
|
if (!this.artifactService || !((_a2 = message.parts) == null ? void 0 : _a2.length)) {
|
|
262
|
-
return;
|
|
282
|
+
return message;
|
|
263
283
|
}
|
|
284
|
+
const sessionKey = {
|
|
285
|
+
appName: this.appName,
|
|
286
|
+
userId,
|
|
287
|
+
sessionId
|
|
288
|
+
};
|
|
289
|
+
const newParts = [];
|
|
290
|
+
let modified = false;
|
|
264
291
|
for (let i = 0; i < message.parts.length; i++) {
|
|
265
292
|
const part = message.parts[i];
|
|
266
293
|
if (!part.inlineData) {
|
|
294
|
+
newParts.push(part);
|
|
267
295
|
continue;
|
|
268
296
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
297
|
+
try {
|
|
298
|
+
const inlineData = part.inlineData;
|
|
299
|
+
const fileName = inlineData.displayName || `artifact_${invocationId}_${i}`;
|
|
300
|
+
const version = await this.artifactService.saveArtifact({
|
|
301
|
+
...sessionKey,
|
|
302
|
+
filename: fileName,
|
|
303
|
+
artifact: part
|
|
304
|
+
});
|
|
305
|
+
newParts.push(createPartFromText(`[Uploaded Artifact: "${fileName}"]`));
|
|
306
|
+
try {
|
|
307
|
+
const artifactVersion = await this.artifactService.getArtifactVersion(
|
|
308
|
+
{
|
|
309
|
+
...sessionKey,
|
|
310
|
+
filename: fileName,
|
|
311
|
+
version
|
|
312
|
+
}
|
|
313
|
+
);
|
|
314
|
+
if ((artifactVersion == null ? void 0 : artifactVersion.canonicalUri) && /^(gs|https?):/i.test(artifactVersion.canonicalUri)) {
|
|
315
|
+
newParts.push({
|
|
316
|
+
fileData: {
|
|
317
|
+
fileUri: artifactVersion.canonicalUri,
|
|
318
|
+
mimeType: artifactVersion.mimeType || inlineData.mimeType || "",
|
|
319
|
+
displayName: fileName
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
} catch (error) {
|
|
324
|
+
logger.warn(
|
|
325
|
+
`Failed to resolve artifact version for ${fileName}:`,
|
|
326
|
+
error
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
modified = true;
|
|
330
|
+
logger.info(`Successfully saved artifact: ${fileName}`);
|
|
331
|
+
} catch (error) {
|
|
332
|
+
logger.error(`Failed to save artifact for part ${i}:`, error);
|
|
333
|
+
newParts.push(part);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (!modified) {
|
|
337
|
+
return message;
|
|
280
338
|
}
|
|
339
|
+
return {
|
|
340
|
+
...message,
|
|
341
|
+
parts: newParts
|
|
342
|
+
};
|
|
281
343
|
}
|
|
282
344
|
/**
|
|
283
345
|
* Determines the next agent to run to continue the session. This is primarily
|
|
284
346
|
* used for session resumption.
|
|
285
347
|
*/
|
|
286
|
-
|
|
287
|
-
|
|
348
|
+
/**
|
|
349
|
+
* Determines the next agent to run to continue the session. This is primarily
|
|
350
|
+
* used for session resumption across tool and LRO boundaries.
|
|
351
|
+
*/
|
|
288
352
|
determineAgentForResumption(session, rootAgent) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
logger.info("event:", JSON.stringify(session.events[i]));
|
|
295
|
-
const event2 = session.events[i];
|
|
296
|
-
if (event2.author === "user" || !event2.author) {
|
|
297
|
-
continue;
|
|
298
|
-
}
|
|
299
|
-
if (event2.author === rootAgent.name) {
|
|
300
|
-
return rootAgent;
|
|
301
|
-
}
|
|
302
|
-
const agent = rootAgent.findSubAgent(event2.author);
|
|
303
|
-
if (!agent) {
|
|
304
|
-
logger.warn(
|
|
305
|
-
`Event from an unknown agent: ${event2.author}, event id: ${event2.id}`
|
|
306
|
-
);
|
|
307
|
-
continue;
|
|
308
|
-
}
|
|
309
|
-
if (this.isRoutableLlmAgent(agent)) {
|
|
310
|
-
return agent;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
return rootAgent;
|
|
353
|
+
return determineAgentForResumption(
|
|
354
|
+
session,
|
|
355
|
+
rootAgent,
|
|
356
|
+
this.resumabilityConfig
|
|
357
|
+
);
|
|
314
358
|
}
|
|
315
359
|
/**
|
|
316
360
|
* Whether the agent to run can transfer to any other agent in the agent tree.
|
|
317
361
|
*
|
|
318
|
-
* An agent is transferable if:
|
|
319
|
-
* - It is an instance of `LlmAgent`.
|
|
320
|
-
* - All its ancestors are also transferable (i.e., they have
|
|
321
|
-
* `disallowTransferToParent` set to false).
|
|
322
|
-
*
|
|
323
362
|
* @param agentToRun The agent to check for transferability.
|
|
324
363
|
* @returns True if the agent can transfer, False otherwise.
|
|
325
364
|
*/
|
|
326
365
|
isRoutableLlmAgent(agentToRun) {
|
|
327
|
-
|
|
328
|
-
while (agent) {
|
|
329
|
-
if (!isLlmAgent(agent)) {
|
|
330
|
-
return false;
|
|
331
|
-
}
|
|
332
|
-
if (agent.disallowTransferToParent) {
|
|
333
|
-
return false;
|
|
334
|
-
}
|
|
335
|
-
agent = agent.parentAgent;
|
|
336
|
-
}
|
|
337
|
-
return true;
|
|
366
|
+
return isRoutableLlmAgent(agentToRun);
|
|
338
367
|
}
|
|
339
368
|
// TODO - b/425992518: Implement runLive and related methods.
|
|
340
369
|
}
|
|
341
|
-
function
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
370
|
+
function determineAgentForResumption(session, rootAgent, resumabilityConfig) {
|
|
371
|
+
const event = findEventByLastFunctionResponseId(session.events);
|
|
372
|
+
const isResumable = Boolean(resumabilityConfig == null ? void 0 : resumabilityConfig.isResumable);
|
|
373
|
+
if (event && event.author && isResumable) {
|
|
374
|
+
const resumedAgent = rootAgent.findAgent(event.author);
|
|
375
|
+
if (resumedAgent) {
|
|
376
|
+
return resumedAgent;
|
|
377
|
+
}
|
|
378
|
+
logger.warn(
|
|
379
|
+
`Function response from an unknown agent: ${event.author}, event id: ${event.id}`
|
|
380
|
+
);
|
|
352
381
|
}
|
|
353
|
-
for (let i = events.length -
|
|
354
|
-
|
|
355
|
-
const
|
|
356
|
-
if (!
|
|
382
|
+
for (let i = session.events.length - 1; i >= 0; i--) {
|
|
383
|
+
logger.debug("event:", JSON.stringify(session.events[i]));
|
|
384
|
+
const event2 = session.events[i];
|
|
385
|
+
if (event2.author === "user" || !event2.author) {
|
|
357
386
|
continue;
|
|
358
387
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
388
|
+
if (event2.author === rootAgent.name) {
|
|
389
|
+
return rootAgent;
|
|
390
|
+
}
|
|
391
|
+
const agent = rootAgent.findSubAgent(event2.author);
|
|
392
|
+
if (!agent) {
|
|
393
|
+
logger.warn(
|
|
394
|
+
`Event from an unknown agent: ${event2.author}, event id: ${event2.id}`
|
|
395
|
+
);
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
if (isRoutableLlmAgent(agent)) {
|
|
399
|
+
return agent;
|
|
363
400
|
}
|
|
364
401
|
}
|
|
365
|
-
return
|
|
402
|
+
return rootAgent;
|
|
403
|
+
}
|
|
404
|
+
function isRoutableLlmAgent(agentToRun) {
|
|
405
|
+
let agent = agentToRun;
|
|
406
|
+
while (agent) {
|
|
407
|
+
if (!isLlmAgent(agent)) {
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
410
|
+
if (agent.disallowTransferToParent) {
|
|
411
|
+
return false;
|
|
412
|
+
}
|
|
413
|
+
agent = agent.parentAgent;
|
|
414
|
+
}
|
|
415
|
+
return true;
|
|
416
|
+
}
|
|
417
|
+
function findEventByLastFunctionResponseId(events) {
|
|
418
|
+
var _a2;
|
|
419
|
+
return (_a2 = findMatchingFunctionCall(events)) != null ? _a2 : null;
|
|
366
420
|
}
|
|
367
421
|
function getAllToolsets(agent) {
|
|
368
422
|
const toolsets = [];
|
|
@@ -386,5 +440,8 @@ function getAllToolsets(agent) {
|
|
|
386
440
|
}
|
|
387
441
|
export {
|
|
388
442
|
Runner,
|
|
443
|
+
determineAgentForResumption,
|
|
444
|
+
findEventByLastFunctionResponseId,
|
|
445
|
+
isRoutableLlmAgent,
|
|
389
446
|
isRunner
|
|
390
447
|
};
|
|
@@ -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
|
/**
|
|
@@ -371,16 +371,28 @@ class DatabaseSessionService extends BaseSessionService {
|
|
|
371
371
|
storageSession.state = { ...storageSession.state, ...sessionDelta };
|
|
372
372
|
}
|
|
373
373
|
}
|
|
374
|
-
const
|
|
374
|
+
const existingStorageEvent = await txEm.findOne(StorageEvent, {
|
|
375
375
|
id: trimmedEvent.id,
|
|
376
376
|
appName: session.appName,
|
|
377
377
|
userId: session.userId,
|
|
378
|
-
sessionId: session.id
|
|
379
|
-
invocationId: trimmedEvent.invocationId,
|
|
380
|
-
timestamp: new Date(trimmedEvent.timestamp),
|
|
381
|
-
eventData: trimmedEvent
|
|
378
|
+
sessionId: session.id
|
|
382
379
|
});
|
|
383
|
-
|
|
380
|
+
if (existingStorageEvent) {
|
|
381
|
+
existingStorageEvent.eventData = trimmedEvent;
|
|
382
|
+
existingStorageEvent.timestamp = new Date(trimmedEvent.timestamp);
|
|
383
|
+
txEm.persist(existingStorageEvent);
|
|
384
|
+
} else {
|
|
385
|
+
const newStorageEvent = txEm.create(StorageEvent, {
|
|
386
|
+
id: trimmedEvent.id,
|
|
387
|
+
appName: session.appName,
|
|
388
|
+
userId: session.userId,
|
|
389
|
+
sessionId: session.id,
|
|
390
|
+
invocationId: trimmedEvent.invocationId,
|
|
391
|
+
timestamp: new Date(trimmedEvent.timestamp),
|
|
392
|
+
eventData: trimmedEvent
|
|
393
|
+
});
|
|
394
|
+
txEm.persist(newStorageEvent);
|
|
395
|
+
}
|
|
384
396
|
await txEm.commit();
|
|
385
397
|
storageSession.updateTime = new Date(event.timestamp);
|
|
386
398
|
const newMergedState = mergeStates(
|
|
@@ -389,7 +401,12 @@ class DatabaseSessionService extends BaseSessionService {
|
|
|
389
401
|
storageSession.state
|
|
390
402
|
);
|
|
391
403
|
session.state = newMergedState;
|
|
392
|
-
session.events.
|
|
404
|
+
const index = session.events.findIndex((e) => e.id === event.id);
|
|
405
|
+
if (index >= 0) {
|
|
406
|
+
session.events[index] = event;
|
|
407
|
+
} else {
|
|
408
|
+
session.events.push(event);
|
|
409
|
+
}
|
|
393
410
|
session.lastUpdateTime = storageSession.updateTime.getTime();
|
|
394
411
|
});
|
|
395
412
|
return event;
|
|
@@ -32,6 +32,10 @@ const HTTP_NOT_FOUND = 404;
|
|
|
32
32
|
function isVertexAiConnectionString(uri) {
|
|
33
33
|
return (uri == null ? void 0 : uri.startsWith("vertexai://")) || false;
|
|
34
34
|
}
|
|
35
|
+
function quoteFilterLiteral(value) {
|
|
36
|
+
const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
37
|
+
return `"${escaped}"`;
|
|
38
|
+
}
|
|
35
39
|
let VertexAiSessionService = class extends BaseSessionService {
|
|
36
40
|
constructor(options) {
|
|
37
41
|
super();
|
|
@@ -199,7 +203,7 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
199
203
|
const response = await this.sessions.listInternal({
|
|
200
204
|
name: `reasoningEngines/${reasoningEngineId}`,
|
|
201
205
|
config: {
|
|
202
|
-
...userId ? { filter: `user_id
|
|
206
|
+
...userId ? { filter: `user_id=${quoteFilterLiteral(userId)}` } : {},
|
|
203
207
|
...pageToken ? { pageToken } : {}
|
|
204
208
|
}
|
|
205
209
|
});
|
|
@@ -260,10 +264,19 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
260
264
|
}
|
|
261
265
|
async deleteSession({
|
|
262
266
|
appName,
|
|
263
|
-
userId
|
|
267
|
+
userId,
|
|
264
268
|
sessionId
|
|
265
269
|
}) {
|
|
266
270
|
const reasoningEngineId = this.getReasoningEngineId(appName);
|
|
271
|
+
const session = await this.getSession({
|
|
272
|
+
appName,
|
|
273
|
+
userId,
|
|
274
|
+
sessionId,
|
|
275
|
+
config: { numRecentEvents: 0 }
|
|
276
|
+
});
|
|
277
|
+
if (!session) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
267
280
|
await this.sessions.delete({
|
|
268
281
|
name: `reasoningEngines/${reasoningEngineId}/sessions/${sessionId}`
|
|
269
282
|
});
|
|
@@ -401,5 +414,6 @@ function _fromApiEvent(apiEventObj) {
|
|
|
401
414
|
}
|
|
402
415
|
export {
|
|
403
416
|
VertexAiSessionService,
|
|
404
|
-
isVertexAiConnectionString
|
|
417
|
+
isVertexAiConnectionString,
|
|
418
|
+
quoteFilterLiteral
|
|
405
419
|
};
|
|
@@ -84,12 +84,12 @@ function parseSkillMdContent(content) {
|
|
|
84
84
|
if (!content.startsWith("---")) {
|
|
85
85
|
throw new Error("SKILL.md must start with YAML frontmatter (---)");
|
|
86
86
|
}
|
|
87
|
-
const parts = content.split("---"
|
|
87
|
+
const parts = content.split("---");
|
|
88
88
|
if (parts.length < 3) {
|
|
89
89
|
throw new Error("SKILL.md frontmatter not properly closed with ---");
|
|
90
90
|
}
|
|
91
91
|
const frontmatterStr = parts[1];
|
|
92
|
-
const body = parts
|
|
92
|
+
const body = parts.filter((_, i) => i >= 2).join("---").trim();
|
|
93
93
|
try {
|
|
94
94
|
const parsed = yaml.load(frontmatterStr);
|
|
95
95
|
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
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
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 {
|
|
9
|
+
isGemini1Model,
|
|
10
|
+
isGeminiModel,
|
|
11
|
+
isGeminiModelIdCheckDisabled
|
|
12
|
+
} from "../utils/model_name.js";
|
|
13
|
+
import { BaseTool } from "./base_tool.js";
|
|
14
|
+
function applyEnterpriseWebSearch(llmRequest) {
|
|
15
|
+
if (!llmRequest.model) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const modelCheckDisabled = isGeminiModelIdCheckDisabled();
|
|
19
|
+
llmRequest.config = llmRequest.config || {};
|
|
20
|
+
llmRequest.config.tools = llmRequest.config.tools || [];
|
|
21
|
+
if (isGeminiModel(llmRequest.model) || modelCheckDisabled) {
|
|
22
|
+
if (isGemini1Model(llmRequest.model) && llmRequest.config.tools.length > 0) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
"Enterprise Web Search tool cannot be used with other tools in Gemini 1.x."
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
llmRequest.config.tools.push({ enterpriseWebSearch: {} });
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Enterprise Web Search tool is not supported for model ${llmRequest.model}`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
class EnterpriseWebSearchTool extends BaseTool {
|
|
35
|
+
constructor() {
|
|
36
|
+
super({
|
|
37
|
+
name: "enterprise_web_search",
|
|
38
|
+
description: "Enterprise Web Search Tool"
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
runAsync() {
|
|
42
|
+
return Promise.resolve();
|
|
43
|
+
}
|
|
44
|
+
async processLlmRequest({
|
|
45
|
+
llmRequest
|
|
46
|
+
}) {
|
|
47
|
+
applyEnterpriseWebSearch(llmRequest);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const ENTERPRISE_WEB_SEARCH = new EnterpriseWebSearchTool();
|
|
51
|
+
export {
|
|
52
|
+
ENTERPRISE_WEB_SEARCH,
|
|
53
|
+
EnterpriseWebSearchTool,
|
|
54
|
+
applyEnterpriseWebSearch
|
|
55
|
+
};
|