@google/adk 2.1.0 → 2.2.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_card.js +8 -0
- package/dist/cjs/a2a/agent_executor.js +8 -3
- package/dist/cjs/agents/llm_agent.js +15 -1
- package/dist/cjs/agents/processors/content_processor_utils.js +10 -2
- package/dist/cjs/agents/processors/nl_planning_processor.js +114 -0
- package/dist/cjs/artifacts/gcs_artifact_service.js +13 -7
- package/dist/cjs/auth/auth_credential.js +12 -2
- package/dist/cjs/code_executors/code_execution_utils.js +3 -3
- package/dist/cjs/common.js +45 -0
- package/dist/cjs/examples/example.js +92 -0
- package/dist/cjs/examples/example_util.js +28 -4
- package/dist/cjs/examples/index.js +39 -0
- package/dist/cjs/examples/vertex_ai_example_store.js +39 -0
- package/dist/cjs/index.js +46 -0
- package/dist/cjs/memory/vertex_ai_memory_bank_service.js +17 -5
- package/dist/cjs/models/base_llm.js +1 -6
- package/dist/cjs/models/chrome_prompt_llm.js +16 -2
- package/dist/cjs/models/chrome_prompt_utils.js +54 -2
- package/dist/cjs/models/gemini_llm_connection.js +5 -4
- package/dist/cjs/planners/base_planner.js +56 -0
- package/dist/cjs/planners/built_in_planner.js +85 -0
- package/dist/cjs/planners/plan_re_act_planner.js +172 -0
- package/dist/cjs/plugins/base_plugin.js +46 -61
- package/dist/cjs/tools/example_tool.js +1 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +14 -8
- package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +281 -2
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +15 -1
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.js +70 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +120 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +10 -10
- package/dist/cjs/tools/openapi_tool/common/common.js +139 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +11 -6
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +73 -13
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +146 -34
- package/dist/cjs/tools/openapi_tool/openapi_toolset.js +14 -2
- package/dist/cjs/tools/openapi_tool/rest_api_tool.js +90 -28
- package/dist/cjs/tools/skill/skill_toolset.js +2 -0
- package/dist/cjs/tools/tool_context.js +41 -0
- package/dist/cjs/tools/webmcp/index.js +37 -0
- package/dist/cjs/tools/webmcp/webmcp_tool.js +156 -0
- package/dist/cjs/tools/webmcp/webmcp_toolset.js +116 -0
- package/dist/cjs/tools/webmcp/webmcp_types.js +50 -0
- package/dist/cjs/utils/case_utils.js +52 -2
- package/dist/cjs/utils/client_labels.js +67 -0
- package/dist/cjs/utils/gemini_schema_util.js +103 -3
- package/dist/cjs/utils/hash_utils.js +73 -0
- package/dist/cjs/utils/live_connection_utils.js +10 -9
- package/dist/cjs/utils/model_name.js +17 -2
- package/dist/cjs/utils/simple_zod_to_json.js +5 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/agent_card.js +8 -0
- package/dist/esm/a2a/agent_executor.js +8 -3
- package/dist/esm/agents/llm_agent.js +18 -1
- package/dist/esm/agents/processors/content_processor_utils.js +10 -2
- package/dist/esm/agents/processors/nl_planning_processor.js +87 -0
- package/dist/esm/artifacts/gcs_artifact_service.js +13 -7
- package/dist/esm/auth/auth_credential.js +11 -1
- package/dist/esm/code_executors/code_execution_utils.js +3 -3
- package/dist/esm/common.js +38 -2
- package/dist/esm/examples/example.js +85 -0
- package/dist/esm/examples/example_util.js +25 -3
- package/dist/esm/examples/index.js +11 -0
- package/dist/esm/examples/vertex_ai_example_store.js +11 -0
- package/dist/esm/index.js +51 -1
- package/dist/esm/memory/vertex_ai_memory_bank_service.js +17 -5
- package/dist/esm/models/base_llm.js +2 -7
- package/dist/esm/models/chrome_prompt_llm.js +20 -3
- package/dist/esm/models/chrome_prompt_utils.js +51 -2
- package/dist/esm/models/gemini_llm_connection.js +6 -5
- package/dist/esm/planners/base_planner.js +28 -0
- package/dist/esm/planners/built_in_planner.js +57 -0
- package/dist/esm/planners/plan_re_act_planner.js +145 -0
- package/dist/esm/plugins/base_plugin.js +46 -61
- package/dist/esm/tools/example_tool.js +1 -1
- package/dist/esm/tools/mcp/mcp_session_manager.js +14 -8
- package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +272 -1
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +15 -1
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.js +43 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +93 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +10 -12
- package/dist/esm/tools/openapi_tool/common/common.js +112 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +11 -6
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +80 -13
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +146 -33
- package/dist/esm/tools/openapi_tool/openapi_toolset.js +14 -2
- package/dist/esm/tools/openapi_tool/rest_api_tool.js +89 -28
- package/dist/esm/tools/skill/skill_toolset.js +2 -0
- package/dist/esm/tools/tool_context.js +15 -0
- package/dist/esm/tools/webmcp/index.js +10 -0
- package/dist/esm/tools/webmcp/webmcp_tool.js +131 -0
- package/dist/esm/tools/webmcp/webmcp_toolset.js +89 -0
- package/dist/esm/tools/webmcp/webmcp_types.js +22 -0
- package/dist/esm/utils/case_utils.js +49 -1
- package/dist/esm/utils/client_labels.js +65 -0
- package/dist/esm/utils/gemini_schema_util.js +102 -3
- package/dist/esm/utils/hash_utils.js +45 -0
- package/dist/esm/utils/live_connection_utils.js +11 -10
- package/dist/esm/utils/model_name.js +15 -2
- package/dist/esm/utils/simple_zod_to_json.js +5 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/agents/llm_agent.d.ts +12 -1
- package/dist/types/agents/processors/nl_planning_processor.d.ts +30 -0
- package/dist/types/auth/auth_credential.d.ts +9 -0
- package/dist/types/common.d.ts +16 -4
- package/dist/types/examples/base_example_provider.d.ts +2 -2
- package/dist/types/examples/example.d.ts +75 -0
- package/dist/types/examples/example_util.d.ts +13 -2
- package/dist/types/examples/index.d.ts +18 -0
- package/dist/types/examples/vertex_ai_example_store.d.ts +7 -0
- package/dist/types/index.d.ts +12 -3
- package/dist/types/memory/memory_entry.d.ts +15 -0
- package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +9 -0
- package/dist/types/models/chrome_prompt_utils.d.ts +29 -0
- package/dist/types/planners/base_planner.d.ts +50 -0
- package/dist/types/planners/built_in_planner.d.ts +53 -0
- package/dist/types/planners/plan_re_act_planner.d.ts +21 -0
- package/dist/types/plugins/base_plugin.d.ts +52 -52
- package/dist/types/skills/skill_registry.d.ts +8 -0
- package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +110 -1
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +32 -2
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.d.ts +35 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.d.ts +54 -0
- package/dist/types/tools/openapi_tool/common/common.d.ts +60 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +7 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +56 -2
- package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +73 -5
- package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +11 -0
- package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +42 -8
- package/dist/types/tools/tool_context.d.ts +19 -0
- package/dist/types/tools/webmcp/index.d.ts +12 -0
- package/dist/types/tools/webmcp/webmcp_tool.d.ts +47 -0
- package/dist/types/tools/webmcp/webmcp_toolset.d.ts +67 -0
- package/dist/types/tools/webmcp/webmcp_types.d.ts +69 -0
- package/dist/types/utils/case_utils.d.ts +36 -0
- package/dist/types/utils/client_labels.d.ts +33 -0
- package/dist/types/utils/gemini_schema_util.d.ts +13 -0
- package/dist/types/utils/hash_utils.d.ts +25 -0
- package/dist/types/utils/logger.d.ts +10 -2
- package/dist/types/utils/model_name.d.ts +30 -2
- package/dist/types/version.d.ts +1 -1
- package/dist/web/index_web.js +112 -79
- package/dist/web/index_web.js.map +4 -4
- package/package.json +8 -2
|
@@ -19,7 +19,10 @@ import {
|
|
|
19
19
|
finalText,
|
|
20
20
|
isAbortError,
|
|
21
21
|
isRecord,
|
|
22
|
-
|
|
22
|
+
looksLikeEnvelope,
|
|
23
|
+
renderToolInstructions,
|
|
24
|
+
salvageFinalText,
|
|
25
|
+
TRUNCATED_REPLY
|
|
23
26
|
} from "./chrome_prompt_utils.js";
|
|
24
27
|
import { stripAdkIdentityPreamble } from "./chrome_prompt_utils.js";
|
|
25
28
|
const _ChromeModelUnavailableError = class _ChromeModelUnavailableError extends Error {
|
|
@@ -231,11 +234,19 @@ const _ChromeBuiltInLlm = class _ChromeBuiltInLlm extends BaseLlm {
|
|
|
231
234
|
}
|
|
232
235
|
}
|
|
233
236
|
if (!isRecord(parsed)) {
|
|
237
|
+
const salvaged = salvageFinalText(raw);
|
|
238
|
+
if (salvaged !== void 0) {
|
|
239
|
+
this.diagnostic({
|
|
240
|
+
phase: "parse-fallback",
|
|
241
|
+
note: "truncated envelope; recovered the text"
|
|
242
|
+
});
|
|
243
|
+
return finalText(salvaged);
|
|
244
|
+
}
|
|
234
245
|
this.diagnostic({
|
|
235
246
|
phase: "parse-fallback",
|
|
236
247
|
note: "unparseable JSON; treated as text"
|
|
237
248
|
});
|
|
238
|
-
return finalText(raw);
|
|
249
|
+
return finalText(looksLikeEnvelope(raw) ? TRUNCATED_REPLY : raw);
|
|
239
250
|
}
|
|
240
251
|
if (parsed["kind"] === "tool" && typeof parsed["name"] === "string") {
|
|
241
252
|
const name = parsed["name"];
|
|
@@ -253,7 +264,13 @@ const _ChromeBuiltInLlm = class _ChromeBuiltInLlm extends BaseLlm {
|
|
|
253
264
|
turnComplete: true
|
|
254
265
|
};
|
|
255
266
|
}
|
|
256
|
-
|
|
267
|
+
if (typeof parsed["text"] === "string") return finalText(parsed["text"]);
|
|
268
|
+
if (parsed["text"] !== void 0) return finalText(String(parsed["text"]));
|
|
269
|
+
this.diagnostic({
|
|
270
|
+
phase: "parse-fallback",
|
|
271
|
+
note: "envelope carried no text"
|
|
272
|
+
});
|
|
273
|
+
return finalText(looksLikeEnvelope(raw) ? TRUNCATED_REPLY : raw);
|
|
257
274
|
}
|
|
258
275
|
async connect(_llmRequest) {
|
|
259
276
|
throw new Error(
|
|
@@ -43,7 +43,8 @@ function buildToolChoiceSchema(declarations) {
|
|
|
43
43
|
kind: { type: "string", enum: ["final"] },
|
|
44
44
|
text: { type: "string" }
|
|
45
45
|
},
|
|
46
|
-
required: ["kind", "text"]
|
|
46
|
+
required: ["kind", "text"],
|
|
47
|
+
additionalProperties: false
|
|
47
48
|
}
|
|
48
49
|
];
|
|
49
50
|
for (const declaration of declarations) {
|
|
@@ -55,7 +56,8 @@ function buildToolChoiceSchema(declarations) {
|
|
|
55
56
|
name: { type: "string", enum: [declaration.name] },
|
|
56
57
|
args: argumentSchema(declaration)
|
|
57
58
|
},
|
|
58
|
-
required: ["kind", "name", "args"]
|
|
59
|
+
required: ["kind", "name", "args"],
|
|
60
|
+
additionalProperties: false
|
|
59
61
|
});
|
|
60
62
|
}
|
|
61
63
|
return branches.length === 1 ? branches[0] : { anyOf: branches };
|
|
@@ -177,7 +179,52 @@ function errorResponse(error) {
|
|
|
177
179
|
return { errorCode: name, errorMessage: message, turnComplete: true };
|
|
178
180
|
}
|
|
179
181
|
__name(errorResponse, "errorResponse");
|
|
182
|
+
const TRUNCATED_REPLY = "The model started an answer and did not finish it. Ask again.";
|
|
183
|
+
function looksLikeEnvelope(raw) {
|
|
184
|
+
return /^\s*[[{]/.test(raw) || /"kind"\s*:/.test(raw);
|
|
185
|
+
}
|
|
186
|
+
__name(looksLikeEnvelope, "looksLikeEnvelope");
|
|
187
|
+
function salvageFinalText(raw) {
|
|
188
|
+
var _a;
|
|
189
|
+
const key = raw.match(/"text"\s*:\s*"/);
|
|
190
|
+
if ((key == null ? void 0 : key.index) === void 0) return void 0;
|
|
191
|
+
const escapes = {
|
|
192
|
+
n: "\n",
|
|
193
|
+
t: " ",
|
|
194
|
+
r: "\r",
|
|
195
|
+
b: "\b",
|
|
196
|
+
f: "\f",
|
|
197
|
+
'"': '"',
|
|
198
|
+
"\\": "\\",
|
|
199
|
+
"/": "/"
|
|
200
|
+
};
|
|
201
|
+
let out = "";
|
|
202
|
+
for (let i = key.index + key[0].length; i < raw.length; i++) {
|
|
203
|
+
const char = raw[i];
|
|
204
|
+
if (char === '"') break;
|
|
205
|
+
if (char !== "\\") {
|
|
206
|
+
out += char;
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
const next = raw[i + 1];
|
|
210
|
+
if (next === void 0) break;
|
|
211
|
+
if (next === "u") {
|
|
212
|
+
const hex = raw.slice(i + 2, i + 6);
|
|
213
|
+
if (/^[0-9a-fA-F]{4}$/.test(hex)) {
|
|
214
|
+
out += String.fromCharCode(parseInt(hex, 16));
|
|
215
|
+
i += 5;
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
out += (_a = escapes[next]) != null ? _a : next;
|
|
220
|
+
i++;
|
|
221
|
+
}
|
|
222
|
+
const text = out.trim();
|
|
223
|
+
return text.length ? text : void 0;
|
|
224
|
+
}
|
|
225
|
+
__name(salvageFinalText, "salvageFinalText");
|
|
180
226
|
export {
|
|
227
|
+
TRUNCATED_REPLY,
|
|
181
228
|
buildToolChoiceSchema,
|
|
182
229
|
collectFunctionDeclarations,
|
|
183
230
|
contentsToMessages,
|
|
@@ -186,7 +233,9 @@ export {
|
|
|
186
233
|
finalText,
|
|
187
234
|
isAbortError,
|
|
188
235
|
isRecord,
|
|
236
|
+
looksLikeEnvelope,
|
|
189
237
|
renderToolInstructions,
|
|
190
238
|
renderToolResult,
|
|
239
|
+
salvageFinalText,
|
|
191
240
|
stripAdkIdentityPreamble
|
|
192
241
|
};
|
|
@@ -9,7 +9,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
9
9
|
*/
|
|
10
10
|
import { LiveResponseAggregator } from "../utils/live_connection_utils.js";
|
|
11
11
|
import { logger } from "../utils/logger.js";
|
|
12
|
-
import {
|
|
12
|
+
import { isGemini35LiveTranslate, isGemini3xLive } from "../utils/model_name.js";
|
|
13
13
|
const _GeminiLlmConnection = class _GeminiLlmConnection {
|
|
14
14
|
constructor(geminiSession, modelVersion, messageQueue) {
|
|
15
15
|
this.geminiSession = geminiSession;
|
|
@@ -33,7 +33,7 @@ const _GeminiLlmConnection = class _GeminiLlmConnection {
|
|
|
33
33
|
}
|
|
34
34
|
);
|
|
35
35
|
if (contents.length > 0) {
|
|
36
|
-
const isGemini3x =
|
|
36
|
+
const isGemini3x = isGemini3xLive(this.modelVersion);
|
|
37
37
|
this.geminiSession.sendClientContent({
|
|
38
38
|
turns: contents,
|
|
39
39
|
turnComplete: isGemini3x ? true : contents[contents.length - 1].role === "user"
|
|
@@ -63,7 +63,7 @@ const _GeminiLlmConnection = class _GeminiLlmConnection {
|
|
|
63
63
|
});
|
|
64
64
|
} else {
|
|
65
65
|
logger.debug("Sending LLM new content", content);
|
|
66
|
-
const isGemini3x =
|
|
66
|
+
const isGemini3x = isGemini3xLive(this.modelVersion);
|
|
67
67
|
if (isGemini3x && content.parts.length === 1 && content.parts[0].text) {
|
|
68
68
|
logger.debug("Using sendRealtimeInput for Gemini 3.x text input");
|
|
69
69
|
this.geminiSession.sendRealtimeInput({ text: content.parts[0].text });
|
|
@@ -83,9 +83,10 @@ const _GeminiLlmConnection = class _GeminiLlmConnection {
|
|
|
83
83
|
async sendRealtime(blob) {
|
|
84
84
|
var _a, _b, _c;
|
|
85
85
|
logger.debug("Sending LLM Blob:", blob);
|
|
86
|
-
const isGemini3x =
|
|
86
|
+
const isGemini3x = isGemini3xLive(this.modelVersion);
|
|
87
87
|
const isNativeAudio = (_a = this.modelVersion) == null ? void 0 : _a.includes("native-audio");
|
|
88
|
-
|
|
88
|
+
const isLiveTranslate = isGemini35LiveTranslate(this.modelVersion);
|
|
89
|
+
if (isGemini3x || isNativeAudio || isLiveTranslate) {
|
|
89
90
|
if ((_b = blob.mimeType) == null ? void 0 : _b.startsWith("audio/")) {
|
|
90
91
|
this.geminiSession.sendRealtimeInput({ audio: blob });
|
|
91
92
|
} else if ((_c = blob.mimeType) == null ? void 0 : _c.startsWith("image/")) {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
/**
|
|
6
|
+
* @license
|
|
7
|
+
* Copyright 2026 Google LLC
|
|
8
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
*/
|
|
10
|
+
var _a;
|
|
11
|
+
const BASE_PLANNER_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for("google.adk.basePlanner");
|
|
12
|
+
function isBasePlanner(obj) {
|
|
13
|
+
return typeof obj === "object" && obj !== null && BASE_PLANNER_SIGNATURE_SYMBOL in obj && obj[BASE_PLANNER_SIGNATURE_SYMBOL] === true;
|
|
14
|
+
}
|
|
15
|
+
__name(isBasePlanner, "isBasePlanner");
|
|
16
|
+
_a = BASE_PLANNER_SIGNATURE_SYMBOL;
|
|
17
|
+
const _BasePlanner = class _BasePlanner {
|
|
18
|
+
constructor() {
|
|
19
|
+
/** A unique symbol to identify ADK base planner class. */
|
|
20
|
+
this[_a] = true;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
__name(_BasePlanner, "BasePlanner");
|
|
24
|
+
let BasePlanner = _BasePlanner;
|
|
25
|
+
export {
|
|
26
|
+
BasePlanner,
|
|
27
|
+
isBasePlanner
|
|
28
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
/**
|
|
6
|
+
* @license
|
|
7
|
+
* Copyright 2026 Google LLC
|
|
8
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
*/
|
|
10
|
+
var _a, _b;
|
|
11
|
+
import { BasePlanner } from "./base_planner.js";
|
|
12
|
+
const BUILT_IN_PLANNER_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for(
|
|
13
|
+
"google.adk.builtInPlanner"
|
|
14
|
+
);
|
|
15
|
+
function isBuiltInPlanner(obj) {
|
|
16
|
+
return typeof obj === "object" && obj !== null && BUILT_IN_PLANNER_SIGNATURE_SYMBOL in obj && obj[BUILT_IN_PLANNER_SIGNATURE_SYMBOL] === true;
|
|
17
|
+
}
|
|
18
|
+
__name(isBuiltInPlanner, "isBuiltInPlanner");
|
|
19
|
+
const _BuiltInPlanner = class _BuiltInPlanner extends (_b = BasePlanner, _a = BUILT_IN_PLANNER_SIGNATURE_SYMBOL, _b) {
|
|
20
|
+
/**
|
|
21
|
+
* Initializes the built-in planner.
|
|
22
|
+
*
|
|
23
|
+
* @param options.thinkingConfig Config for model built-in thinking features.
|
|
24
|
+
* An error will be returned if this field is set for models that don't
|
|
25
|
+
* support thinking.
|
|
26
|
+
*/
|
|
27
|
+
constructor(options) {
|
|
28
|
+
super();
|
|
29
|
+
/** A unique symbol to identify ADK built-in planner class. */
|
|
30
|
+
this[_a] = true;
|
|
31
|
+
this.thinkingConfig = options.thinkingConfig;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Applies the thinking config to the LLM request.
|
|
35
|
+
*
|
|
36
|
+
* @param llmRequest The LLM request to apply the thinking config to.
|
|
37
|
+
*/
|
|
38
|
+
applyThinkingConfig(llmRequest) {
|
|
39
|
+
var _a2;
|
|
40
|
+
if (this.thinkingConfig) {
|
|
41
|
+
llmRequest.config = (_a2 = llmRequest.config) != null ? _a2 : {};
|
|
42
|
+
llmRequest.config.thinkingConfig = this.thinkingConfig;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
buildPlanningInstruction(_readonlyContext, _llmRequest) {
|
|
46
|
+
return void 0;
|
|
47
|
+
}
|
|
48
|
+
processPlanningResponse(_callbackContext, _responseParts) {
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
__name(_BuiltInPlanner, "BuiltInPlanner");
|
|
53
|
+
let BuiltInPlanner = _BuiltInPlanner;
|
|
54
|
+
export {
|
|
55
|
+
BuiltInPlanner,
|
|
56
|
+
isBuiltInPlanner
|
|
57
|
+
};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
/**
|
|
6
|
+
* @license
|
|
7
|
+
* Copyright 2026 Google LLC
|
|
8
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
*/
|
|
10
|
+
import { BasePlanner } from "./base_planner.js";
|
|
11
|
+
const PLANNING_TAG = "/*PLANNING*/";
|
|
12
|
+
const REPLANNING_TAG = "/*REPLANNING*/";
|
|
13
|
+
const REASONING_TAG = "/*REASONING*/";
|
|
14
|
+
const ACTION_TAG = "/*ACTION*/";
|
|
15
|
+
const FINAL_ANSWER_TAG = "/*FINAL_ANSWER*/";
|
|
16
|
+
const THOUGHT_PREFIX_TAGS = [
|
|
17
|
+
PLANNING_TAG,
|
|
18
|
+
REASONING_TAG,
|
|
19
|
+
ACTION_TAG,
|
|
20
|
+
REPLANNING_TAG
|
|
21
|
+
];
|
|
22
|
+
const _PlanReActPlanner = class _PlanReActPlanner extends BasePlanner {
|
|
23
|
+
buildPlanningInstruction(_readonlyContext, _llmRequest) {
|
|
24
|
+
return buildNlPlannerInstruction();
|
|
25
|
+
}
|
|
26
|
+
processPlanningResponse(_callbackContext, responseParts) {
|
|
27
|
+
if (!responseParts || responseParts.length === 0) {
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
const preservedParts = [];
|
|
31
|
+
let firstFcPartIndex = -1;
|
|
32
|
+
for (let i = 0; i < responseParts.length; i++) {
|
|
33
|
+
const part = responseParts[i];
|
|
34
|
+
if (part.functionCall) {
|
|
35
|
+
if (!part.functionCall.name) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
preservedParts.push(part);
|
|
39
|
+
firstFcPartIndex = i;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
handleNonFunctionCallPart(part, preservedParts);
|
|
43
|
+
}
|
|
44
|
+
if (firstFcPartIndex > 0) {
|
|
45
|
+
for (let j = firstFcPartIndex + 1; j < responseParts.length; j++) {
|
|
46
|
+
if (!responseParts[j].functionCall) {
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
preservedParts.push(responseParts[j]);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return preservedParts;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
__name(_PlanReActPlanner, "PlanReActPlanner");
|
|
56
|
+
let PlanReActPlanner = _PlanReActPlanner;
|
|
57
|
+
function splitByLastPattern(text, separator) {
|
|
58
|
+
const index = text.lastIndexOf(separator);
|
|
59
|
+
if (index === -1) {
|
|
60
|
+
return [text, ""];
|
|
61
|
+
}
|
|
62
|
+
const end = index + separator.length;
|
|
63
|
+
return [text.slice(0, end), text.slice(end)];
|
|
64
|
+
}
|
|
65
|
+
__name(splitByLastPattern, "splitByLastPattern");
|
|
66
|
+
function handleNonFunctionCallPart(responsePart, preservedParts) {
|
|
67
|
+
var _a;
|
|
68
|
+
if (responsePart.text && responsePart.text.includes(FINAL_ANSWER_TAG)) {
|
|
69
|
+
const [reasoningText, finalAnswerText] = splitByLastPattern(
|
|
70
|
+
responsePart.text,
|
|
71
|
+
FINAL_ANSWER_TAG
|
|
72
|
+
);
|
|
73
|
+
if (reasoningText) {
|
|
74
|
+
preservedParts.push(markAsThought({ text: reasoningText }));
|
|
75
|
+
}
|
|
76
|
+
if (finalAnswerText) {
|
|
77
|
+
preservedParts.push({ text: finalAnswerText });
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const responseText = (_a = responsePart.text) != null ? _a : "";
|
|
82
|
+
if (responseText && THOUGHT_PREFIX_TAGS.some((tag) => responseText.startsWith(tag))) {
|
|
83
|
+
preservedParts.push(markAsThought(responsePart));
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
preservedParts.push(responsePart);
|
|
87
|
+
}
|
|
88
|
+
__name(handleNonFunctionCallPart, "handleNonFunctionCallPart");
|
|
89
|
+
function markAsThought(responsePart) {
|
|
90
|
+
if (responsePart.text) {
|
|
91
|
+
return { ...responsePart, thought: true };
|
|
92
|
+
}
|
|
93
|
+
return responsePart;
|
|
94
|
+
}
|
|
95
|
+
__name(markAsThought, "markAsThought");
|
|
96
|
+
function buildNlPlannerInstruction() {
|
|
97
|
+
const highLevelPreamble = `
|
|
98
|
+
When answering the question, try to leverage the available tools to gather the information instead of your memorized knowledge.
|
|
99
|
+
|
|
100
|
+
Follow this process when answering the question: (1) first come up with a plan in natural language text format; (2) Then use tools to execute the plan and provide reasoning between tool code snippets to make a summary of current state and next step. Tool code snippets and reasoning should be interleaved with each other. (3) In the end, return one final answer.
|
|
101
|
+
|
|
102
|
+
Follow this format when answering the question: (1) The planning part should be under ${PLANNING_TAG}. (2) The tool code snippets should be under ${ACTION_TAG}, and the reasoning parts should be under ${REASONING_TAG}. (3) The final answer part should be under ${FINAL_ANSWER_TAG}.
|
|
103
|
+
`;
|
|
104
|
+
const planningPreamble = `
|
|
105
|
+
Below are the requirements for the planning:
|
|
106
|
+
The plan is made to answer the user query if following the plan. The plan is coherent and covers all aspects of information from user query, and only involves the tools that are accessible by the agent. The plan contains the decomposed steps as a numbered list where each step should use one or multiple available tools. By reading the plan, you can intuitively know which tools to trigger or what actions to take.
|
|
107
|
+
If the initial plan cannot be successfully executed, you should learn from previous execution results and revise your plan. The revised plan should be be under ${REPLANNING_TAG}. Then use tools to follow the new plan.
|
|
108
|
+
`;
|
|
109
|
+
const reasoningPreamble = `
|
|
110
|
+
Below are the requirements for the reasoning:
|
|
111
|
+
The reasoning makes a summary of the current trajectory based on the user query and tool outputs. Based on the tool outputs and plan, the reasoning also comes up with instructions to the next steps, making the trajectory closer to the final answer.
|
|
112
|
+
`;
|
|
113
|
+
const finalAnswerPreamble = `
|
|
114
|
+
Below are the requirements for the final answer:
|
|
115
|
+
The final answer should be precise and follow query formatting requirements. Some queries may not be answerable with the available tools and information. In those cases, inform the user why you cannot process their query and ask for more information.
|
|
116
|
+
`;
|
|
117
|
+
const toolCodeWithoutPythonLibrariesPreamble = `
|
|
118
|
+
Below are the requirements for the tool code:
|
|
119
|
+
|
|
120
|
+
**Custom Tools:** The available tools are described in the context and can be directly used.
|
|
121
|
+
- Code must be valid self-contained Python snippets with no imports and no references to tools or Python libraries that are not in the context.
|
|
122
|
+
- You cannot use any parameters or fields that are not explicitly defined in the APIs in the context.
|
|
123
|
+
- The code snippets should be readable, efficient, and directly relevant to the user query and reasoning steps.
|
|
124
|
+
- When using the tools, you should use the library name together with the function name, e.g., vertex_search.search().
|
|
125
|
+
- If Python libraries are not provided in the context, NEVER write your own code other than the function calls using the provided tools.
|
|
126
|
+
`;
|
|
127
|
+
const userInputPreamble = `
|
|
128
|
+
VERY IMPORTANT instruction that you MUST follow in addition to the above instructions:
|
|
129
|
+
|
|
130
|
+
You should ask for clarification if you need more information to answer the question.
|
|
131
|
+
You should prefer using the information available in the context instead of repeated tool use.
|
|
132
|
+
`;
|
|
133
|
+
return [
|
|
134
|
+
highLevelPreamble,
|
|
135
|
+
planningPreamble,
|
|
136
|
+
reasoningPreamble,
|
|
137
|
+
finalAnswerPreamble,
|
|
138
|
+
toolCodeWithoutPythonLibrariesPreamble,
|
|
139
|
+
userInputPreamble
|
|
140
|
+
].join("\n\n");
|
|
141
|
+
}
|
|
142
|
+
__name(buildNlPlannerInstruction, "buildNlPlannerInstruction");
|
|
143
|
+
export {
|
|
144
|
+
PlanReActPlanner
|
|
145
|
+
};
|
|
@@ -39,14 +39,13 @@ const _BasePlugin = class _BasePlugin {
|
|
|
39
39
|
* This callback helps logging and modifying the user message before the
|
|
40
40
|
* runner starts the invocation.
|
|
41
41
|
*
|
|
42
|
-
* @param
|
|
43
|
-
* @param
|
|
42
|
+
* @param _params.invocationContext The context for the entire invocation.
|
|
43
|
+
* @param _params.userMessage The message content input by user.
|
|
44
44
|
* @returns An optional `Content` to be returned to the ADK. Returning a
|
|
45
45
|
* value to replace the user message. Returning `undefined` to proceed
|
|
46
46
|
* normally.
|
|
47
47
|
*/
|
|
48
|
-
|
|
49
|
-
async onUserMessageCallback(params) {
|
|
48
|
+
async onUserMessageCallback(_params) {
|
|
50
49
|
return;
|
|
51
50
|
}
|
|
52
51
|
/**
|
|
@@ -55,14 +54,13 @@ const _BasePlugin = class _BasePlugin {
|
|
|
55
54
|
* This is the first callback to be called in the lifecycle, ideal for global
|
|
56
55
|
* setup or initialization tasks.
|
|
57
56
|
*
|
|
58
|
-
* @param
|
|
57
|
+
* @param _params.invocationContext The context for the entire invocation, containing
|
|
59
58
|
* session information, the root agent, etc.
|
|
60
59
|
* @returns An optional `Event` to be returned to the ADK. Returning a value
|
|
61
60
|
* to halt execution of the runner and ends the runner with that event.
|
|
62
61
|
* Return `undefined` to proceed normally.
|
|
63
62
|
*/
|
|
64
|
-
|
|
65
|
-
async beforeRunCallback(params) {
|
|
63
|
+
async beforeRunCallback(_params) {
|
|
66
64
|
return;
|
|
67
65
|
}
|
|
68
66
|
/**
|
|
@@ -71,16 +69,15 @@ const _BasePlugin = class _BasePlugin {
|
|
|
71
69
|
* This is the ideal place to make modification to the event before the event
|
|
72
70
|
* is handled by the underlying agent app.
|
|
73
71
|
*
|
|
74
|
-
* @param
|
|
75
|
-
* @param
|
|
72
|
+
* @param _params.invocationContext The context for the entire invocation.
|
|
73
|
+
* @param _params.event The event raised by the runner.
|
|
76
74
|
* @returns An optional value. A non-`undefined` return may be used by the
|
|
77
|
-
* framework to modify or replace the response. Copy
|
|
78
|
-
* constructing a replacement to preserve fields that are not
|
|
79
|
-
* modified, such as event actions. Returning `undefined` allows the
|
|
75
|
+
* framework to modify or replace the response. Copy the incoming
|
|
76
|
+
* `event` when constructing a replacement to preserve fields that are not
|
|
77
|
+
* being modified, such as event actions. Returning `undefined` allows the
|
|
80
78
|
* original response to be used.
|
|
81
79
|
*/
|
|
82
|
-
|
|
83
|
-
async onEventCallback(params) {
|
|
80
|
+
async onEventCallback(_params) {
|
|
84
81
|
return;
|
|
85
82
|
}
|
|
86
83
|
/**
|
|
@@ -89,11 +86,10 @@ const _BasePlugin = class _BasePlugin {
|
|
|
89
86
|
* This is the final callback in the ADK lifecycle, suitable for cleanup,
|
|
90
87
|
* final logging, or reporting tasks.
|
|
91
88
|
*
|
|
92
|
-
* @param
|
|
89
|
+
* @param _params.invocationContext The context for the entire invocation.
|
|
93
90
|
* @returns undefined
|
|
94
91
|
*/
|
|
95
|
-
|
|
96
|
-
async afterRunCallback(params) {
|
|
92
|
+
async afterRunCallback(_params) {
|
|
97
93
|
return;
|
|
98
94
|
}
|
|
99
95
|
/**
|
|
@@ -102,14 +98,13 @@ const _BasePlugin = class _BasePlugin {
|
|
|
102
98
|
* This callback can be used for logging, setup, or to short-circuit the
|
|
103
99
|
* agent's execution by returning a value.
|
|
104
100
|
*
|
|
105
|
-
* @param
|
|
106
|
-
* @param
|
|
101
|
+
* @param _params.agent The agent that is about to run.
|
|
102
|
+
* @param _params.callbackContext The context for the agent invocation.
|
|
107
103
|
* @returns An optional `Content` object. If a value is returned, it will
|
|
108
104
|
* bypass the agent's callbacks and its execution, and return this value
|
|
109
105
|
* directly. Returning `undefined` allows the agent to proceed normally.
|
|
110
106
|
*/
|
|
111
|
-
|
|
112
|
-
async beforeAgentCallback(params) {
|
|
107
|
+
async beforeAgentCallback(_params) {
|
|
113
108
|
return;
|
|
114
109
|
}
|
|
115
110
|
/**
|
|
@@ -118,14 +113,13 @@ const _BasePlugin = class _BasePlugin {
|
|
|
118
113
|
* This callback can be used to inspect, log, or modify the agent's final
|
|
119
114
|
* result before it is returned.
|
|
120
115
|
*
|
|
121
|
-
* @param
|
|
122
|
-
* @param
|
|
116
|
+
* @param _params.agent The agent that has just run.
|
|
117
|
+
* @param _params.callbackContext The context for the agent invocation.
|
|
123
118
|
* @returns An optional `Content` object. If a value is returned, it will
|
|
124
119
|
* replace the agent's original result. Returning `undefined` uses the
|
|
125
120
|
* original, unmodified result.
|
|
126
121
|
*/
|
|
127
|
-
|
|
128
|
-
async afterAgentCallback(params) {
|
|
122
|
+
async afterAgentCallback(_params) {
|
|
129
123
|
return;
|
|
130
124
|
}
|
|
131
125
|
/**
|
|
@@ -166,14 +160,13 @@ const _BasePlugin = class _BasePlugin {
|
|
|
166
160
|
* object. It can also be used to implement caching by returning a cached
|
|
167
161
|
* `LlmResponse`, which would skip the actual model call.
|
|
168
162
|
*
|
|
169
|
-
* @param
|
|
170
|
-
* @param
|
|
163
|
+
* @param _params.callbackContext The context for the current agent call.
|
|
164
|
+
* @param _params.llmRequest The prepared request object to be sent to the model.
|
|
171
165
|
* @returns An optional value. The interpretation of a non-`undefined`
|
|
172
166
|
* trigger an early exit and returns the response immediately. Returning
|
|
173
167
|
* `undefined` allows the LLM request to proceed normally.
|
|
174
168
|
*/
|
|
175
|
-
|
|
176
|
-
async beforeModelCallback(params) {
|
|
169
|
+
async beforeModelCallback(_params) {
|
|
177
170
|
return;
|
|
178
171
|
}
|
|
179
172
|
/**
|
|
@@ -182,14 +175,13 @@ const _BasePlugin = class _BasePlugin {
|
|
|
182
175
|
* This is the ideal place to log model responses, collect metrics on token
|
|
183
176
|
* usage, or perform post-processing on the raw `LlmResponse`.
|
|
184
177
|
*
|
|
185
|
-
* @param
|
|
186
|
-
* @param
|
|
178
|
+
* @param _params.callbackContext The context for the current agent call.
|
|
179
|
+
* @param _params.llmResponse The response object received from the model.
|
|
187
180
|
* @returns An optional value. A non-`undefined` return may be used by the
|
|
188
181
|
* framework to modify or replace the response. Returning `undefined`
|
|
189
182
|
* allows the original response to be used.
|
|
190
183
|
*/
|
|
191
|
-
|
|
192
|
-
async afterModelCallback(params) {
|
|
184
|
+
async afterModelCallback(_params) {
|
|
193
185
|
return;
|
|
194
186
|
}
|
|
195
187
|
/**
|
|
@@ -198,28 +190,24 @@ const _BasePlugin = class _BasePlugin {
|
|
|
198
190
|
* This callback provides an opportunity to handle model errors gracefully,
|
|
199
191
|
* potentially providing alternative responses or recovery mechanisms.
|
|
200
192
|
*
|
|
201
|
-
* @param
|
|
202
|
-
* @param
|
|
193
|
+
* @param _params.callbackContext The context for the current agent call.
|
|
194
|
+
* @param _params.llmRequest The request that was sent to the model when the error
|
|
203
195
|
* occurred.
|
|
204
|
-
* @param
|
|
196
|
+
* @param _params.error The exception that was raised during model execution.
|
|
205
197
|
* @returns An optional LlmResponse. If an LlmResponse is returned, it will be
|
|
206
198
|
* used instead of propagating the error. Returning `undefined` allows
|
|
207
199
|
* the original error to be raised.
|
|
208
200
|
*/
|
|
209
|
-
|
|
210
|
-
async onModelErrorCallback(params) {
|
|
201
|
+
async onModelErrorCallback(_params) {
|
|
211
202
|
return;
|
|
212
203
|
}
|
|
213
|
-
|
|
214
|
-
async beforeToolSelection(params) {
|
|
204
|
+
async beforeToolSelection(_params) {
|
|
215
205
|
return;
|
|
216
206
|
}
|
|
217
|
-
|
|
218
|
-
async beforeContextCompaction(params) {
|
|
207
|
+
async beforeContextCompaction(_params) {
|
|
219
208
|
return;
|
|
220
209
|
}
|
|
221
|
-
|
|
222
|
-
async afterContextCompaction(params) {
|
|
210
|
+
async afterContextCompaction(_params) {
|
|
223
211
|
return;
|
|
224
212
|
}
|
|
225
213
|
/**
|
|
@@ -228,16 +216,15 @@ const _BasePlugin = class _BasePlugin {
|
|
|
228
216
|
* This callback is useful for logging tool usage, input validation, or
|
|
229
217
|
* modifying the arguments before they are passed to the tool.
|
|
230
218
|
*
|
|
231
|
-
* @param
|
|
232
|
-
* @param
|
|
219
|
+
* @param _params.tool The tool instance that is about to be executed.
|
|
220
|
+
* @param _params.toolArgs The dictionary of arguments to be used for invoking the
|
|
233
221
|
* tool.
|
|
234
|
-
* @param
|
|
222
|
+
* @param _params.toolContext The context specific to the tool execution.
|
|
235
223
|
* @returns An optional dictionary. If a dictionary is returned, it will stop
|
|
236
224
|
* the tool execution and return this response immediately. Returning
|
|
237
225
|
* `undefined` uses the original, unmodified arguments.
|
|
238
226
|
*/
|
|
239
|
-
|
|
240
|
-
async beforeToolCallback(params) {
|
|
227
|
+
async beforeToolCallback(_params) {
|
|
241
228
|
return;
|
|
242
229
|
}
|
|
243
230
|
/**
|
|
@@ -246,17 +233,16 @@ const _BasePlugin = class _BasePlugin {
|
|
|
246
233
|
* This callback allows for inspecting, logging, or modifying the result
|
|
247
234
|
* returned by a tool.
|
|
248
235
|
*
|
|
249
|
-
* @param
|
|
250
|
-
* @param
|
|
251
|
-
* @param
|
|
252
|
-
* @param
|
|
236
|
+
* @param _params.tool The tool instance that has just been executed.
|
|
237
|
+
* @param _params.toolArgs The original arguments that were passed to the tool.
|
|
238
|
+
* @param _params.toolContext The context specific to the tool execution.
|
|
239
|
+
* @param _params.result The dictionary returned by the tool invocation.
|
|
253
240
|
* @returns An optional dictionary. If a dictionary is returned, it will
|
|
254
241
|
* **replace** the original result from the tool. This allows for
|
|
255
242
|
* post-processing or altering tool outputs. Returning `undefined` uses
|
|
256
243
|
* the original, unmodified result.
|
|
257
244
|
*/
|
|
258
|
-
|
|
259
|
-
async afterToolCallback(params) {
|
|
245
|
+
async afterToolCallback(_params) {
|
|
260
246
|
return;
|
|
261
247
|
}
|
|
262
248
|
/**
|
|
@@ -275,16 +261,15 @@ const _BasePlugin = class _BasePlugin {
|
|
|
275
261
|
* This callback provides an opportunity to handle tool errors gracefully,
|
|
276
262
|
* potentially providing alternative responses or recovery mechanisms.
|
|
277
263
|
*
|
|
278
|
-
* @param
|
|
279
|
-
* @param
|
|
280
|
-
* @param
|
|
281
|
-
* @param
|
|
264
|
+
* @param _params.tool The tool instance that encountered an error.
|
|
265
|
+
* @param _params.toolArgs The arguments that were passed to the tool.
|
|
266
|
+
* @param _params.toolContext The context specific to the tool execution.
|
|
267
|
+
* @param _params.error The exception that was raised during tool execution.
|
|
282
268
|
* @returns An optional dictionary. If a dictionary is returned, it will be
|
|
283
269
|
* used as the tool response instead of propagating the error. Returning
|
|
284
270
|
* `undefined` allows the original error to be raised.
|
|
285
271
|
*/
|
|
286
|
-
|
|
287
|
-
async onToolErrorCallback(params) {
|
|
272
|
+
async onToolErrorCallback(_params) {
|
|
288
273
|
return;
|
|
289
274
|
}
|
|
290
275
|
};
|
|
@@ -35,7 +35,7 @@ const _ExampleTool = class _ExampleTool extends BaseTool {
|
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
37
|
appendInstructions(llmRequest, [
|
|
38
|
-
buildExampleSi(this.examples, parts[0].text, llmRequest.model)
|
|
38
|
+
await buildExampleSi(this.examples, parts[0].text, llmRequest.model)
|
|
39
39
|
]);
|
|
40
40
|
}
|
|
41
41
|
};
|