@google/adk 1.0.0 → 1.1.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/common.js +8 -0
- package/dist/cjs/index.js +83 -125
- package/dist/cjs/tools/agent_tool.js +1 -1
- package/dist/cjs/tools/mcp/mcp_tool.js +3 -2
- package/dist/cjs/tools/mcp/mcp_toolset.js +1 -1
- package/dist/cjs/tools/url_context_tool.js +73 -0
- package/dist/cjs/tools/vertex_ai_search_tool.js +127 -0
- package/dist/cjs/utils/model_name.js +8 -2
- package/dist/cjs/version.js +1 -1
- package/dist/esm/common.js +5 -0
- package/dist/esm/index.js +43 -130
- package/dist/esm/tools/agent_tool.js +1 -1
- package/dist/esm/tools/mcp/mcp_tool.js +3 -2
- package/dist/esm/tools/mcp/mcp_toolset.js +1 -1
- package/dist/esm/tools/url_context_tool.js +44 -0
- package/dist/esm/tools/vertex_ai_search_tool.js +103 -0
- package/dist/esm/utils/model_name.js +6 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/common.d.ts +3 -0
- package/dist/types/tools/mcp/mcp_tool.d.ts +7 -1
- package/dist/types/tools/mcp/mcp_toolset.d.ts +5 -0
- package/dist/types/tools/url_context_tool.d.ts +17 -0
- package/dist/types/tools/vertex_ai_search_tool.d.ts +55 -0
- package/dist/types/utils/model_name.d.ts +4 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/common.js +5 -0
- package/dist/web/index.js +43 -12
- package/dist/web/tools/agent_tool.js +1 -1
- package/dist/web/tools/mcp/mcp_tool.js +3 -2
- package/dist/web/tools/mcp/mcp_toolset.js +1 -1
- package/dist/web/tools/url_context_tool.js +44 -0
- package/dist/web/tools/vertex_ai_search_tool.js +103 -0
- package/dist/web/utils/model_name.js +6 -1
- package/dist/web/version.js +1 -1
- package/package.json +2 -2
- package/dist/cjs/index.js.map +0 -7
- package/dist/esm/index.js.map +0 -7
- package/dist/web/index.js.map +0 -7
|
@@ -88,7 +88,7 @@ class AgentTool extends (_b = BaseTool, _a = AGENT_TOOL_SIGNATURE_SYMBOL, _b) {
|
|
|
88
88
|
memoryService: (_b2 = toolContext.invocationContext.memoryService) != null ? _b2 : new InMemoryMemoryService(),
|
|
89
89
|
credentialService: toolContext.invocationContext.credentialService
|
|
90
90
|
});
|
|
91
|
-
const session = await runner.sessionService.
|
|
91
|
+
const session = await runner.sessionService.getOrCreateSession({
|
|
92
92
|
appName: this.agent.name,
|
|
93
93
|
userId: toolContext.invocationContext.userId,
|
|
94
94
|
sessionId: toolContext.invocationContext.session.id,
|
|
@@ -8,10 +8,11 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
8
8
|
import { toGeminiSchema } from "../../utils/gemini_schema_util.js";
|
|
9
9
|
import { BaseTool } from "../base_tool.js";
|
|
10
10
|
class MCPTool extends BaseTool {
|
|
11
|
-
constructor(mcpTool, mcpSessionManager) {
|
|
11
|
+
constructor(mcpTool, mcpSessionManager, originalName) {
|
|
12
12
|
super({ name: mcpTool.name, description: mcpTool.description || "" });
|
|
13
13
|
this.mcpTool = mcpTool;
|
|
14
14
|
this.mcpSessionManager = mcpSessionManager;
|
|
15
|
+
this.originalName = originalName || mcpTool.name;
|
|
15
16
|
}
|
|
16
17
|
_getDeclaration() {
|
|
17
18
|
return {
|
|
@@ -26,7 +27,7 @@ class MCPTool extends BaseTool {
|
|
|
26
27
|
async runAsync(request) {
|
|
27
28
|
const session = await this.mcpSessionManager.createSession();
|
|
28
29
|
const callRequest = {};
|
|
29
|
-
callRequest.params = { name: this.
|
|
30
|
+
callRequest.params = { name: this.originalName, arguments: request.args };
|
|
30
31
|
const result = await session.callTool(callRequest.params, void 0, {
|
|
31
32
|
signal: request.toolContext.abortSignal
|
|
32
33
|
});
|
|
@@ -26,7 +26,7 @@ class MCPToolset extends BaseToolset {
|
|
|
26
26
|
...tool,
|
|
27
27
|
name: this.prefix ? `${this.prefix}_${tool.name}` : tool.name
|
|
28
28
|
};
|
|
29
|
-
return new MCPTool(toolWithPrefix, this.mcpSessionManager);
|
|
29
|
+
return new MCPTool(toolWithPrefix, this.mcpSessionManager, tool.name);
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
async close() {
|
|
@@ -0,0 +1,44 @@
|
|
|
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 { isGemini2OrAbove, isGeminiModel } from "../utils/model_name.js";
|
|
9
|
+
import { BaseTool } from "./base_tool.js";
|
|
10
|
+
class UrlContextTool extends BaseTool {
|
|
11
|
+
constructor() {
|
|
12
|
+
super({ name: "url_context", description: "URL Context Tool" });
|
|
13
|
+
}
|
|
14
|
+
runAsync() {
|
|
15
|
+
return Promise.resolve();
|
|
16
|
+
}
|
|
17
|
+
async processLlmRequest({
|
|
18
|
+
llmRequest
|
|
19
|
+
}) {
|
|
20
|
+
if (!llmRequest.model) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (!isGeminiModel(llmRequest.model)) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`URL context tool is not supported for model ${llmRequest.model}`
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
if (!isGemini2OrAbove(llmRequest.model)) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
`URL context tool requires Gemini 2 or above, but got ${llmRequest.model}`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
llmRequest.config = llmRequest.config || {};
|
|
34
|
+
llmRequest.config.tools = llmRequest.config.tools || [];
|
|
35
|
+
llmRequest.config.tools.push({
|
|
36
|
+
urlContext: {}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const URL_CONTEXT = new UrlContextTool();
|
|
41
|
+
export {
|
|
42
|
+
URL_CONTEXT,
|
|
43
|
+
UrlContextTool
|
|
44
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
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 { getLogger } from "../utils/logger.js";
|
|
9
|
+
import {
|
|
10
|
+
isGemini1Model,
|
|
11
|
+
isGeminiModel,
|
|
12
|
+
isGeminiModelIdCheckDisabled
|
|
13
|
+
} from "../utils/model_name.js";
|
|
14
|
+
import { BaseTool } from "./base_tool.js";
|
|
15
|
+
const logger = getLogger();
|
|
16
|
+
class VertexAiSearchTool extends BaseTool {
|
|
17
|
+
constructor(params) {
|
|
18
|
+
super({ name: "vertex_ai_search", description: "vertex_ai_search" });
|
|
19
|
+
const {
|
|
20
|
+
dataStoreId,
|
|
21
|
+
dataStoreSpecs,
|
|
22
|
+
searchEngineId,
|
|
23
|
+
filter,
|
|
24
|
+
maxResults,
|
|
25
|
+
bypassMultiToolsLimit = false
|
|
26
|
+
} = params;
|
|
27
|
+
if (dataStoreId === void 0 && searchEngineId === void 0 || dataStoreId !== void 0 && searchEngineId !== void 0) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
"Either dataStoreId or searchEngineId must be specified."
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
if (dataStoreSpecs !== void 0 && searchEngineId === void 0) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
"searchEngineId must be specified if dataStoreSpecs is specified."
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
this.dataStoreId = dataStoreId;
|
|
38
|
+
this.dataStoreSpecs = dataStoreSpecs;
|
|
39
|
+
this.searchEngineId = searchEngineId;
|
|
40
|
+
this.filter = filter;
|
|
41
|
+
this.maxResults = maxResults;
|
|
42
|
+
this.bypassMultiToolsLimit = bypassMultiToolsLimit;
|
|
43
|
+
}
|
|
44
|
+
runAsync() {
|
|
45
|
+
return Promise.resolve();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Builds the VertexAISearch configuration.
|
|
49
|
+
*
|
|
50
|
+
* Override this method in a subclass to dynamically customize the search
|
|
51
|
+
* configuration based on the context (e.g., set filter based on session
|
|
52
|
+
* state).
|
|
53
|
+
*/
|
|
54
|
+
buildVertexAiSearchConfig(_readonlyContext) {
|
|
55
|
+
return {
|
|
56
|
+
datastore: this.dataStoreId,
|
|
57
|
+
dataStoreSpecs: this.dataStoreSpecs,
|
|
58
|
+
engine: this.searchEngineId,
|
|
59
|
+
filter: this.filter,
|
|
60
|
+
maxResults: this.maxResults
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
async processLlmRequest({
|
|
64
|
+
toolContext,
|
|
65
|
+
llmRequest
|
|
66
|
+
}) {
|
|
67
|
+
if (!llmRequest.model) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const modelCheckDisabled = isGeminiModelIdCheckDisabled();
|
|
71
|
+
llmRequest.config = llmRequest.config || {};
|
|
72
|
+
llmRequest.config.tools = llmRequest.config.tools || [];
|
|
73
|
+
if (!isGeminiModel(llmRequest.model) && !modelCheckDisabled) {
|
|
74
|
+
throw new Error(
|
|
75
|
+
`Vertex AI search tool is not supported for model ${llmRequest.model}`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
if (isGemini1Model(llmRequest.model) && llmRequest.config.tools.length > 0 && !this.bypassMultiToolsLimit) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
"Vertex AI search tool cannot be used with other tools in Gemini 1.x."
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
const vertexAiSearchConfig = this.buildVertexAiSearchConfig(toolContext);
|
|
84
|
+
let specsInfo;
|
|
85
|
+
if (vertexAiSearchConfig.dataStoreSpecs) {
|
|
86
|
+
const specIds = vertexAiSearchConfig.dataStoreSpecs.map(
|
|
87
|
+
(spec) => spec.dataStore ? spec.dataStore.split("/").pop() : "unnamed"
|
|
88
|
+
);
|
|
89
|
+
specsInfo = `${vertexAiSearchConfig.dataStoreSpecs.length} spec(s): [${specIds.join(", ")}]`;
|
|
90
|
+
}
|
|
91
|
+
logger.debug(
|
|
92
|
+
`Adding Vertex AI Search tool config to LLM request: datastore=${vertexAiSearchConfig.datastore}, engine=${vertexAiSearchConfig.engine}, filter=${vertexAiSearchConfig.filter}, maxResults=${vertexAiSearchConfig.maxResults}, dataStoreSpecs=${specsInfo}`
|
|
93
|
+
);
|
|
94
|
+
llmRequest.config.tools.push({
|
|
95
|
+
retrieval: {
|
|
96
|
+
vertexAiSearch: vertexAiSearchConfig
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export {
|
|
102
|
+
VertexAiSearchTool
|
|
103
|
+
};
|
|
@@ -5,6 +5,7 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
5
5
|
* Copyright 2025 Google LLC
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
|
+
import { getBooleanEnvVar } from "./env_aware_utils.js";
|
|
8
9
|
const MODEL_NAME_PATTERN = "^projects/[^/]+/locations/[^/]+/publishers/[^/]+/models/(.+)$";
|
|
9
10
|
function extractModelName(modelString) {
|
|
10
11
|
const match = modelString.match(MODEL_NAME_PATTERN);
|
|
@@ -45,9 +46,13 @@ function isGemini2OrAbove(modelString) {
|
|
|
45
46
|
const parsedVersion = parseVersion(versionString);
|
|
46
47
|
return parsedVersion.valid && parsedVersion.major >= 2;
|
|
47
48
|
}
|
|
49
|
+
function isGeminiModelIdCheckDisabled() {
|
|
50
|
+
return getBooleanEnvVar("ADK_DISABLE_GEMINI_MODEL_ID_CHECK");
|
|
51
|
+
}
|
|
48
52
|
export {
|
|
49
53
|
extractModelName,
|
|
50
54
|
isGemini1Model,
|
|
51
55
|
isGemini2OrAbove,
|
|
52
|
-
isGeminiModel
|
|
56
|
+
isGeminiModel,
|
|
57
|
+
isGeminiModelIdCheckDisabled
|
|
53
58
|
};
|
package/dist/esm/version.js
CHANGED
package/dist/types/common.d.ts
CHANGED
|
@@ -114,6 +114,9 @@ export { LOAD_MEMORY, LoadMemoryTool } from './tools/load_memory_tool.js';
|
|
|
114
114
|
export { LongRunningFunctionTool } from './tools/long_running_tool.js';
|
|
115
115
|
export { PRELOAD_MEMORY, PreloadMemoryTool, } from './tools/preload_memory_tool.js';
|
|
116
116
|
export { ToolConfirmation } from './tools/tool_confirmation.js';
|
|
117
|
+
export { URL_CONTEXT, UrlContextTool } from './tools/url_context_tool.js';
|
|
118
|
+
export { VertexAiSearchTool } from './tools/vertex_ai_search_tool.js';
|
|
119
|
+
export type { DataStoreParams, SearchEngineParams, VertexAISearchConfig, VertexAISearchDataStoreSpec, VertexAiSearchToolParams, } from './tools/vertex_ai_search_tool.js';
|
|
117
120
|
export { LogLevel, getLogger, setLogLevel, setLogger } from './utils/logger.js';
|
|
118
121
|
export type { Logger } from './utils/logger.js';
|
|
119
122
|
export { isGemini2OrAbove } from './utils/model_name.js';
|
|
@@ -20,11 +20,17 @@ import { MCPSessionManager } from './mcp_session_manager.js';
|
|
|
20
20
|
* invoked, which in turn establishes an MCP session, sends a `callTool`
|
|
21
21
|
* request with the provided arguments, and returns the result from the
|
|
22
22
|
* remote tool.
|
|
23
|
+
*
|
|
24
|
+
* The originalName parameter allows the tool to track the native tool name
|
|
25
|
+
* exposed by the MCP server. This is critical when the toolset applies a
|
|
26
|
+
* prefix to tool names (e.g., for LLM namespace disambiguation), ensuring
|
|
27
|
+
* the correct original name is used when executing on the server.
|
|
23
28
|
*/
|
|
24
29
|
export declare class MCPTool extends BaseTool {
|
|
25
30
|
private readonly mcpTool;
|
|
26
31
|
private readonly mcpSessionManager;
|
|
27
|
-
|
|
32
|
+
private readonly originalName;
|
|
33
|
+
constructor(mcpTool: Tool, mcpSessionManager: MCPSessionManager, originalName?: string);
|
|
28
34
|
_getDeclaration(): FunctionDeclaration;
|
|
29
35
|
runAsync(request: RunAsyncToolRequest): Promise<unknown>;
|
|
30
36
|
}
|
|
@@ -17,6 +17,11 @@ import { MCPConnectionParams } from './mcp_session_manager.js';
|
|
|
17
17
|
* The toolset can be configured with a filter to selectively expose a subset
|
|
18
18
|
* of the tools provided by the MCP server.
|
|
19
19
|
*
|
|
20
|
+
* It can also be configured with a prefix. If provided, all tools discovered
|
|
21
|
+
* from the MCP server will have their names prefixed with `${prefix}_`. When the
|
|
22
|
+
* LLM invokes the prefixed tool, this toolset transparently strips the prefix
|
|
23
|
+
* before sending the request to the underlying MCP server.
|
|
24
|
+
*
|
|
20
25
|
* Usage:
|
|
21
26
|
* import { MCPToolset } from '@google/adk';
|
|
22
27
|
* import { StreamableHTTPConnectionParamsSchema } from '@google/adk';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseTool, ToolProcessLlmRequest } from './base_tool.js';
|
|
2
|
+
/**
|
|
3
|
+
* A built-in tool that allows Gemini 2+ models to retrieve content from URLs
|
|
4
|
+
* provided in the conversation.
|
|
5
|
+
*
|
|
6
|
+
* This tool operates internally within the model and does not require or
|
|
7
|
+
* perform local code execution.
|
|
8
|
+
*/
|
|
9
|
+
export declare class UrlContextTool extends BaseTool {
|
|
10
|
+
constructor();
|
|
11
|
+
runAsync(): Promise<unknown>;
|
|
12
|
+
processLlmRequest({ llmRequest, }: ToolProcessLlmRequest): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A global instance of {@link UrlContextTool}.
|
|
16
|
+
*/
|
|
17
|
+
export declare const URL_CONTEXT: UrlContextTool;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { ReadonlyContext } from '../agents/readonly_context.js';
|
|
7
|
+
import { BaseTool, ToolProcessLlmRequest } from './base_tool.js';
|
|
8
|
+
export interface VertexAISearchDataStoreSpec {
|
|
9
|
+
dataStore?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface VertexAISearchConfig {
|
|
12
|
+
datastore?: string;
|
|
13
|
+
dataStoreSpecs?: VertexAISearchDataStoreSpec[];
|
|
14
|
+
engine?: string;
|
|
15
|
+
filter?: string;
|
|
16
|
+
maxResults?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface BaseVertexAiSearchToolParams {
|
|
19
|
+
filter?: string;
|
|
20
|
+
maxResults?: number;
|
|
21
|
+
bypassMultiToolsLimit?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface DataStoreParams extends BaseVertexAiSearchToolParams {
|
|
24
|
+
dataStoreId: string;
|
|
25
|
+
searchEngineId?: never;
|
|
26
|
+
dataStoreSpecs?: never;
|
|
27
|
+
}
|
|
28
|
+
export interface SearchEngineParams extends BaseVertexAiSearchToolParams {
|
|
29
|
+
searchEngineId: string;
|
|
30
|
+
dataStoreId?: never;
|
|
31
|
+
dataStoreSpecs?: VertexAISearchDataStoreSpec[];
|
|
32
|
+
}
|
|
33
|
+
export type VertexAiSearchToolParams = DataStoreParams | SearchEngineParams;
|
|
34
|
+
/**
|
|
35
|
+
* A built-in tool using Vertex AI Search.
|
|
36
|
+
*/
|
|
37
|
+
export declare class VertexAiSearchTool extends BaseTool {
|
|
38
|
+
readonly dataStoreId?: string;
|
|
39
|
+
readonly dataStoreSpecs?: VertexAISearchDataStoreSpec[];
|
|
40
|
+
readonly searchEngineId?: string;
|
|
41
|
+
readonly filter?: string;
|
|
42
|
+
readonly maxResults?: number;
|
|
43
|
+
readonly bypassMultiToolsLimit: boolean;
|
|
44
|
+
constructor(params: VertexAiSearchToolParams);
|
|
45
|
+
runAsync(): Promise<unknown>;
|
|
46
|
+
/**
|
|
47
|
+
* Builds the VertexAISearch configuration.
|
|
48
|
+
*
|
|
49
|
+
* Override this method in a subclass to dynamically customize the search
|
|
50
|
+
* configuration based on the context (e.g., set filter based on session
|
|
51
|
+
* state).
|
|
52
|
+
*/
|
|
53
|
+
protected buildVertexAiSearchConfig(_readonlyContext: ReadonlyContext): VertexAISearchConfig;
|
|
54
|
+
processLlmRequest({ toolContext, llmRequest, }: ToolProcessLlmRequest): Promise<void>;
|
|
55
|
+
}
|
|
@@ -32,3 +32,7 @@ export declare function isGemini1Model(modelString: string): boolean;
|
|
|
32
32
|
* @return true if it's a Gemini 2.x model, false otherwise.
|
|
33
33
|
*/
|
|
34
34
|
export declare function isGemini2OrAbove(modelString: string): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Returns True when Gemini model-id validation should be bypassed.
|
|
37
|
+
*/
|
|
38
|
+
export declare function isGeminiModelIdCheckDisabled(): boolean;
|
package/dist/types/version.d.ts
CHANGED
package/dist/web/common.js
CHANGED
|
@@ -102,6 +102,8 @@ import {
|
|
|
102
102
|
PreloadMemoryTool
|
|
103
103
|
} from "./tools/preload_memory_tool.js";
|
|
104
104
|
import { ToolConfirmation } from "./tools/tool_confirmation.js";
|
|
105
|
+
import { URL_CONTEXT, UrlContextTool } from "./tools/url_context_tool.js";
|
|
106
|
+
import { VertexAiSearchTool } from "./tools/vertex_ai_search_tool.js";
|
|
105
107
|
import { LogLevel, getLogger, setLogLevel, setLogger } from "./utils/logger.js";
|
|
106
108
|
import { isGemini2OrAbove } from "./utils/model_name.js";
|
|
107
109
|
import { zodObjectToSchema } from "./utils/simple_zod_to_json.js";
|
|
@@ -197,6 +199,9 @@ export {
|
|
|
197
199
|
TokenBasedContextCompactor,
|
|
198
200
|
ToolConfirmation,
|
|
199
201
|
TruncatingContextCompactor,
|
|
202
|
+
URL_CONTEXT,
|
|
203
|
+
UrlContextTool,
|
|
204
|
+
VertexAiSearchTool,
|
|
200
205
|
createEvent,
|
|
201
206
|
createEventActions,
|
|
202
207
|
createSession,
|