@google/adk 0.2.4 → 0.2.5
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/agents/base_agent.js +9 -3
- package/dist/cjs/agents/invocation_context.js +3 -1
- package/dist/cjs/agents/llm_agent.js +129 -75
- package/dist/cjs/agents/loop_agent.js +16 -5
- package/dist/cjs/agents/parallel_agent.js +17 -3
- package/dist/cjs/agents/readonly_context.js +4 -1
- package/dist/cjs/agents/sequential_agent.js +34 -12
- package/dist/cjs/code_executors/base_code_executor.js +12 -2
- package/dist/cjs/code_executors/built_in_code_executor.js +15 -3
- package/dist/cjs/common.js +41 -0
- package/dist/cjs/examples/base_example_provider.js +18 -2
- package/dist/cjs/examples/example_util.js +1 -1
- package/dist/cjs/index.js +11 -11
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/plugins/base_plugin.js +59 -49
- package/dist/cjs/plugins/security_plugin.js +4 -1
- package/dist/cjs/runner/runner.js +34 -24
- package/dist/cjs/tools/agent_tool.js +18 -9
- package/dist/cjs/tools/base_tool.js +16 -6
- package/dist/cjs/tools/function_tool.js +14 -5
- package/dist/cjs/tools/google_search_tool.js +8 -3
- package/dist/cjs/tools/tool_context.js +4 -9
- package/dist/cjs/utils/gemini_schema_util.js +1 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/base_agent.js +9 -3
- package/dist/esm/agents/invocation_context.js +3 -1
- package/dist/esm/agents/llm_agent.js +165 -83
- package/dist/esm/agents/loop_agent.js +14 -4
- package/dist/esm/agents/parallel_agent.js +15 -2
- package/dist/esm/agents/readonly_context.js +4 -1
- package/dist/esm/agents/sequential_agent.js +33 -12
- package/dist/esm/code_executors/base_code_executor.js +10 -1
- package/dist/esm/code_executors/built_in_code_executor.js +13 -2
- package/dist/esm/common.js +53 -10
- package/dist/esm/examples/base_example_provider.js +16 -1
- package/dist/esm/examples/example_util.js +4 -2
- package/dist/esm/index.js +11 -11
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/plugins/base_plugin.js +59 -49
- package/dist/esm/plugins/security_plugin.js +4 -1
- package/dist/esm/runner/runner.js +43 -27
- package/dist/esm/tools/agent_tool.js +17 -9
- package/dist/esm/tools/base_tool.js +14 -5
- package/dist/esm/tools/function_tool.js +13 -7
- package/dist/esm/tools/google_search_tool.js +9 -3
- package/dist/esm/tools/tool_context.js +4 -9
- package/dist/esm/utils/gemini_schema_util.js +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/agents/base_agent.d.ts +14 -3
- package/dist/types/agents/invocation_context.d.ts +4 -2
- package/dist/types/agents/llm_agent.d.ts +42 -30
- package/dist/types/agents/loop_agent.d.ts +16 -0
- package/dist/types/agents/parallel_agent.d.ts +16 -0
- package/dist/types/agents/sequential_agent.d.ts +17 -1
- package/dist/types/auth/auth_schemes.d.ts +5 -2
- package/dist/types/code_executors/base_code_executor.d.ts +14 -0
- package/dist/types/code_executors/built_in_code_executor.d.ts +19 -0
- package/dist/types/common.d.ts +38 -14
- package/dist/types/examples/base_example_provider.d.ts +16 -0
- package/dist/types/plugins/base_plugin.d.ts +50 -40
- package/dist/types/runner/runner.d.ts +17 -9
- package/dist/types/tools/agent_tool.d.ts +14 -0
- package/dist/types/tools/base_tool.d.ts +14 -0
- package/dist/types/tools/function_tool.d.ts +14 -1
- package/dist/types/tools/google_search_tool.d.ts +3 -4
- package/dist/types/tools/tool_context.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/base_agent.js +9 -3
- package/dist/web/agents/invocation_context.js +3 -1
- package/dist/web/agents/llm_agent.js +165 -83
- package/dist/web/agents/loop_agent.js +14 -4
- package/dist/web/agents/parallel_agent.js +15 -2
- package/dist/web/agents/readonly_context.js +4 -1
- package/dist/web/agents/sequential_agent.js +33 -12
- package/dist/web/code_executors/base_code_executor.js +10 -1
- package/dist/web/code_executors/built_in_code_executor.js +13 -2
- package/dist/web/common.js +53 -10
- package/dist/web/examples/base_example_provider.js +16 -1
- package/dist/web/examples/example_util.js +4 -2
- package/dist/web/index.js +1 -1
- package/dist/web/index.js.map +4 -4
- package/dist/web/plugins/base_plugin.js +59 -49
- package/dist/web/plugins/security_plugin.js +4 -1
- package/dist/web/runner/runner.js +44 -28
- package/dist/web/tools/agent_tool.js +17 -9
- package/dist/web/tools/base_tool.js +14 -5
- package/dist/web/tools/function_tool.js +13 -7
- package/dist/web/tools/google_search_tool.js +9 -3
- package/dist/web/tools/tool_context.js +4 -9
- package/dist/web/utils/gemini_schema_util.js +1 -0
- package/dist/web/version.js +1 -1
- package/package.json +2 -2
|
@@ -55,7 +55,9 @@ class BaseAgent {
|
|
|
55
55
|
this.parentAgent = config.parentAgent;
|
|
56
56
|
this.subAgents = config.subAgents || [];
|
|
57
57
|
this.rootAgent = getRootAgent(this);
|
|
58
|
-
this.beforeAgentCallback = getCannonicalCallback(
|
|
58
|
+
this.beforeAgentCallback = getCannonicalCallback(
|
|
59
|
+
config.beforeAgentCallback
|
|
60
|
+
);
|
|
59
61
|
this.afterAgentCallback = getCannonicalCallback(config.afterAgentCallback);
|
|
60
62
|
this.setParentAgentForSubAgents();
|
|
61
63
|
}
|
|
@@ -217,7 +219,9 @@ class BaseAgent {
|
|
|
217
219
|
setParentAgentForSubAgents() {
|
|
218
220
|
for (const subAgent of this.subAgents) {
|
|
219
221
|
if (subAgent.parentAgent) {
|
|
220
|
-
throw new Error(
|
|
222
|
+
throw new Error(
|
|
223
|
+
`Agent "${subAgent.name}" already has a parent agent, current parent: "${subAgent.parentAgent.name}", trying to add: "${this.name}"`
|
|
224
|
+
);
|
|
221
225
|
}
|
|
222
226
|
subAgent.parentAgent = this;
|
|
223
227
|
}
|
|
@@ -225,7 +229,9 @@ class BaseAgent {
|
|
|
225
229
|
}
|
|
226
230
|
function validateAgentName(name) {
|
|
227
231
|
if (!isIdentifier(name)) {
|
|
228
|
-
throw new Error(
|
|
232
|
+
throw new Error(
|
|
233
|
+
`Found invalid agent name: "${name}". Agent name must be a valid identifier. It should start with a letter (a-z, A-Z) or an underscore (_), and can only contain letters, digits (0-9), and underscores.`
|
|
234
|
+
);
|
|
229
235
|
}
|
|
230
236
|
if (name === "user") {
|
|
231
237
|
throw new Error(
|
|
@@ -47,7 +47,9 @@ class InvocationCostManager {
|
|
|
47
47
|
incrementAndEnforceLlmCallsLimit(runConfig) {
|
|
48
48
|
this.numberOfLlmCalls++;
|
|
49
49
|
if (runConfig && runConfig.maxLlmCalls > 0 && this.numberOfLlmCalls > runConfig.maxLlmCalls) {
|
|
50
|
-
throw new Error(
|
|
50
|
+
throw new Error(
|
|
51
|
+
`Max number of llm calls limit of ${runConfig.maxLlmCalls} exceeded`
|
|
52
|
+
);
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
}
|
|
@@ -26,6 +26,7 @@ var llm_agent_exports = {};
|
|
|
26
26
|
__export(llm_agent_exports, {
|
|
27
27
|
LlmAgent: () => LlmAgent,
|
|
28
28
|
REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR: () => REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR,
|
|
29
|
+
isLlmAgent: () => isLlmAgent,
|
|
29
30
|
responseProcessor: () => responseProcessor
|
|
30
31
|
});
|
|
31
32
|
module.exports = __toCommonJS(llm_agent_exports);
|
|
@@ -60,6 +61,7 @@ var import_run_config = require("./run_config.js");
|
|
|
60
61
|
* Copyright 2025 Google LLC
|
|
61
62
|
* SPDX-License-Identifier: Apache-2.0
|
|
62
63
|
*/
|
|
64
|
+
var _a, _b;
|
|
63
65
|
const ADK_AGENT_NAME_LABEL_KEY = "adk_agent_name";
|
|
64
66
|
async function convertToolUnionToTools(toolUnion, context) {
|
|
65
67
|
if (toolUnion instanceof import_base_tool.BaseTool) {
|
|
@@ -69,13 +71,13 @@ async function convertToolUnionToTools(toolUnion, context) {
|
|
|
69
71
|
}
|
|
70
72
|
class BasicLlmRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
|
|
71
73
|
async *runAsync(invocationContext, llmRequest) {
|
|
72
|
-
var
|
|
74
|
+
var _a2;
|
|
73
75
|
const agent = invocationContext.agent;
|
|
74
|
-
if (!(agent
|
|
76
|
+
if (!isLlmAgent(agent)) {
|
|
75
77
|
return;
|
|
76
78
|
}
|
|
77
79
|
llmRequest.model = agent.canonicalModel.model;
|
|
78
|
-
llmRequest.config = { ...(
|
|
80
|
+
llmRequest.config = { ...(_a2 = agent.generateContentConfig) != null ? _a2 : {} };
|
|
79
81
|
if (agent.outputSchema) {
|
|
80
82
|
(0, import_llm_request.setOutputSchema)(llmRequest, agent.outputSchema);
|
|
81
83
|
}
|
|
@@ -112,7 +114,7 @@ class InstructionsLlmRequestProcessor extends import_base_llm_processor.BaseLlmR
|
|
|
112
114
|
return;
|
|
113
115
|
}
|
|
114
116
|
const rootAgent = agent.rootAgent;
|
|
115
|
-
if (rootAgent
|
|
117
|
+
if (isLlmAgent(rootAgent) && rootAgent.globalInstruction) {
|
|
116
118
|
const { instruction, requireStateInjection } = await rootAgent.canonicalGlobalInstruction(
|
|
117
119
|
new import_readonly_context.ReadonlyContext(invocationContext)
|
|
118
120
|
);
|
|
@@ -144,7 +146,7 @@ const INSTRUCTIONS_LLM_REQUEST_PROCESSOR = new InstructionsLlmRequestProcessor()
|
|
|
144
146
|
class ContentRequestProcessor {
|
|
145
147
|
async *runAsync(invocationContext, llmRequest) {
|
|
146
148
|
const agent = invocationContext.agent;
|
|
147
|
-
if (!agent || !(agent
|
|
149
|
+
if (!agent || !isLlmAgent(agent)) {
|
|
148
150
|
return;
|
|
149
151
|
}
|
|
150
152
|
if (agent.includeContents === "default") {
|
|
@@ -232,7 +234,7 @@ to your parent agent.
|
|
|
232
234
|
getTransferTargets(agent) {
|
|
233
235
|
const targets = [];
|
|
234
236
|
targets.push(...agent.subAgents);
|
|
235
|
-
if (!agent.parentAgent || !(agent.parentAgent
|
|
237
|
+
if (!agent.parentAgent || !isLlmAgent(agent.parentAgent)) {
|
|
236
238
|
return targets;
|
|
237
239
|
}
|
|
238
240
|
if (!agent.disallowTransferToParent) {
|
|
@@ -253,7 +255,7 @@ class RequestConfirmationLlmRequestProcessor extends import_base_llm_processor.B
|
|
|
253
255
|
/** Handles tool confirmation information to build the LLM request. */
|
|
254
256
|
async *runAsync(invocationContext, llmRequest) {
|
|
255
257
|
const agent = invocationContext.agent;
|
|
256
|
-
if (!(agent
|
|
258
|
+
if (!isLlmAgent(agent)) {
|
|
257
259
|
return;
|
|
258
260
|
}
|
|
259
261
|
const events = invocationContext.session.events;
|
|
@@ -279,7 +281,9 @@ class RequestConfirmationLlmRequestProcessor extends import_base_llm_processor.B
|
|
|
279
281
|
foundConfirmation = true;
|
|
280
282
|
let toolConfirmation = null;
|
|
281
283
|
if (functionResponse.response && Object.keys(functionResponse.response).length === 1 && "response" in functionResponse.response) {
|
|
282
|
-
toolConfirmation = JSON.parse(
|
|
284
|
+
toolConfirmation = JSON.parse(
|
|
285
|
+
functionResponse.response["response"]
|
|
286
|
+
);
|
|
283
287
|
} else if (functionResponse.response) {
|
|
284
288
|
toolConfirmation = new import_tool_confirmation.ToolConfirmation({
|
|
285
289
|
hint: functionResponse.response["hint"],
|
|
@@ -343,8 +347,12 @@ class RequestConfirmationLlmRequestProcessor extends import_base_llm_processor.B
|
|
|
343
347
|
if (Object.keys(toolsToResumeWithConfirmation).length === 0) {
|
|
344
348
|
continue;
|
|
345
349
|
}
|
|
346
|
-
const toolsList = await agent.canonicalTools(
|
|
347
|
-
|
|
350
|
+
const toolsList = await agent.canonicalTools(
|
|
351
|
+
new import_readonly_context.ReadonlyContext(invocationContext)
|
|
352
|
+
);
|
|
353
|
+
const toolsDict = Object.fromEntries(
|
|
354
|
+
toolsList.map((tool) => [tool.name, tool])
|
|
355
|
+
);
|
|
348
356
|
const functionResponseEvent = await (0, import_functions.handleFunctionCallList)({
|
|
349
357
|
invocationContext,
|
|
350
358
|
functionCalls: Object.values(toolsToResumeWithArgs),
|
|
@@ -373,7 +381,7 @@ class CodeExecutionRequestProcessor extends import_base_llm_processor.BaseLlmReq
|
|
|
373
381
|
for await (const event of runPreProcessor(invocationContext, llmRequest)) {
|
|
374
382
|
yield event;
|
|
375
383
|
}
|
|
376
|
-
if (!(invocationContext.agent.codeExecutor
|
|
384
|
+
if (!(0, import_base_code_executor.isBaseCodeExecutor)(invocationContext.agent.codeExecutor)) {
|
|
377
385
|
return;
|
|
378
386
|
}
|
|
379
387
|
for (const content of llmRequest.contents) {
|
|
@@ -442,7 +450,10 @@ class CodeExecutionResponseProcessor {
|
|
|
442
450
|
if (llmResponse.partial) {
|
|
443
451
|
return;
|
|
444
452
|
}
|
|
445
|
-
for await (const event of runPostProcessor(
|
|
453
|
+
for await (const event of runPostProcessor(
|
|
454
|
+
invocationContext,
|
|
455
|
+
llmResponse
|
|
456
|
+
)) {
|
|
446
457
|
yield event;
|
|
447
458
|
}
|
|
448
459
|
}
|
|
@@ -450,27 +461,36 @@ class CodeExecutionResponseProcessor {
|
|
|
450
461
|
const responseProcessor = new CodeExecutionResponseProcessor();
|
|
451
462
|
async function* runPreProcessor(invocationContext, llmRequest) {
|
|
452
463
|
const agent = invocationContext.agent;
|
|
453
|
-
if (!(agent
|
|
464
|
+
if (!isLlmAgent(agent)) {
|
|
454
465
|
return;
|
|
455
466
|
}
|
|
456
467
|
const codeExecutor = agent.codeExecutor;
|
|
457
|
-
if (!codeExecutor || !(
|
|
468
|
+
if (!codeExecutor || !(0, import_base_code_executor.isBaseCodeExecutor)(codeExecutor)) {
|
|
458
469
|
return;
|
|
459
470
|
}
|
|
460
|
-
if (
|
|
471
|
+
if ((0, import_built_in_code_executor.isBuiltInCodeExecutor)(codeExecutor)) {
|
|
461
472
|
codeExecutor.processLlmRequest(llmRequest);
|
|
462
473
|
return;
|
|
463
474
|
}
|
|
464
475
|
if (!codeExecutor.optimizeDataFile) {
|
|
465
476
|
return;
|
|
466
477
|
}
|
|
467
|
-
const codeExecutorContext = new import_code_executor_context.CodeExecutorContext(
|
|
478
|
+
const codeExecutorContext = new import_code_executor_context.CodeExecutorContext(
|
|
479
|
+
new import_state.State(invocationContext.session.state)
|
|
480
|
+
);
|
|
468
481
|
if (codeExecutorContext.getErrorCount(invocationContext.invocationId) >= codeExecutor.errorRetryAttempts) {
|
|
469
482
|
return;
|
|
470
483
|
}
|
|
471
|
-
const allInputFiles = extractAndReplaceInlineFiles(
|
|
472
|
-
|
|
473
|
-
|
|
484
|
+
const allInputFiles = extractAndReplaceInlineFiles(
|
|
485
|
+
codeExecutorContext,
|
|
486
|
+
llmRequest
|
|
487
|
+
);
|
|
488
|
+
const processedFileNames = new Set(
|
|
489
|
+
codeExecutorContext.getProcessedFileNames()
|
|
490
|
+
);
|
|
491
|
+
const filesToProcess = allInputFiles.filter(
|
|
492
|
+
(f) => !processedFileNames.has(f.name)
|
|
493
|
+
);
|
|
474
494
|
for (const file of filesToProcess) {
|
|
475
495
|
const codeStr = getDataFilePreprocessingCode(file);
|
|
476
496
|
if (!codeStr) {
|
|
@@ -490,7 +510,10 @@ async function* runPreProcessor(invocationContext, llmRequest) {
|
|
|
490
510
|
branch: invocationContext.branch,
|
|
491
511
|
content: codeContent
|
|
492
512
|
});
|
|
493
|
-
const executionId = getOrSetExecutionId(
|
|
513
|
+
const executionId = getOrSetExecutionId(
|
|
514
|
+
invocationContext,
|
|
515
|
+
codeExecutorContext
|
|
516
|
+
);
|
|
494
517
|
const codeExecutionResult = await codeExecutor.executeCode({
|
|
495
518
|
invocationContext,
|
|
496
519
|
codeExecutionInput: {
|
|
@@ -517,20 +540,22 @@ async function* runPreProcessor(invocationContext, llmRequest) {
|
|
|
517
540
|
}
|
|
518
541
|
async function* runPostProcessor(invocationContext, llmResponse) {
|
|
519
542
|
const agent = invocationContext.agent;
|
|
520
|
-
if (!(agent
|
|
543
|
+
if (!isLlmAgent(agent)) {
|
|
521
544
|
return;
|
|
522
545
|
}
|
|
523
546
|
const codeExecutor = agent.codeExecutor;
|
|
524
|
-
if (!codeExecutor || !(
|
|
547
|
+
if (!codeExecutor || !(0, import_base_code_executor.isBaseCodeExecutor)(codeExecutor)) {
|
|
525
548
|
return;
|
|
526
549
|
}
|
|
527
550
|
if (!llmResponse || !llmResponse.content) {
|
|
528
551
|
return;
|
|
529
552
|
}
|
|
530
|
-
if (
|
|
553
|
+
if ((0, import_built_in_code_executor.isBuiltInCodeExecutor)(codeExecutor)) {
|
|
531
554
|
return;
|
|
532
555
|
}
|
|
533
|
-
const codeExecutorContext = new import_code_executor_context.CodeExecutorContext(
|
|
556
|
+
const codeExecutorContext = new import_code_executor_context.CodeExecutorContext(
|
|
557
|
+
new import_state.State(invocationContext.session.state)
|
|
558
|
+
);
|
|
534
559
|
if (codeExecutorContext.getErrorCount(invocationContext.invocationId) >= codeExecutor.errorRetryAttempts) {
|
|
535
560
|
return;
|
|
536
561
|
}
|
|
@@ -548,7 +573,10 @@ async function* runPostProcessor(invocationContext, llmResponse) {
|
|
|
548
573
|
branch: invocationContext.branch,
|
|
549
574
|
content: responseContent
|
|
550
575
|
});
|
|
551
|
-
const executionId = getOrSetExecutionId(
|
|
576
|
+
const executionId = getOrSetExecutionId(
|
|
577
|
+
invocationContext,
|
|
578
|
+
codeExecutorContext
|
|
579
|
+
);
|
|
552
580
|
const codeExecutionResult = await codeExecutor.executeCode({
|
|
553
581
|
invocationContext,
|
|
554
582
|
codeExecutionInput: {
|
|
@@ -571,7 +599,7 @@ async function* runPostProcessor(invocationContext, llmResponse) {
|
|
|
571
599
|
llmResponse.content = null;
|
|
572
600
|
}
|
|
573
601
|
function extractAndReplaceInlineFiles(codeExecutorContext, llmRequest) {
|
|
574
|
-
var
|
|
602
|
+
var _a2;
|
|
575
603
|
const allInputFiles = codeExecutorContext.getInputFiles();
|
|
576
604
|
const savedFileNames = new Set(allInputFiles.map((f) => f.name));
|
|
577
605
|
for (let i = 0; i < llmRequest.contents.length; i++) {
|
|
@@ -581,7 +609,7 @@ function extractAndReplaceInlineFiles(codeExecutorContext, llmRequest) {
|
|
|
581
609
|
}
|
|
582
610
|
for (let j = 0; j < content.parts.length; j++) {
|
|
583
611
|
const part = content.parts[j];
|
|
584
|
-
const mimeType = (
|
|
612
|
+
const mimeType = (_a2 = part.inlineData) == null ? void 0 : _a2.mimeType;
|
|
585
613
|
if (!mimeType || !part.inlineData || !DATA_FILE_UTIL_MAP[mimeType]) {
|
|
586
614
|
continue;
|
|
587
615
|
}
|
|
@@ -603,9 +631,9 @@ Available file: \`${fileName}\`
|
|
|
603
631
|
return allInputFiles;
|
|
604
632
|
}
|
|
605
633
|
function getOrSetExecutionId(invocationContext, codeExecutorContext) {
|
|
606
|
-
var
|
|
634
|
+
var _a2;
|
|
607
635
|
const agent = invocationContext.agent;
|
|
608
|
-
if (!(agent
|
|
636
|
+
if (!isLlmAgent(agent) || !((_a2 = agent.codeExecutor) == null ? void 0 : _a2.stateful)) {
|
|
609
637
|
return void 0;
|
|
610
638
|
}
|
|
611
639
|
let executionId = codeExecutorContext.getExecutionId();
|
|
@@ -623,7 +651,9 @@ async function postProcessCodeExecutionResult(invocationContext, codeExecutorCon
|
|
|
623
651
|
role: "model",
|
|
624
652
|
parts: [(0, import_code_execution_utils.buildCodeExecutionResultPart)(codeExecutionResult)]
|
|
625
653
|
};
|
|
626
|
-
const eventActions = (0, import_event_actions.createEventActions)({
|
|
654
|
+
const eventActions = (0, import_event_actions.createEventActions)({
|
|
655
|
+
stateDelta: codeExecutorContext.getStateDelta()
|
|
656
|
+
});
|
|
627
657
|
if (codeExecutionResult.stderr) {
|
|
628
658
|
codeExecutorContext.incrementErrorCount(invocationContext.invocationId);
|
|
629
659
|
} else {
|
|
@@ -662,10 +692,7 @@ function getDataFilePreprocessingCode(file) {
|
|
|
662
692
|
return void 0;
|
|
663
693
|
}
|
|
664
694
|
const varName = getNormalizedFileName(file.name);
|
|
665
|
-
const loaderCode = DATA_FILE_UTIL_MAP[file.mimeType].loaderCodeTemplate.replace(
|
|
666
|
-
"{filename}",
|
|
667
|
-
file.name
|
|
668
|
-
);
|
|
695
|
+
const loaderCode = DATA_FILE_UTIL_MAP[file.mimeType].loaderCodeTemplate.replace("{filename}", file.name);
|
|
669
696
|
return `
|
|
670
697
|
${DATA_FILE_HELPER_LIB}
|
|
671
698
|
|
|
@@ -677,13 +704,19 @@ explore_df(${varName})
|
|
|
677
704
|
`;
|
|
678
705
|
}
|
|
679
706
|
const CODE_EXECUTION_REQUEST_PROCESSOR = new CodeExecutionRequestProcessor();
|
|
680
|
-
|
|
707
|
+
const LLM_AGENT_SIGNATURE_SYMBOL = Symbol.for("google.adk.llmAgent");
|
|
708
|
+
function isLlmAgent(obj) {
|
|
709
|
+
return typeof obj === "object" && obj !== null && LLM_AGENT_SIGNATURE_SYMBOL in obj && obj[LLM_AGENT_SIGNATURE_SYMBOL] === true;
|
|
710
|
+
}
|
|
711
|
+
class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
681
712
|
constructor(config) {
|
|
682
|
-
var
|
|
713
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
|
|
683
714
|
super(config);
|
|
715
|
+
/** A unique symbol to identify ADK LLM agent class. */
|
|
716
|
+
this[_a] = true;
|
|
684
717
|
this.model = config.model;
|
|
685
|
-
this.instruction = (
|
|
686
|
-
this.globalInstruction = (
|
|
718
|
+
this.instruction = (_a2 = config.instruction) != null ? _a2 : "";
|
|
719
|
+
this.globalInstruction = (_b2 = config.globalInstruction) != null ? _b2 : "";
|
|
687
720
|
this.tools = (_c = config.tools) != null ? _c : [];
|
|
688
721
|
this.generateContentConfig = config.generateContentConfig;
|
|
689
722
|
this.disallowTransferToParent = (_d = config.disallowTransferToParent) != null ? _d : false;
|
|
@@ -761,7 +794,7 @@ class LlmAgent extends import_base_agent.BaseAgent {
|
|
|
761
794
|
}
|
|
762
795
|
let ancestorAgent = this.parentAgent;
|
|
763
796
|
while (ancestorAgent) {
|
|
764
|
-
if (ancestorAgent
|
|
797
|
+
if (isLlmAgent(ancestorAgent)) {
|
|
765
798
|
return ancestorAgent.canonicalModel;
|
|
766
799
|
}
|
|
767
800
|
ancestorAgent = ancestorAgent.parentAgent;
|
|
@@ -769,12 +802,12 @@ class LlmAgent extends import_base_agent.BaseAgent {
|
|
|
769
802
|
throw new Error(`No model found for ${this.name}.`);
|
|
770
803
|
}
|
|
771
804
|
/**
|
|
772
|
-
* The resolved
|
|
805
|
+
* The resolved instruction field to construct instruction for this
|
|
773
806
|
* agent.
|
|
774
807
|
*
|
|
775
808
|
* This method is only for use by Agent Development Kit.
|
|
776
809
|
* @param context The context to retrieve the session state.
|
|
777
|
-
* @returns The resolved
|
|
810
|
+
* @returns The resolved instruction field.
|
|
778
811
|
*/
|
|
779
812
|
async canonicalInstruction(context) {
|
|
780
813
|
if (typeof this.instruction === "string") {
|
|
@@ -786,11 +819,11 @@ class LlmAgent extends import_base_agent.BaseAgent {
|
|
|
786
819
|
};
|
|
787
820
|
}
|
|
788
821
|
/**
|
|
789
|
-
* The resolved
|
|
822
|
+
* The resolved globalInstruction field to construct global instruction.
|
|
790
823
|
*
|
|
791
824
|
* This method is only for use by Agent Development Kit.
|
|
792
825
|
* @param context The context to retrieve the session state.
|
|
793
|
-
* @returns The resolved
|
|
826
|
+
* @returns The resolved globalInstruction field.
|
|
794
827
|
*/
|
|
795
828
|
async canonicalGlobalInstruction(context) {
|
|
796
829
|
if (typeof this.globalInstruction === "string") {
|
|
@@ -802,7 +835,7 @@ class LlmAgent extends import_base_agent.BaseAgent {
|
|
|
802
835
|
};
|
|
803
836
|
}
|
|
804
837
|
/**
|
|
805
|
-
* The resolved
|
|
838
|
+
* The resolved tools field as a list of BaseTool based on the context.
|
|
806
839
|
*
|
|
807
840
|
* This method is only for use by Agent Development Kit.
|
|
808
841
|
*/
|
|
@@ -830,7 +863,7 @@ class LlmAgent extends import_base_agent.BaseAgent {
|
|
|
830
863
|
return [callback];
|
|
831
864
|
}
|
|
832
865
|
/**
|
|
833
|
-
* The resolved
|
|
866
|
+
* The resolved beforeModelCallback field as a list of
|
|
834
867
|
* SingleBeforeModelCallback.
|
|
835
868
|
*
|
|
836
869
|
* This method is only for use by Agent Development Kit.
|
|
@@ -839,7 +872,7 @@ class LlmAgent extends import_base_agent.BaseAgent {
|
|
|
839
872
|
return LlmAgent.normalizeCallbackArray(this.beforeModelCallback);
|
|
840
873
|
}
|
|
841
874
|
/**
|
|
842
|
-
* The resolved
|
|
875
|
+
* The resolved afterModelCallback field as a list of
|
|
843
876
|
* SingleAfterModelCallback.
|
|
844
877
|
*
|
|
845
878
|
* This method is only for use by Agent Development Kit.
|
|
@@ -848,7 +881,7 @@ class LlmAgent extends import_base_agent.BaseAgent {
|
|
|
848
881
|
return LlmAgent.normalizeCallbackArray(this.afterModelCallback);
|
|
849
882
|
}
|
|
850
883
|
/**
|
|
851
|
-
* The resolved
|
|
884
|
+
* The resolved beforeToolCallback field as a list of
|
|
852
885
|
* BeforeToolCallback.
|
|
853
886
|
*
|
|
854
887
|
* This method is only for use by Agent Development Kit.
|
|
@@ -857,7 +890,7 @@ class LlmAgent extends import_base_agent.BaseAgent {
|
|
|
857
890
|
return LlmAgent.normalizeCallbackArray(this.beforeToolCallback);
|
|
858
891
|
}
|
|
859
892
|
/**
|
|
860
|
-
* The resolved
|
|
893
|
+
* The resolved afterToolCallback field as a list of AfterToolCallback.
|
|
861
894
|
*
|
|
862
895
|
* This method is only for use by Agent Development Kit.
|
|
863
896
|
*/
|
|
@@ -874,7 +907,7 @@ class LlmAgent extends import_base_agent.BaseAgent {
|
|
|
874
907
|
* @param event The event to process.
|
|
875
908
|
*/
|
|
876
909
|
maybeSaveOutputToState(event) {
|
|
877
|
-
var
|
|
910
|
+
var _a2, _b2;
|
|
878
911
|
if (event.author !== this.name) {
|
|
879
912
|
import_logger.logger.debug(
|
|
880
913
|
`Skipping output save for agent ${this.name}: event authored by ${event.author}`
|
|
@@ -893,7 +926,7 @@ class LlmAgent extends import_base_agent.BaseAgent {
|
|
|
893
926
|
);
|
|
894
927
|
return;
|
|
895
928
|
}
|
|
896
|
-
if (!((
|
|
929
|
+
if (!((_b2 = (_a2 = event.content) == null ? void 0 : _a2.parts) == null ? void 0 : _b2.length)) {
|
|
897
930
|
import_logger.logger.debug(
|
|
898
931
|
`Skipping output save for agent ${this.name}: event content is empty`
|
|
899
932
|
);
|
|
@@ -953,7 +986,10 @@ class LlmAgent extends import_base_agent.BaseAgent {
|
|
|
953
986
|
liveConnectConfig: {}
|
|
954
987
|
};
|
|
955
988
|
for (const processor of this.requestProcessors) {
|
|
956
|
-
for await (const event of processor.runAsync(
|
|
989
|
+
for await (const event of processor.runAsync(
|
|
990
|
+
invocationContext,
|
|
991
|
+
llmRequest
|
|
992
|
+
)) {
|
|
957
993
|
yield event;
|
|
958
994
|
}
|
|
959
995
|
}
|
|
@@ -993,9 +1029,12 @@ class LlmAgent extends import_base_agent.BaseAgent {
|
|
|
993
1029
|
}
|
|
994
1030
|
}
|
|
995
1031
|
async *postprocess(invocationContext, llmRequest, llmResponse, modelResponseEvent) {
|
|
996
|
-
var
|
|
1032
|
+
var _a2;
|
|
997
1033
|
for (const processor of this.responseProcessors) {
|
|
998
|
-
for await (const event of processor.runAsync(
|
|
1034
|
+
for await (const event of processor.runAsync(
|
|
1035
|
+
invocationContext,
|
|
1036
|
+
llmResponse
|
|
1037
|
+
)) {
|
|
999
1038
|
yield event;
|
|
1000
1039
|
}
|
|
1001
1040
|
}
|
|
@@ -1016,7 +1055,7 @@ class LlmAgent extends import_base_agent.BaseAgent {
|
|
|
1016
1055
|
}
|
|
1017
1056
|
}
|
|
1018
1057
|
yield mergedEvent;
|
|
1019
|
-
if (!((
|
|
1058
|
+
if (!((_a2 = (0, import_event.getFunctionCalls)(mergedEvent)) == null ? void 0 : _a2.length)) {
|
|
1020
1059
|
return;
|
|
1021
1060
|
}
|
|
1022
1061
|
const functionResponseEvent = await (0, import_functions.handleFunctionCallsAsync)({
|
|
@@ -1029,7 +1068,10 @@ class LlmAgent extends import_base_agent.BaseAgent {
|
|
|
1029
1068
|
if (!functionResponseEvent) {
|
|
1030
1069
|
return;
|
|
1031
1070
|
}
|
|
1032
|
-
const authEvent = (0, import_functions.generateAuthEvent)(
|
|
1071
|
+
const authEvent = (0, import_functions.generateAuthEvent)(
|
|
1072
|
+
invocationContext,
|
|
1073
|
+
functionResponseEvent
|
|
1074
|
+
);
|
|
1033
1075
|
if (authEvent) {
|
|
1034
1076
|
yield authEvent;
|
|
1035
1077
|
}
|
|
@@ -1071,7 +1113,7 @@ class LlmAgent extends import_base_agent.BaseAgent {
|
|
|
1071
1113
|
return agentToRun;
|
|
1072
1114
|
}
|
|
1073
1115
|
async *callLlmAsync(invocationContext, llmRequest, modelResponseEvent) {
|
|
1074
|
-
var
|
|
1116
|
+
var _a2, _b2, _c, _d, _e;
|
|
1075
1117
|
const beforeModelResponse = await this.handleBeforeModelCallback(
|
|
1076
1118
|
invocationContext,
|
|
1077
1119
|
llmRequest,
|
|
@@ -1081,8 +1123,8 @@ class LlmAgent extends import_base_agent.BaseAgent {
|
|
|
1081
1123
|
yield beforeModelResponse;
|
|
1082
1124
|
return;
|
|
1083
1125
|
}
|
|
1084
|
-
(
|
|
1085
|
-
(_c = (
|
|
1126
|
+
(_a2 = llmRequest.config) != null ? _a2 : llmRequest.config = {};
|
|
1127
|
+
(_c = (_b2 = llmRequest.config).labels) != null ? _c : _b2.labels = {};
|
|
1086
1128
|
if (!llmRequest.config.labels[ADK_AGENT_NAME_LABEL_KEY]) {
|
|
1087
1129
|
llmRequest.config.labels[ADK_AGENT_NAME_LABEL_KEY] = this.name;
|
|
1088
1130
|
}
|
|
@@ -1112,17 +1154,22 @@ class LlmAgent extends import_base_agent.BaseAgent {
|
|
|
1112
1154
|
}
|
|
1113
1155
|
}
|
|
1114
1156
|
async handleBeforeModelCallback(invocationContext, llmRequest, modelResponseEvent) {
|
|
1115
|
-
const callbackContext = new import_callback_context.CallbackContext(
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1157
|
+
const callbackContext = new import_callback_context.CallbackContext({
|
|
1158
|
+
invocationContext,
|
|
1159
|
+
eventActions: modelResponseEvent.actions
|
|
1160
|
+
});
|
|
1161
|
+
const beforeModelCallbackResponse = await invocationContext.pluginManager.runBeforeModelCallback({
|
|
1162
|
+
callbackContext,
|
|
1163
|
+
llmRequest
|
|
1164
|
+
});
|
|
1121
1165
|
if (beforeModelCallbackResponse) {
|
|
1122
1166
|
return beforeModelCallbackResponse;
|
|
1123
1167
|
}
|
|
1124
1168
|
for (const callback of this.canonicalBeforeModelCallbacks) {
|
|
1125
|
-
const callbackResponse = await callback({
|
|
1169
|
+
const callbackResponse = await callback({
|
|
1170
|
+
context: callbackContext,
|
|
1171
|
+
request: llmRequest
|
|
1172
|
+
});
|
|
1126
1173
|
if (callbackResponse) {
|
|
1127
1174
|
return callbackResponse;
|
|
1128
1175
|
}
|
|
@@ -1130,17 +1177,22 @@ class LlmAgent extends import_base_agent.BaseAgent {
|
|
|
1130
1177
|
return void 0;
|
|
1131
1178
|
}
|
|
1132
1179
|
async handleAfterModelCallback(invocationContext, llmResponse, modelResponseEvent) {
|
|
1133
|
-
const callbackContext = new import_callback_context.CallbackContext(
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1180
|
+
const callbackContext = new import_callback_context.CallbackContext({
|
|
1181
|
+
invocationContext,
|
|
1182
|
+
eventActions: modelResponseEvent.actions
|
|
1183
|
+
});
|
|
1184
|
+
const afterModelCallbackResponse = await invocationContext.pluginManager.runAfterModelCallback({
|
|
1185
|
+
callbackContext,
|
|
1186
|
+
llmResponse
|
|
1187
|
+
});
|
|
1139
1188
|
if (afterModelCallbackResponse) {
|
|
1140
1189
|
return afterModelCallbackResponse;
|
|
1141
1190
|
}
|
|
1142
1191
|
for (const callback of this.canonicalAfterModelCallbacks) {
|
|
1143
|
-
const callbackResponse = await callback({
|
|
1192
|
+
const callbackResponse = await callback({
|
|
1193
|
+
context: callbackContext,
|
|
1194
|
+
response: llmResponse
|
|
1195
|
+
});
|
|
1144
1196
|
if (callbackResponse) {
|
|
1145
1197
|
return callbackResponse;
|
|
1146
1198
|
}
|
|
@@ -1153,9 +1205,10 @@ class LlmAgent extends import_base_agent.BaseAgent {
|
|
|
1153
1205
|
yield response;
|
|
1154
1206
|
}
|
|
1155
1207
|
} catch (modelError) {
|
|
1156
|
-
const callbackContext = new import_callback_context.CallbackContext(
|
|
1157
|
-
|
|
1158
|
-
|
|
1208
|
+
const callbackContext = new import_callback_context.CallbackContext({
|
|
1209
|
+
invocationContext,
|
|
1210
|
+
eventActions: modelResponseEvent.actions
|
|
1211
|
+
});
|
|
1159
1212
|
if (modelError instanceof Error) {
|
|
1160
1213
|
const onModelErrorCallbackResponse = await invocationContext.pluginManager.runOnModelErrorCallback({
|
|
1161
1214
|
callbackContext,
|
|
@@ -1188,5 +1241,6 @@ class LlmAgent extends import_base_agent.BaseAgent {
|
|
|
1188
1241
|
0 && (module.exports = {
|
|
1189
1242
|
LlmAgent,
|
|
1190
1243
|
REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR,
|
|
1244
|
+
isLlmAgent,
|
|
1191
1245
|
responseProcessor
|
|
1192
1246
|
});
|
|
@@ -24,7 +24,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var loop_agent_exports = {};
|
|
26
26
|
__export(loop_agent_exports, {
|
|
27
|
-
LoopAgent: () => LoopAgent
|
|
27
|
+
LoopAgent: () => LoopAgent,
|
|
28
|
+
isLoopAgent: () => isLoopAgent
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(loop_agent_exports);
|
|
30
31
|
var import_base_agent = require("./base_agent.js");
|
|
@@ -33,11 +34,20 @@ var import_base_agent = require("./base_agent.js");
|
|
|
33
34
|
* Copyright 2025 Google LLC
|
|
34
35
|
* SPDX-License-Identifier: Apache-2.0
|
|
35
36
|
*/
|
|
36
|
-
|
|
37
|
+
var _a, _b;
|
|
38
|
+
const LOOP_AGENT_SIGNATURE_SYMBOL = Symbol.for("google.adk.loopAgent");
|
|
39
|
+
function isLoopAgent(obj) {
|
|
40
|
+
return typeof obj === "object" && obj !== null && LOOP_AGENT_SIGNATURE_SYMBOL in obj && obj[LOOP_AGENT_SIGNATURE_SYMBOL] === true;
|
|
41
|
+
}
|
|
42
|
+
class LoopAgent extends (_b = import_base_agent.BaseAgent, _a = LOOP_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
37
43
|
constructor(config) {
|
|
38
|
-
var
|
|
44
|
+
var _a2;
|
|
39
45
|
super(config);
|
|
40
|
-
|
|
46
|
+
/**
|
|
47
|
+
* A unique symbol to identify ADK loop agent class.
|
|
48
|
+
*/
|
|
49
|
+
this[_a] = true;
|
|
50
|
+
this.maxIterations = (_a2 = config.maxIterations) != null ? _a2 : Number.MAX_SAFE_INTEGER;
|
|
41
51
|
}
|
|
42
52
|
async *runAsyncImpl(context) {
|
|
43
53
|
let iteration = 0;
|
|
@@ -64,5 +74,6 @@ class LoopAgent extends import_base_agent.BaseAgent {
|
|
|
64
74
|
}
|
|
65
75
|
// Annotate the CommonJS export names for ESM import in node:
|
|
66
76
|
0 && (module.exports = {
|
|
67
|
-
LoopAgent
|
|
77
|
+
LoopAgent,
|
|
78
|
+
isLoopAgent
|
|
68
79
|
});
|
|
@@ -24,7 +24,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var parallel_agent_exports = {};
|
|
26
26
|
__export(parallel_agent_exports, {
|
|
27
|
-
ParallelAgent: () => ParallelAgent
|
|
27
|
+
ParallelAgent: () => ParallelAgent,
|
|
28
|
+
isParallelAgent: () => isParallelAgent
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(parallel_agent_exports);
|
|
30
31
|
var import_base_agent = require("./base_agent.js");
|
|
@@ -34,7 +35,19 @@ var import_invocation_context = require("./invocation_context.js");
|
|
|
34
35
|
* Copyright 2025 Google LLC
|
|
35
36
|
* SPDX-License-Identifier: Apache-2.0
|
|
36
37
|
*/
|
|
37
|
-
|
|
38
|
+
var _a, _b;
|
|
39
|
+
const PARALLEL_AGENT_SIGNATURE_SYMBOL = Symbol.for("google.adk.parallelAgent");
|
|
40
|
+
function isParallelAgent(obj) {
|
|
41
|
+
return typeof obj === "object" && obj !== null && PARALLEL_AGENT_SIGNATURE_SYMBOL in obj && obj[PARALLEL_AGENT_SIGNATURE_SYMBOL] === true;
|
|
42
|
+
}
|
|
43
|
+
class ParallelAgent extends (_b = import_base_agent.BaseAgent, _a = PARALLEL_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
44
|
+
constructor() {
|
|
45
|
+
super(...arguments);
|
|
46
|
+
/**
|
|
47
|
+
* A unique symbol to identify ADK parallel agent class.
|
|
48
|
+
*/
|
|
49
|
+
this[_a] = true;
|
|
50
|
+
}
|
|
38
51
|
async *runAsyncImpl(context) {
|
|
39
52
|
const agentRuns = this.subAgents.map(
|
|
40
53
|
(subAgent) => subAgent.runAsync(
|
|
@@ -74,5 +87,6 @@ async function* mergeAgentRuns(agentRuns) {
|
|
|
74
87
|
}
|
|
75
88
|
// Annotate the CommonJS export names for ESM import in node:
|
|
76
89
|
0 && (module.exports = {
|
|
77
|
-
ParallelAgent
|
|
90
|
+
ParallelAgent,
|
|
91
|
+
isParallelAgent
|
|
78
92
|
});
|
|
@@ -59,7 +59,10 @@ class ReadonlyContext {
|
|
|
59
59
|
* The state of the current session.
|
|
60
60
|
*/
|
|
61
61
|
get state() {
|
|
62
|
-
return new import_state.State(
|
|
62
|
+
return new import_state.State(
|
|
63
|
+
this.invocationContext.session.state,
|
|
64
|
+
{}
|
|
65
|
+
);
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
68
|
// Annotate the CommonJS export names for ESM import in node:
|