@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
@@ -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(config.beforeAgentCallback);
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(`Agent "${subAgent.name}" already has a parent agent, current parent: "${subAgent.parentAgent.name}", trying to add: "${this.name}"`);
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(`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.`);
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(`Max number of llm calls limit of ${runConfig.maxLlmCalls} exceeded`);
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 _a;
74
+ var _a2;
73
75
  const agent = invocationContext.agent;
74
- if (!(agent instanceof LlmAgent)) {
76
+ if (!isLlmAgent(agent)) {
75
77
  return;
76
78
  }
77
79
  llmRequest.model = agent.canonicalModel.model;
78
- llmRequest.config = { ...(_a = agent.generateContentConfig) != null ? _a : {} };
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 instanceof LlmAgent && rootAgent.globalInstruction) {
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 instanceof LlmAgent)) {
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 instanceof LlmAgent)) {
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 instanceof LlmAgent)) {
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(functionResponse.response["response"]);
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(new import_readonly_context.ReadonlyContext(invocationContext));
347
- const toolsDict = Object.fromEntries(toolsList.map((tool) => [tool.name, tool]));
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 instanceof import_base_code_executor.BaseCodeExecutor)) {
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(invocationContext, llmResponse)) {
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 instanceof LlmAgent)) {
464
+ if (!isLlmAgent(agent)) {
454
465
  return;
455
466
  }
456
467
  const codeExecutor = agent.codeExecutor;
457
- if (!codeExecutor || !(codeExecutor instanceof import_base_code_executor.BaseCodeExecutor)) {
468
+ if (!codeExecutor || !(0, import_base_code_executor.isBaseCodeExecutor)(codeExecutor)) {
458
469
  return;
459
470
  }
460
- if (codeExecutor instanceof import_built_in_code_executor.BuiltInCodeExecutor) {
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(new import_state.State(invocationContext.session.state));
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(codeExecutorContext, llmRequest);
472
- const processedFileNames = new Set(codeExecutorContext.getProcessedFileNames());
473
- const filesToProcess = allInputFiles.filter((f) => !processedFileNames.has(f.name));
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(invocationContext, codeExecutorContext);
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 instanceof LlmAgent)) {
543
+ if (!isLlmAgent(agent)) {
521
544
  return;
522
545
  }
523
546
  const codeExecutor = agent.codeExecutor;
524
- if (!codeExecutor || !(codeExecutor instanceof import_base_code_executor.BaseCodeExecutor)) {
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 (codeExecutor instanceof import_built_in_code_executor.BuiltInCodeExecutor) {
553
+ if ((0, import_built_in_code_executor.isBuiltInCodeExecutor)(codeExecutor)) {
531
554
  return;
532
555
  }
533
- const codeExecutorContext = new import_code_executor_context.CodeExecutorContext(new import_state.State(invocationContext.session.state));
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(invocationContext, codeExecutorContext);
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 _a;
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 = (_a = part.inlineData) == null ? void 0 : _a.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 _a;
634
+ var _a2;
607
635
  const agent = invocationContext.agent;
608
- if (!(agent instanceof LlmAgent) || !((_a = agent.codeExecutor) == null ? void 0 : _a.stateful)) {
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)({ stateDelta: codeExecutorContext.getStateDelta() });
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
- class LlmAgent extends import_base_agent.BaseAgent {
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 _a, _b, _c, _d, _e, _f, _g, _h, _i;
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 = (_a = config.instruction) != null ? _a : "";
686
- this.globalInstruction = (_b = config.globalInstruction) != null ? _b : "";
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 instanceof LlmAgent) {
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 self.instruction field to construct instruction for this
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 self.instruction field.
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 self.instruction field to construct global instruction.
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 self.global_instruction field.
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 self.tools field as a list of BaseTool based on the context.
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 self.before_model_callback field as a list of
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 self.after_model_callback field as a list of
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 self.before_tool_callback field as a list of
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 self.after_tool_callback field as a list of AfterToolCallback.
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 _a, _b;
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 (!((_b = (_a = event.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.length)) {
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(invocationContext, llmRequest)) {
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 _a;
1032
+ var _a2;
997
1033
  for (const processor of this.responseProcessors) {
998
- for await (const event of processor.runAsync(invocationContext, llmResponse)) {
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 (!((_a = (0, import_event.getFunctionCalls)(mergedEvent)) == null ? void 0 : _a.length)) {
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)(invocationContext, functionResponseEvent);
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 _a, _b, _c, _d, _e;
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
- (_a = llmRequest.config) != null ? _a : llmRequest.config = {};
1085
- (_c = (_b = llmRequest.config).labels) != null ? _c : _b.labels = {};
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
- { invocationContext, eventActions: modelResponseEvent.actions }
1117
- );
1118
- const beforeModelCallbackResponse = await invocationContext.pluginManager.runBeforeModelCallback(
1119
- { callbackContext, llmRequest }
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({ context: callbackContext, request: llmRequest });
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
- { invocationContext, eventActions: modelResponseEvent.actions }
1135
- );
1136
- const afterModelCallbackResponse = await invocationContext.pluginManager.runAfterModelCallback(
1137
- { callbackContext, llmResponse }
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({ context: callbackContext, response: llmResponse });
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
- { invocationContext, eventActions: modelResponseEvent.actions }
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
- class LoopAgent extends import_base_agent.BaseAgent {
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 _a;
44
+ var _a2;
39
45
  super(config);
40
- this.maxIterations = (_a = config.maxIterations) != null ? _a : Number.MAX_SAFE_INTEGER;
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
- class ParallelAgent extends import_base_agent.BaseAgent {
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(this.invocationContext.session.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: