@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.
Files changed (92) hide show
  1. package/dist/cjs/agents/base_agent.js +9 -3
  2. package/dist/cjs/agents/invocation_context.js +3 -1
  3. package/dist/cjs/agents/llm_agent.js +129 -75
  4. package/dist/cjs/agents/loop_agent.js +16 -5
  5. package/dist/cjs/agents/parallel_agent.js +17 -3
  6. package/dist/cjs/agents/readonly_context.js +4 -1
  7. package/dist/cjs/agents/sequential_agent.js +34 -12
  8. package/dist/cjs/code_executors/base_code_executor.js +12 -2
  9. package/dist/cjs/code_executors/built_in_code_executor.js +15 -3
  10. package/dist/cjs/common.js +41 -0
  11. package/dist/cjs/examples/base_example_provider.js +18 -2
  12. package/dist/cjs/examples/example_util.js +1 -1
  13. package/dist/cjs/index.js +11 -11
  14. package/dist/cjs/index.js.map +4 -4
  15. package/dist/cjs/plugins/base_plugin.js +59 -49
  16. package/dist/cjs/plugins/security_plugin.js +4 -1
  17. package/dist/cjs/runner/runner.js +34 -24
  18. package/dist/cjs/tools/agent_tool.js +18 -9
  19. package/dist/cjs/tools/base_tool.js +16 -6
  20. package/dist/cjs/tools/function_tool.js +14 -5
  21. package/dist/cjs/tools/google_search_tool.js +8 -3
  22. package/dist/cjs/tools/tool_context.js +4 -9
  23. package/dist/cjs/utils/gemini_schema_util.js +1 -0
  24. package/dist/cjs/version.js +1 -1
  25. package/dist/esm/agents/base_agent.js +9 -3
  26. package/dist/esm/agents/invocation_context.js +3 -1
  27. package/dist/esm/agents/llm_agent.js +165 -83
  28. package/dist/esm/agents/loop_agent.js +14 -4
  29. package/dist/esm/agents/parallel_agent.js +15 -2
  30. package/dist/esm/agents/readonly_context.js +4 -1
  31. package/dist/esm/agents/sequential_agent.js +33 -12
  32. package/dist/esm/code_executors/base_code_executor.js +10 -1
  33. package/dist/esm/code_executors/built_in_code_executor.js +13 -2
  34. package/dist/esm/common.js +53 -10
  35. package/dist/esm/examples/base_example_provider.js +16 -1
  36. package/dist/esm/examples/example_util.js +4 -2
  37. package/dist/esm/index.js +11 -11
  38. package/dist/esm/index.js.map +4 -4
  39. package/dist/esm/plugins/base_plugin.js +59 -49
  40. package/dist/esm/plugins/security_plugin.js +4 -1
  41. package/dist/esm/runner/runner.js +43 -27
  42. package/dist/esm/tools/agent_tool.js +17 -9
  43. package/dist/esm/tools/base_tool.js +14 -5
  44. package/dist/esm/tools/function_tool.js +13 -7
  45. package/dist/esm/tools/google_search_tool.js +9 -3
  46. package/dist/esm/tools/tool_context.js +4 -9
  47. package/dist/esm/utils/gemini_schema_util.js +1 -0
  48. package/dist/esm/version.js +1 -1
  49. package/dist/types/agents/base_agent.d.ts +14 -3
  50. package/dist/types/agents/invocation_context.d.ts +4 -2
  51. package/dist/types/agents/llm_agent.d.ts +42 -30
  52. package/dist/types/agents/loop_agent.d.ts +16 -0
  53. package/dist/types/agents/parallel_agent.d.ts +16 -0
  54. package/dist/types/agents/sequential_agent.d.ts +17 -1
  55. package/dist/types/auth/auth_schemes.d.ts +5 -2
  56. package/dist/types/code_executors/base_code_executor.d.ts +14 -0
  57. package/dist/types/code_executors/built_in_code_executor.d.ts +19 -0
  58. package/dist/types/common.d.ts +38 -14
  59. package/dist/types/examples/base_example_provider.d.ts +16 -0
  60. package/dist/types/plugins/base_plugin.d.ts +50 -40
  61. package/dist/types/runner/runner.d.ts +17 -9
  62. package/dist/types/tools/agent_tool.d.ts +14 -0
  63. package/dist/types/tools/base_tool.d.ts +14 -0
  64. package/dist/types/tools/function_tool.d.ts +14 -1
  65. package/dist/types/tools/google_search_tool.d.ts +3 -4
  66. package/dist/types/tools/tool_context.d.ts +1 -1
  67. package/dist/types/version.d.ts +1 -1
  68. package/dist/web/agents/base_agent.js +9 -3
  69. package/dist/web/agents/invocation_context.js +3 -1
  70. package/dist/web/agents/llm_agent.js +165 -83
  71. package/dist/web/agents/loop_agent.js +14 -4
  72. package/dist/web/agents/parallel_agent.js +15 -2
  73. package/dist/web/agents/readonly_context.js +4 -1
  74. package/dist/web/agents/sequential_agent.js +33 -12
  75. package/dist/web/code_executors/base_code_executor.js +10 -1
  76. package/dist/web/code_executors/built_in_code_executor.js +13 -2
  77. package/dist/web/common.js +53 -10
  78. package/dist/web/examples/base_example_provider.js +16 -1
  79. package/dist/web/examples/example_util.js +4 -2
  80. package/dist/web/index.js +1 -1
  81. package/dist/web/index.js.map +4 -4
  82. package/dist/web/plugins/base_plugin.js +59 -49
  83. package/dist/web/plugins/security_plugin.js +4 -1
  84. package/dist/web/runner/runner.js +44 -28
  85. package/dist/web/tools/agent_tool.js +17 -9
  86. package/dist/web/tools/base_tool.js +14 -5
  87. package/dist/web/tools/function_tool.js +13 -7
  88. package/dist/web/tools/google_search_tool.js +9 -3
  89. package/dist/web/tools/tool_context.js +4 -9
  90. package/dist/web/utils/gemini_schema_util.js +1 -0
  91. package/dist/web/version.js +1 -1
  92. package/package.json +2 -2
@@ -36,16 +36,33 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
36
36
  * Copyright 2025 Google LLC
37
37
  * SPDX-License-Identifier: Apache-2.0
38
38
  */
39
+ var _a, _b;
39
40
  import { cloneDeep } from "lodash-es";
40
41
  import { z } from "zod";
41
- import { BaseCodeExecutor } from "../code_executors/base_code_executor.js";
42
- import { BuiltInCodeExecutor } from "../code_executors/built_in_code_executor.js";
43
- import { buildCodeExecutionResultPart, buildExecutableCodePart, convertCodeExecutionParts, extractCodeAndTruncateContent } from "../code_executors/code_execution_utils.js";
42
+ import {
43
+ isBaseCodeExecutor
44
+ } from "../code_executors/base_code_executor.js";
45
+ import { isBuiltInCodeExecutor } from "../code_executors/built_in_code_executor.js";
46
+ import {
47
+ buildCodeExecutionResultPart,
48
+ buildExecutableCodePart,
49
+ convertCodeExecutionParts,
50
+ extractCodeAndTruncateContent
51
+ } from "../code_executors/code_execution_utils.js";
44
52
  import { CodeExecutorContext } from "../code_executors/code_executor_context.js";
45
- import { createEvent, createNewEventId, getFunctionCalls, getFunctionResponses, isFinalResponse } from "../events/event.js";
53
+ import {
54
+ createEvent,
55
+ createNewEventId,
56
+ getFunctionCalls,
57
+ getFunctionResponses,
58
+ isFinalResponse
59
+ } from "../events/event.js";
46
60
  import { createEventActions } from "../events/event_actions.js";
47
61
  import { isBaseLlm } from "../models/base_llm.js";
48
- import { appendInstructions, setOutputSchema } from "../models/llm_request.js";
62
+ import {
63
+ appendInstructions,
64
+ setOutputSchema
65
+ } from "../models/llm_request.js";
49
66
  import { LLMRegistry } from "../models/registry.js";
50
67
  import { State } from "../sessions/state.js";
51
68
  import { BaseTool } from "../tools/base_tool.js";
@@ -55,10 +72,23 @@ import { ToolContext } from "../tools/tool_context.js";
55
72
  import { base64Decode } from "../utils/env_aware_utils.js";
56
73
  import { logger } from "../utils/logger.js";
57
74
  import { BaseAgent } from "./base_agent.js";
58
- import { BaseLlmRequestProcessor } from "./base_llm_processor.js";
75
+ import {
76
+ BaseLlmRequestProcessor
77
+ } from "./base_llm_processor.js";
59
78
  import { CallbackContext } from "./callback_context.js";
60
- import { getContents, getCurrentTurnContents } from "./content_processor_utils.js";
61
- import { generateAuthEvent, generateRequestConfirmationEvent, getLongRunningFunctionCalls, handleFunctionCallList, handleFunctionCallsAsync, populateClientFunctionCallId, REQUEST_CONFIRMATION_FUNCTION_CALL_NAME } from "./functions.js";
79
+ import {
80
+ getContents,
81
+ getCurrentTurnContents
82
+ } from "./content_processor_utils.js";
83
+ import {
84
+ generateAuthEvent,
85
+ generateRequestConfirmationEvent,
86
+ getLongRunningFunctionCalls,
87
+ handleFunctionCallList,
88
+ handleFunctionCallsAsync,
89
+ populateClientFunctionCallId,
90
+ REQUEST_CONFIRMATION_FUNCTION_CALL_NAME
91
+ } from "./functions.js";
62
92
  import { injectSessionState } from "./instructions.js";
63
93
  import { ReadonlyContext } from "./readonly_context.js";
64
94
  import { StreamingMode } from "./run_config.js";
@@ -72,13 +102,13 @@ async function convertToolUnionToTools(toolUnion, context) {
72
102
  class BasicLlmRequestProcessor extends BaseLlmRequestProcessor {
73
103
  runAsync(invocationContext, llmRequest) {
74
104
  return __asyncGenerator(this, null, function* () {
75
- var _a;
105
+ var _a2;
76
106
  const agent = invocationContext.agent;
77
- if (!(agent instanceof LlmAgent)) {
107
+ if (!isLlmAgent(agent)) {
78
108
  return;
79
109
  }
80
110
  llmRequest.model = agent.canonicalModel.model;
81
- llmRequest.config = __spreadValues({}, (_a = agent.generateContentConfig) != null ? _a : {});
111
+ llmRequest.config = __spreadValues({}, (_a2 = agent.generateContentConfig) != null ? _a2 : {});
82
112
  if (agent.outputSchema) {
83
113
  setOutputSchema(llmRequest, agent.outputSchema);
84
114
  }
@@ -119,7 +149,7 @@ class InstructionsLlmRequestProcessor extends BaseLlmRequestProcessor {
119
149
  return;
120
150
  }
121
151
  const rootAgent = agent.rootAgent;
122
- if (rootAgent instanceof LlmAgent && rootAgent.globalInstruction) {
152
+ if (isLlmAgent(rootAgent) && rootAgent.globalInstruction) {
123
153
  const { instruction, requireStateInjection } = yield new __await(rootAgent.canonicalGlobalInstruction(
124
154
  new ReadonlyContext(invocationContext)
125
155
  ));
@@ -153,7 +183,7 @@ class ContentRequestProcessor {
153
183
  runAsync(invocationContext, llmRequest) {
154
184
  return __asyncGenerator(this, null, function* () {
155
185
  const agent = invocationContext.agent;
156
- if (!agent || !(agent instanceof LlmAgent)) {
186
+ if (!agent || !isLlmAgent(agent)) {
157
187
  return;
158
188
  }
159
189
  if (agent.includeContents === "default") {
@@ -225,7 +255,7 @@ class AgentTransferLlmRequestProcessor extends BaseLlmRequestProcessor {
225
255
  getTransferTargets(agent) {
226
256
  const targets = [];
227
257
  targets.push(...agent.subAgents);
228
- if (!agent.parentAgent || !(agent.parentAgent instanceof LlmAgent)) {
258
+ if (!agent.parentAgent || !isLlmAgent(agent.parentAgent)) {
229
259
  return targets;
230
260
  }
231
261
  if (!agent.disallowTransferToParent) {
@@ -247,7 +277,7 @@ class RequestConfirmationLlmRequestProcessor extends BaseLlmRequestProcessor {
247
277
  runAsync(invocationContext, llmRequest) {
248
278
  return __asyncGenerator(this, null, function* () {
249
279
  const agent = invocationContext.agent;
250
- if (!(agent instanceof LlmAgent)) {
280
+ if (!isLlmAgent(agent)) {
251
281
  return;
252
282
  }
253
283
  const events = invocationContext.session.events;
@@ -273,7 +303,9 @@ class RequestConfirmationLlmRequestProcessor extends BaseLlmRequestProcessor {
273
303
  foundConfirmation = true;
274
304
  let toolConfirmation = null;
275
305
  if (functionResponse.response && Object.keys(functionResponse.response).length === 1 && "response" in functionResponse.response) {
276
- toolConfirmation = JSON.parse(functionResponse.response["response"]);
306
+ toolConfirmation = JSON.parse(
307
+ functionResponse.response["response"]
308
+ );
277
309
  } else if (functionResponse.response) {
278
310
  toolConfirmation = new ToolConfirmation({
279
311
  hint: functionResponse.response["hint"],
@@ -337,8 +369,12 @@ class RequestConfirmationLlmRequestProcessor extends BaseLlmRequestProcessor {
337
369
  if (Object.keys(toolsToResumeWithConfirmation).length === 0) {
338
370
  continue;
339
371
  }
340
- const toolsList = yield new __await(agent.canonicalTools(new ReadonlyContext(invocationContext)));
341
- const toolsDict = Object.fromEntries(toolsList.map((tool) => [tool.name, tool]));
372
+ const toolsList = yield new __await(agent.canonicalTools(
373
+ new ReadonlyContext(invocationContext)
374
+ ));
375
+ const toolsDict = Object.fromEntries(
376
+ toolsList.map((tool) => [tool.name, tool])
377
+ );
342
378
  const functionResponseEvent = yield new __await(handleFunctionCallList({
343
379
  invocationContext,
344
380
  functionCalls: Object.values(toolsToResumeWithArgs),
@@ -381,7 +417,7 @@ class CodeExecutionRequestProcessor extends BaseLlmRequestProcessor {
381
417
  throw error[0];
382
418
  }
383
419
  }
384
- if (!(invocationContext.agent.codeExecutor instanceof BaseCodeExecutor)) {
420
+ if (!isBaseCodeExecutor(invocationContext.agent.codeExecutor)) {
385
421
  return;
386
422
  }
387
423
  for (const content of llmRequest.contents) {
@@ -416,7 +452,10 @@ class CodeExecutionResponseProcessor {
416
452
  return;
417
453
  }
418
454
  try {
419
- for (var iter = __forAwait(runPostProcessor(invocationContext, llmResponse)), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
455
+ for (var iter = __forAwait(runPostProcessor(
456
+ invocationContext,
457
+ llmResponse
458
+ )), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
420
459
  const event = temp.value;
421
460
  yield event;
422
461
  }
@@ -437,27 +476,36 @@ const responseProcessor = new CodeExecutionResponseProcessor();
437
476
  function runPreProcessor(invocationContext, llmRequest) {
438
477
  return __asyncGenerator(this, null, function* () {
439
478
  const agent = invocationContext.agent;
440
- if (!(agent instanceof LlmAgent)) {
479
+ if (!isLlmAgent(agent)) {
441
480
  return;
442
481
  }
443
482
  const codeExecutor = agent.codeExecutor;
444
- if (!codeExecutor || !(codeExecutor instanceof BaseCodeExecutor)) {
483
+ if (!codeExecutor || !isBaseCodeExecutor(codeExecutor)) {
445
484
  return;
446
485
  }
447
- if (codeExecutor instanceof BuiltInCodeExecutor) {
486
+ if (isBuiltInCodeExecutor(codeExecutor)) {
448
487
  codeExecutor.processLlmRequest(llmRequest);
449
488
  return;
450
489
  }
451
490
  if (!codeExecutor.optimizeDataFile) {
452
491
  return;
453
492
  }
454
- const codeExecutorContext = new CodeExecutorContext(new State(invocationContext.session.state));
493
+ const codeExecutorContext = new CodeExecutorContext(
494
+ new State(invocationContext.session.state)
495
+ );
455
496
  if (codeExecutorContext.getErrorCount(invocationContext.invocationId) >= codeExecutor.errorRetryAttempts) {
456
497
  return;
457
498
  }
458
- const allInputFiles = extractAndReplaceInlineFiles(codeExecutorContext, llmRequest);
459
- const processedFileNames = new Set(codeExecutorContext.getProcessedFileNames());
460
- const filesToProcess = allInputFiles.filter((f) => !processedFileNames.has(f.name));
499
+ const allInputFiles = extractAndReplaceInlineFiles(
500
+ codeExecutorContext,
501
+ llmRequest
502
+ );
503
+ const processedFileNames = new Set(
504
+ codeExecutorContext.getProcessedFileNames()
505
+ );
506
+ const filesToProcess = allInputFiles.filter(
507
+ (f) => !processedFileNames.has(f.name)
508
+ );
461
509
  for (const file of filesToProcess) {
462
510
  const codeStr = getDataFilePreprocessingCode(file);
463
511
  if (!codeStr) {
@@ -477,7 +525,10 @@ function runPreProcessor(invocationContext, llmRequest) {
477
525
  branch: invocationContext.branch,
478
526
  content: codeContent
479
527
  });
480
- const executionId = getOrSetExecutionId(invocationContext, codeExecutorContext);
528
+ const executionId = getOrSetExecutionId(
529
+ invocationContext,
530
+ codeExecutorContext
531
+ );
481
532
  const codeExecutionResult = yield new __await(codeExecutor.executeCode({
482
533
  invocationContext,
483
534
  codeExecutionInput: {
@@ -506,20 +557,22 @@ function runPreProcessor(invocationContext, llmRequest) {
506
557
  function runPostProcessor(invocationContext, llmResponse) {
507
558
  return __asyncGenerator(this, null, function* () {
508
559
  const agent = invocationContext.agent;
509
- if (!(agent instanceof LlmAgent)) {
560
+ if (!isLlmAgent(agent)) {
510
561
  return;
511
562
  }
512
563
  const codeExecutor = agent.codeExecutor;
513
- if (!codeExecutor || !(codeExecutor instanceof BaseCodeExecutor)) {
564
+ if (!codeExecutor || !isBaseCodeExecutor(codeExecutor)) {
514
565
  return;
515
566
  }
516
567
  if (!llmResponse || !llmResponse.content) {
517
568
  return;
518
569
  }
519
- if (codeExecutor instanceof BuiltInCodeExecutor) {
570
+ if (isBuiltInCodeExecutor(codeExecutor)) {
520
571
  return;
521
572
  }
522
- const codeExecutorContext = new CodeExecutorContext(new State(invocationContext.session.state));
573
+ const codeExecutorContext = new CodeExecutorContext(
574
+ new State(invocationContext.session.state)
575
+ );
523
576
  if (codeExecutorContext.getErrorCount(invocationContext.invocationId) >= codeExecutor.errorRetryAttempts) {
524
577
  return;
525
578
  }
@@ -537,7 +590,10 @@ function runPostProcessor(invocationContext, llmResponse) {
537
590
  branch: invocationContext.branch,
538
591
  content: responseContent
539
592
  });
540
- const executionId = getOrSetExecutionId(invocationContext, codeExecutorContext);
593
+ const executionId = getOrSetExecutionId(
594
+ invocationContext,
595
+ codeExecutorContext
596
+ );
541
597
  const codeExecutionResult = yield new __await(codeExecutor.executeCode({
542
598
  invocationContext,
543
599
  codeExecutionInput: {
@@ -561,7 +617,7 @@ function runPostProcessor(invocationContext, llmResponse) {
561
617
  });
562
618
  }
563
619
  function extractAndReplaceInlineFiles(codeExecutorContext, llmRequest) {
564
- var _a;
620
+ var _a2;
565
621
  const allInputFiles = codeExecutorContext.getInputFiles();
566
622
  const savedFileNames = new Set(allInputFiles.map((f) => f.name));
567
623
  for (let i = 0; i < llmRequest.contents.length; i++) {
@@ -571,7 +627,7 @@ function extractAndReplaceInlineFiles(codeExecutorContext, llmRequest) {
571
627
  }
572
628
  for (let j = 0; j < content.parts.length; j++) {
573
629
  const part = content.parts[j];
574
- const mimeType = (_a = part.inlineData) == null ? void 0 : _a.mimeType;
630
+ const mimeType = (_a2 = part.inlineData) == null ? void 0 : _a2.mimeType;
575
631
  if (!mimeType || !part.inlineData || !DATA_FILE_UTIL_MAP[mimeType]) {
576
632
  continue;
577
633
  }
@@ -591,9 +647,9 @@ function extractAndReplaceInlineFiles(codeExecutorContext, llmRequest) {
591
647
  return allInputFiles;
592
648
  }
593
649
  function getOrSetExecutionId(invocationContext, codeExecutorContext) {
594
- var _a;
650
+ var _a2;
595
651
  const agent = invocationContext.agent;
596
- if (!(agent instanceof LlmAgent) || !((_a = agent.codeExecutor) == null ? void 0 : _a.stateful)) {
652
+ if (!isLlmAgent(agent) || !((_a2 = agent.codeExecutor) == null ? void 0 : _a2.stateful)) {
597
653
  return void 0;
598
654
  }
599
655
  let executionId = codeExecutorContext.getExecutionId();
@@ -611,7 +667,9 @@ async function postProcessCodeExecutionResult(invocationContext, codeExecutorCon
611
667
  role: "model",
612
668
  parts: [buildCodeExecutionResultPart(codeExecutionResult)]
613
669
  };
614
- const eventActions = createEventActions({ stateDelta: codeExecutorContext.getStateDelta() });
670
+ const eventActions = createEventActions({
671
+ stateDelta: codeExecutorContext.getStateDelta()
672
+ });
615
673
  if (codeExecutionResult.stderr) {
616
674
  codeExecutorContext.incrementErrorCount(invocationContext.invocationId);
617
675
  } else {
@@ -650,20 +708,23 @@ function getDataFilePreprocessingCode(file) {
650
708
  return void 0;
651
709
  }
652
710
  const varName = getNormalizedFileName(file.name);
653
- const loaderCode = DATA_FILE_UTIL_MAP[file.mimeType].loaderCodeTemplate.replace(
654
- "{filename}",
655
- file.name
656
- );
711
+ const loaderCode = DATA_FILE_UTIL_MAP[file.mimeType].loaderCodeTemplate.replace("{filename}", file.name);
657
712
  return "\n".concat(DATA_FILE_HELPER_LIB, "\n\n# Load the dataframe.\n").concat(varName, " = ").concat(loaderCode, "\n\n# Use `explore_df` to guide my analysis.\nexplore_df(").concat(varName, ")\n");
658
713
  }
659
714
  const CODE_EXECUTION_REQUEST_PROCESSOR = new CodeExecutionRequestProcessor();
660
- class LlmAgent extends BaseAgent {
715
+ const LLM_AGENT_SIGNATURE_SYMBOL = Symbol.for("google.adk.llmAgent");
716
+ function isLlmAgent(obj) {
717
+ return typeof obj === "object" && obj !== null && LLM_AGENT_SIGNATURE_SYMBOL in obj && obj[LLM_AGENT_SIGNATURE_SYMBOL] === true;
718
+ }
719
+ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
661
720
  constructor(config) {
662
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
721
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
663
722
  super(config);
723
+ /** A unique symbol to identify ADK LLM agent class. */
724
+ this[_a] = true;
664
725
  this.model = config.model;
665
- this.instruction = (_a = config.instruction) != null ? _a : "";
666
- this.globalInstruction = (_b = config.globalInstruction) != null ? _b : "";
726
+ this.instruction = (_a2 = config.instruction) != null ? _a2 : "";
727
+ this.globalInstruction = (_b2 = config.globalInstruction) != null ? _b2 : "";
667
728
  this.tools = (_c = config.tools) != null ? _c : [];
668
729
  this.generateContentConfig = config.generateContentConfig;
669
730
  this.disallowTransferToParent = (_d = config.disallowTransferToParent) != null ? _d : false;
@@ -741,7 +802,7 @@ class LlmAgent extends BaseAgent {
741
802
  }
742
803
  let ancestorAgent = this.parentAgent;
743
804
  while (ancestorAgent) {
744
- if (ancestorAgent instanceof LlmAgent) {
805
+ if (isLlmAgent(ancestorAgent)) {
745
806
  return ancestorAgent.canonicalModel;
746
807
  }
747
808
  ancestorAgent = ancestorAgent.parentAgent;
@@ -749,12 +810,12 @@ class LlmAgent extends BaseAgent {
749
810
  throw new Error("No model found for ".concat(this.name, "."));
750
811
  }
751
812
  /**
752
- * The resolved self.instruction field to construct instruction for this
813
+ * The resolved instruction field to construct instruction for this
753
814
  * agent.
754
815
  *
755
816
  * This method is only for use by Agent Development Kit.
756
817
  * @param context The context to retrieve the session state.
757
- * @returns The resolved self.instruction field.
818
+ * @returns The resolved instruction field.
758
819
  */
759
820
  async canonicalInstruction(context) {
760
821
  if (typeof this.instruction === "string") {
@@ -766,11 +827,11 @@ class LlmAgent extends BaseAgent {
766
827
  };
767
828
  }
768
829
  /**
769
- * The resolved self.instruction field to construct global instruction.
830
+ * The resolved globalInstruction field to construct global instruction.
770
831
  *
771
832
  * This method is only for use by Agent Development Kit.
772
833
  * @param context The context to retrieve the session state.
773
- * @returns The resolved self.global_instruction field.
834
+ * @returns The resolved globalInstruction field.
774
835
  */
775
836
  async canonicalGlobalInstruction(context) {
776
837
  if (typeof this.globalInstruction === "string") {
@@ -782,7 +843,7 @@ class LlmAgent extends BaseAgent {
782
843
  };
783
844
  }
784
845
  /**
785
- * The resolved self.tools field as a list of BaseTool based on the context.
846
+ * The resolved tools field as a list of BaseTool based on the context.
786
847
  *
787
848
  * This method is only for use by Agent Development Kit.
788
849
  */
@@ -810,7 +871,7 @@ class LlmAgent extends BaseAgent {
810
871
  return [callback];
811
872
  }
812
873
  /**
813
- * The resolved self.before_model_callback field as a list of
874
+ * The resolved beforeModelCallback field as a list of
814
875
  * SingleBeforeModelCallback.
815
876
  *
816
877
  * This method is only for use by Agent Development Kit.
@@ -819,7 +880,7 @@ class LlmAgent extends BaseAgent {
819
880
  return LlmAgent.normalizeCallbackArray(this.beforeModelCallback);
820
881
  }
821
882
  /**
822
- * The resolved self.after_model_callback field as a list of
883
+ * The resolved afterModelCallback field as a list of
823
884
  * SingleAfterModelCallback.
824
885
  *
825
886
  * This method is only for use by Agent Development Kit.
@@ -828,7 +889,7 @@ class LlmAgent extends BaseAgent {
828
889
  return LlmAgent.normalizeCallbackArray(this.afterModelCallback);
829
890
  }
830
891
  /**
831
- * The resolved self.before_tool_callback field as a list of
892
+ * The resolved beforeToolCallback field as a list of
832
893
  * BeforeToolCallback.
833
894
  *
834
895
  * This method is only for use by Agent Development Kit.
@@ -837,7 +898,7 @@ class LlmAgent extends BaseAgent {
837
898
  return LlmAgent.normalizeCallbackArray(this.beforeToolCallback);
838
899
  }
839
900
  /**
840
- * The resolved self.after_tool_callback field as a list of AfterToolCallback.
901
+ * The resolved afterToolCallback field as a list of AfterToolCallback.
841
902
  *
842
903
  * This method is only for use by Agent Development Kit.
843
904
  */
@@ -854,7 +915,7 @@ class LlmAgent extends BaseAgent {
854
915
  * @param event The event to process.
855
916
  */
856
917
  maybeSaveOutputToState(event) {
857
- var _a, _b;
918
+ var _a2, _b2;
858
919
  if (event.author !== this.name) {
859
920
  logger.debug(
860
921
  "Skipping output save for agent ".concat(this.name, ": event authored by ").concat(event.author)
@@ -873,7 +934,7 @@ class LlmAgent extends BaseAgent {
873
934
  );
874
935
  return;
875
936
  }
876
- if (!((_b = (_a = event.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.length)) {
937
+ if (!((_b2 = (_a2 = event.content) == null ? void 0 : _a2.parts) == null ? void 0 : _b2.length)) {
877
938
  logger.debug(
878
939
  "Skipping output save for agent ".concat(this.name, ": event content is empty")
879
940
  );
@@ -965,7 +1026,10 @@ class LlmAgent extends BaseAgent {
965
1026
  };
966
1027
  for (const processor of this.requestProcessors) {
967
1028
  try {
968
- for (var iter = __forAwait(processor.runAsync(invocationContext, llmRequest)), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
1029
+ for (var iter = __forAwait(processor.runAsync(
1030
+ invocationContext,
1031
+ llmRequest
1032
+ )), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
969
1033
  const event = temp.value;
970
1034
  yield event;
971
1035
  }
@@ -1042,10 +1106,13 @@ class LlmAgent extends BaseAgent {
1042
1106
  }
1043
1107
  postprocess(invocationContext, llmRequest, llmResponse, modelResponseEvent) {
1044
1108
  return __asyncGenerator(this, null, function* () {
1045
- var _a;
1109
+ var _a2;
1046
1110
  for (const processor of this.responseProcessors) {
1047
1111
  try {
1048
- for (var iter = __forAwait(processor.runAsync(invocationContext, llmResponse)), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
1112
+ for (var iter = __forAwait(processor.runAsync(
1113
+ invocationContext,
1114
+ llmResponse
1115
+ )), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
1049
1116
  const event = temp.value;
1050
1117
  yield event;
1051
1118
  }
@@ -1074,7 +1141,7 @@ class LlmAgent extends BaseAgent {
1074
1141
  }
1075
1142
  }
1076
1143
  yield mergedEvent;
1077
- if (!((_a = getFunctionCalls(mergedEvent)) == null ? void 0 : _a.length)) {
1144
+ if (!((_a2 = getFunctionCalls(mergedEvent)) == null ? void 0 : _a2.length)) {
1078
1145
  return;
1079
1146
  }
1080
1147
  const functionResponseEvent = yield new __await(handleFunctionCallsAsync({
@@ -1087,7 +1154,10 @@ class LlmAgent extends BaseAgent {
1087
1154
  if (!functionResponseEvent) {
1088
1155
  return;
1089
1156
  }
1090
- const authEvent = generateAuthEvent(invocationContext, functionResponseEvent);
1157
+ const authEvent = generateAuthEvent(
1158
+ invocationContext,
1159
+ functionResponseEvent
1160
+ );
1091
1161
  if (authEvent) {
1092
1162
  yield authEvent;
1093
1163
  }
@@ -1143,7 +1213,7 @@ class LlmAgent extends BaseAgent {
1143
1213
  }
1144
1214
  callLlmAsync(invocationContext, llmRequest, modelResponseEvent) {
1145
1215
  return __asyncGenerator(this, null, function* () {
1146
- var _a, _b, _c, _d, _e;
1216
+ var _a2, _b2, _c, _d, _e;
1147
1217
  const beforeModelResponse = yield new __await(this.handleBeforeModelCallback(
1148
1218
  invocationContext,
1149
1219
  llmRequest,
@@ -1153,8 +1223,8 @@ class LlmAgent extends BaseAgent {
1153
1223
  yield beforeModelResponse;
1154
1224
  return;
1155
1225
  }
1156
- (_a = llmRequest.config) != null ? _a : llmRequest.config = {};
1157
- (_c = (_b = llmRequest.config).labels) != null ? _c : _b.labels = {};
1226
+ (_a2 = llmRequest.config) != null ? _a2 : llmRequest.config = {};
1227
+ (_c = (_b2 = llmRequest.config).labels) != null ? _c : _b2.labels = {};
1158
1228
  if (!llmRequest.config.labels[ADK_AGENT_NAME_LABEL_KEY]) {
1159
1229
  llmRequest.config.labels[ADK_AGENT_NAME_LABEL_KEY] = this.name;
1160
1230
  }
@@ -1197,17 +1267,22 @@ class LlmAgent extends BaseAgent {
1197
1267
  });
1198
1268
  }
1199
1269
  async handleBeforeModelCallback(invocationContext, llmRequest, modelResponseEvent) {
1200
- const callbackContext = new CallbackContext(
1201
- { invocationContext, eventActions: modelResponseEvent.actions }
1202
- );
1203
- const beforeModelCallbackResponse = await invocationContext.pluginManager.runBeforeModelCallback(
1204
- { callbackContext, llmRequest }
1205
- );
1270
+ const callbackContext = new CallbackContext({
1271
+ invocationContext,
1272
+ eventActions: modelResponseEvent.actions
1273
+ });
1274
+ const beforeModelCallbackResponse = await invocationContext.pluginManager.runBeforeModelCallback({
1275
+ callbackContext,
1276
+ llmRequest
1277
+ });
1206
1278
  if (beforeModelCallbackResponse) {
1207
1279
  return beforeModelCallbackResponse;
1208
1280
  }
1209
1281
  for (const callback of this.canonicalBeforeModelCallbacks) {
1210
- const callbackResponse = await callback({ context: callbackContext, request: llmRequest });
1282
+ const callbackResponse = await callback({
1283
+ context: callbackContext,
1284
+ request: llmRequest
1285
+ });
1211
1286
  if (callbackResponse) {
1212
1287
  return callbackResponse;
1213
1288
  }
@@ -1215,17 +1290,22 @@ class LlmAgent extends BaseAgent {
1215
1290
  return void 0;
1216
1291
  }
1217
1292
  async handleAfterModelCallback(invocationContext, llmResponse, modelResponseEvent) {
1218
- const callbackContext = new CallbackContext(
1219
- { invocationContext, eventActions: modelResponseEvent.actions }
1220
- );
1221
- const afterModelCallbackResponse = await invocationContext.pluginManager.runAfterModelCallback(
1222
- { callbackContext, llmResponse }
1223
- );
1293
+ const callbackContext = new CallbackContext({
1294
+ invocationContext,
1295
+ eventActions: modelResponseEvent.actions
1296
+ });
1297
+ const afterModelCallbackResponse = await invocationContext.pluginManager.runAfterModelCallback({
1298
+ callbackContext,
1299
+ llmResponse
1300
+ });
1224
1301
  if (afterModelCallbackResponse) {
1225
1302
  return afterModelCallbackResponse;
1226
1303
  }
1227
1304
  for (const callback of this.canonicalAfterModelCallbacks) {
1228
- const callbackResponse = await callback({ context: callbackContext, response: llmResponse });
1305
+ const callbackResponse = await callback({
1306
+ context: callbackContext,
1307
+ response: llmResponse
1308
+ });
1229
1309
  if (callbackResponse) {
1230
1310
  return callbackResponse;
1231
1311
  }
@@ -1251,9 +1331,10 @@ class LlmAgent extends BaseAgent {
1251
1331
  }
1252
1332
  }
1253
1333
  } catch (modelError) {
1254
- const callbackContext = new CallbackContext(
1255
- { invocationContext, eventActions: modelResponseEvent.actions }
1256
- );
1334
+ const callbackContext = new CallbackContext({
1335
+ invocationContext,
1336
+ eventActions: modelResponseEvent.actions
1337
+ });
1257
1338
  if (modelError instanceof Error) {
1258
1339
  const onModelErrorCallbackResponse = yield new __await(invocationContext.pluginManager.runOnModelErrorCallback({
1259
1340
  callbackContext,
@@ -1286,5 +1367,6 @@ class LlmAgent extends BaseAgent {
1286
1367
  export {
1287
1368
  LlmAgent,
1288
1369
  REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR,
1370
+ isLlmAgent,
1289
1371
  responseProcessor
1290
1372
  };
@@ -20,12 +20,21 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
20
20
  * Copyright 2025 Google LLC
21
21
  * SPDX-License-Identifier: Apache-2.0
22
22
  */
23
+ var _a, _b;
23
24
  import { BaseAgent } from "./base_agent.js";
24
- class LoopAgent extends BaseAgent {
25
+ const LOOP_AGENT_SIGNATURE_SYMBOL = Symbol.for("google.adk.loopAgent");
26
+ function isLoopAgent(obj) {
27
+ return typeof obj === "object" && obj !== null && LOOP_AGENT_SIGNATURE_SYMBOL in obj && obj[LOOP_AGENT_SIGNATURE_SYMBOL] === true;
28
+ }
29
+ class LoopAgent extends (_b = BaseAgent, _a = LOOP_AGENT_SIGNATURE_SYMBOL, _b) {
25
30
  constructor(config) {
26
- var _a;
31
+ var _a2;
27
32
  super(config);
28
- this.maxIterations = (_a = config.maxIterations) != null ? _a : Number.MAX_SAFE_INTEGER;
33
+ /**
34
+ * A unique symbol to identify ADK loop agent class.
35
+ */
36
+ this[_a] = true;
37
+ this.maxIterations = (_a2 = config.maxIterations) != null ? _a2 : Number.MAX_SAFE_INTEGER;
29
38
  }
30
39
  runAsyncImpl(context) {
31
40
  return __asyncGenerator(this, null, function* () {
@@ -67,5 +76,6 @@ class LoopAgent extends BaseAgent {
67
76
  }
68
77
  }
69
78
  export {
70
- LoopAgent
79
+ LoopAgent,
80
+ isLoopAgent
71
81
  };
@@ -20,9 +20,21 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
20
20
  * Copyright 2025 Google LLC
21
21
  * SPDX-License-Identifier: Apache-2.0
22
22
  */
23
+ var _a, _b;
23
24
  import { BaseAgent } from "./base_agent.js";
24
25
  import { InvocationContext } from "./invocation_context.js";
25
- class ParallelAgent extends BaseAgent {
26
+ const PARALLEL_AGENT_SIGNATURE_SYMBOL = Symbol.for("google.adk.parallelAgent");
27
+ function isParallelAgent(obj) {
28
+ return typeof obj === "object" && obj !== null && PARALLEL_AGENT_SIGNATURE_SYMBOL in obj && obj[PARALLEL_AGENT_SIGNATURE_SYMBOL] === true;
29
+ }
30
+ class ParallelAgent extends (_b = BaseAgent, _a = PARALLEL_AGENT_SIGNATURE_SYMBOL, _b) {
31
+ constructor() {
32
+ super(...arguments);
33
+ /**
34
+ * A unique symbol to identify ADK parallel agent class.
35
+ */
36
+ this[_a] = true;
37
+ }
26
38
  runAsyncImpl(context) {
27
39
  return __asyncGenerator(this, null, function* () {
28
40
  const agentRuns = this.subAgents.map(
@@ -79,5 +91,6 @@ function mergeAgentRuns(agentRuns) {
79
91
  });
80
92
  }
81
93
  export {
82
- ParallelAgent
94
+ ParallelAgent,
95
+ isParallelAgent
83
96
  };
@@ -30,7 +30,10 @@ class ReadonlyContext {
30
30
  * The state of the current session.
31
31
  */
32
32
  get state() {
33
- return new State(this.invocationContext.session.state, {});
33
+ return new State(
34
+ this.invocationContext.session.state,
35
+ {}
36
+ );
34
37
  }
35
38
  }
36
39
  export {