@google/adk 0.2.3 → 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 (107) hide show
  1. package/dist/cjs/agents/base_agent.js +9 -3
  2. package/dist/cjs/agents/content_processor_utils.js +2 -12
  3. package/dist/cjs/agents/functions.js +3 -13
  4. package/dist/cjs/agents/invocation_context.js +3 -1
  5. package/dist/cjs/agents/llm_agent.js +132 -88
  6. package/dist/cjs/agents/loop_agent.js +16 -5
  7. package/dist/cjs/agents/parallel_agent.js +17 -3
  8. package/dist/cjs/agents/readonly_context.js +4 -1
  9. package/dist/cjs/agents/sequential_agent.js +34 -12
  10. package/dist/cjs/code_executors/base_code_executor.js +12 -2
  11. package/dist/cjs/code_executors/built_in_code_executor.js +15 -3
  12. package/dist/cjs/code_executors/code_execution_utils.js +2 -12
  13. package/dist/cjs/code_executors/code_executor_context.js +2 -12
  14. package/dist/cjs/common.js +41 -0
  15. package/dist/cjs/examples/base_example_provider.js +18 -2
  16. package/dist/cjs/examples/example_util.js +1 -1
  17. package/dist/cjs/index.js +11 -11
  18. package/dist/cjs/index.js.map +4 -4
  19. package/dist/cjs/plugins/base_plugin.js +59 -49
  20. package/dist/cjs/plugins/security_plugin.js +4 -1
  21. package/dist/cjs/runner/runner.js +38 -27
  22. package/dist/cjs/sessions/in_memory_session_service.js +3 -13
  23. package/dist/cjs/tools/agent_tool.js +18 -9
  24. package/dist/cjs/tools/base_tool.js +16 -6
  25. package/dist/cjs/tools/function_tool.js +14 -5
  26. package/dist/cjs/tools/google_search_tool.js +8 -3
  27. package/dist/cjs/tools/tool_context.js +4 -9
  28. package/dist/cjs/utils/gemini_schema_util.js +1 -0
  29. package/dist/cjs/version.js +1 -1
  30. package/dist/esm/agents/base_agent.js +9 -3
  31. package/dist/esm/agents/content_processor_utils.js +1 -1
  32. package/dist/esm/agents/functions.js +1 -1
  33. package/dist/esm/agents/invocation_context.js +3 -1
  34. package/dist/esm/agents/llm_agent.js +166 -84
  35. package/dist/esm/agents/loop_agent.js +14 -4
  36. package/dist/esm/agents/parallel_agent.js +15 -2
  37. package/dist/esm/agents/readonly_context.js +4 -1
  38. package/dist/esm/agents/sequential_agent.js +33 -12
  39. package/dist/esm/code_executors/base_code_executor.js +10 -1
  40. package/dist/esm/code_executors/built_in_code_executor.js +13 -2
  41. package/dist/esm/code_executors/code_execution_utils.js +1 -1
  42. package/dist/esm/code_executors/code_executor_context.js +1 -1
  43. package/dist/esm/common.js +53 -10
  44. package/dist/esm/examples/base_example_provider.js +16 -1
  45. package/dist/esm/examples/example_util.js +4 -2
  46. package/dist/esm/index.js +11 -11
  47. package/dist/esm/index.js.map +4 -4
  48. package/dist/esm/plugins/base_plugin.js +59 -49
  49. package/dist/esm/plugins/security_plugin.js +4 -1
  50. package/dist/esm/runner/runner.js +47 -30
  51. package/dist/esm/sessions/in_memory_session_service.js +1 -1
  52. package/dist/esm/tools/agent_tool.js +17 -9
  53. package/dist/esm/tools/base_tool.js +14 -5
  54. package/dist/esm/tools/function_tool.js +13 -7
  55. package/dist/esm/tools/google_search_tool.js +9 -3
  56. package/dist/esm/tools/tool_context.js +4 -9
  57. package/dist/esm/utils/gemini_schema_util.js +1 -0
  58. package/dist/esm/version.js +1 -1
  59. package/dist/types/agents/base_agent.d.ts +14 -3
  60. package/dist/types/agents/invocation_context.d.ts +4 -2
  61. package/dist/types/agents/llm_agent.d.ts +42 -30
  62. package/dist/types/agents/loop_agent.d.ts +16 -0
  63. package/dist/types/agents/parallel_agent.d.ts +16 -0
  64. package/dist/types/agents/sequential_agent.d.ts +17 -1
  65. package/dist/types/auth/auth_schemes.d.ts +5 -2
  66. package/dist/types/code_executors/base_code_executor.d.ts +14 -0
  67. package/dist/types/code_executors/built_in_code_executor.d.ts +19 -0
  68. package/dist/types/common.d.ts +38 -14
  69. package/dist/types/examples/base_example_provider.d.ts +16 -0
  70. package/dist/types/plugins/base_plugin.d.ts +50 -40
  71. package/dist/types/runner/runner.d.ts +17 -9
  72. package/dist/types/tools/agent_tool.d.ts +14 -0
  73. package/dist/types/tools/base_tool.d.ts +14 -0
  74. package/dist/types/tools/function_tool.d.ts +14 -1
  75. package/dist/types/tools/google_search_tool.d.ts +3 -4
  76. package/dist/types/tools/tool_context.d.ts +1 -1
  77. package/dist/types/version.d.ts +1 -1
  78. package/dist/web/agents/base_agent.js +9 -3
  79. package/dist/web/agents/content_processor_utils.js +1 -1
  80. package/dist/web/agents/functions.js +1 -1
  81. package/dist/web/agents/invocation_context.js +3 -1
  82. package/dist/web/agents/llm_agent.js +166 -84
  83. package/dist/web/agents/loop_agent.js +14 -4
  84. package/dist/web/agents/parallel_agent.js +15 -2
  85. package/dist/web/agents/readonly_context.js +4 -1
  86. package/dist/web/agents/sequential_agent.js +33 -12
  87. package/dist/web/code_executors/base_code_executor.js +10 -1
  88. package/dist/web/code_executors/built_in_code_executor.js +13 -2
  89. package/dist/web/code_executors/code_execution_utils.js +1 -1
  90. package/dist/web/code_executors/code_executor_context.js +1 -1
  91. package/dist/web/common.js +53 -10
  92. package/dist/web/examples/base_example_provider.js +16 -1
  93. package/dist/web/examples/example_util.js +4 -2
  94. package/dist/web/index.js +1 -1
  95. package/dist/web/index.js.map +4 -4
  96. package/dist/web/plugins/base_plugin.js +59 -49
  97. package/dist/web/plugins/security_plugin.js +4 -1
  98. package/dist/web/runner/runner.js +48 -31
  99. package/dist/web/sessions/in_memory_session_service.js +1 -1
  100. package/dist/web/tools/agent_tool.js +17 -9
  101. package/dist/web/tools/base_tool.js +14 -5
  102. package/dist/web/tools/function_tool.js +13 -7
  103. package/dist/web/tools/google_search_tool.js +9 -3
  104. package/dist/web/tools/tool_context.js +4 -9
  105. package/dist/web/utils/gemini_schema_util.js +1 -0
  106. package/dist/web/version.js +1 -1
  107. package/package.json +3 -3
@@ -5,11 +5,9 @@
5
5
  */
6
6
 
7
7
  "use strict";
8
- var __create = Object.create;
9
8
  var __defProp = Object.defineProperty;
10
9
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
10
  var __getOwnPropNames = Object.getOwnPropertyNames;
12
- var __getProtoOf = Object.getPrototypeOf;
13
11
  var __hasOwnProp = Object.prototype.hasOwnProperty;
14
12
  var __export = (target, all) => {
15
13
  for (var name in all)
@@ -23,23 +21,16 @@ var __copyProps = (to, from, except, desc) => {
23
21
  }
24
22
  return to;
25
23
  };
26
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27
- // If the importer is in node compatibility mode or this is not an ESM
28
- // file that has been converted to a CommonJS file using a Babel-
29
- // compatible transform (i.e. "__esModule" has not been set), then set
30
- // "default" to the CommonJS "module.exports" for node compatibility.
31
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
32
- mod
33
- ));
34
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
25
  var llm_agent_exports = {};
36
26
  __export(llm_agent_exports, {
37
27
  LlmAgent: () => LlmAgent,
38
28
  REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR: () => REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR,
29
+ isLlmAgent: () => isLlmAgent,
39
30
  responseProcessor: () => responseProcessor
40
31
  });
41
32
  module.exports = __toCommonJS(llm_agent_exports);
42
- var import_cloneDeep = __toESM(require("lodash-es/cloneDeep.js"), 1);
33
+ var import_lodash_es = require("lodash-es");
43
34
  var import_zod = require("zod");
44
35
  var import_base_code_executor = require("../code_executors/base_code_executor.js");
45
36
  var import_built_in_code_executor = require("../code_executors/built_in_code_executor.js");
@@ -70,6 +61,7 @@ var import_run_config = require("./run_config.js");
70
61
  * Copyright 2025 Google LLC
71
62
  * SPDX-License-Identifier: Apache-2.0
72
63
  */
64
+ var _a, _b;
73
65
  const ADK_AGENT_NAME_LABEL_KEY = "adk_agent_name";
74
66
  async function convertToolUnionToTools(toolUnion, context) {
75
67
  if (toolUnion instanceof import_base_tool.BaseTool) {
@@ -79,13 +71,13 @@ async function convertToolUnionToTools(toolUnion, context) {
79
71
  }
80
72
  class BasicLlmRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
81
73
  async *runAsync(invocationContext, llmRequest) {
82
- var _a;
74
+ var _a2;
83
75
  const agent = invocationContext.agent;
84
- if (!(agent instanceof LlmAgent)) {
76
+ if (!isLlmAgent(agent)) {
85
77
  return;
86
78
  }
87
79
  llmRequest.model = agent.canonicalModel.model;
88
- llmRequest.config = { ...(_a = agent.generateContentConfig) != null ? _a : {} };
80
+ llmRequest.config = { ...(_a2 = agent.generateContentConfig) != null ? _a2 : {} };
89
81
  if (agent.outputSchema) {
90
82
  (0, import_llm_request.setOutputSchema)(llmRequest, agent.outputSchema);
91
83
  }
@@ -122,7 +114,7 @@ class InstructionsLlmRequestProcessor extends import_base_llm_processor.BaseLlmR
122
114
  return;
123
115
  }
124
116
  const rootAgent = agent.rootAgent;
125
- if (rootAgent instanceof LlmAgent && rootAgent.globalInstruction) {
117
+ if (isLlmAgent(rootAgent) && rootAgent.globalInstruction) {
126
118
  const { instruction, requireStateInjection } = await rootAgent.canonicalGlobalInstruction(
127
119
  new import_readonly_context.ReadonlyContext(invocationContext)
128
120
  );
@@ -154,7 +146,7 @@ const INSTRUCTIONS_LLM_REQUEST_PROCESSOR = new InstructionsLlmRequestProcessor()
154
146
  class ContentRequestProcessor {
155
147
  async *runAsync(invocationContext, llmRequest) {
156
148
  const agent = invocationContext.agent;
157
- if (!agent || !(agent instanceof LlmAgent)) {
149
+ if (!agent || !isLlmAgent(agent)) {
158
150
  return;
159
151
  }
160
152
  if (agent.includeContents === "default") {
@@ -242,7 +234,7 @@ to your parent agent.
242
234
  getTransferTargets(agent) {
243
235
  const targets = [];
244
236
  targets.push(...agent.subAgents);
245
- if (!agent.parentAgent || !(agent.parentAgent instanceof LlmAgent)) {
237
+ if (!agent.parentAgent || !isLlmAgent(agent.parentAgent)) {
246
238
  return targets;
247
239
  }
248
240
  if (!agent.disallowTransferToParent) {
@@ -263,7 +255,7 @@ class RequestConfirmationLlmRequestProcessor extends import_base_llm_processor.B
263
255
  /** Handles tool confirmation information to build the LLM request. */
264
256
  async *runAsync(invocationContext, llmRequest) {
265
257
  const agent = invocationContext.agent;
266
- if (!(agent instanceof LlmAgent)) {
258
+ if (!isLlmAgent(agent)) {
267
259
  return;
268
260
  }
269
261
  const events = invocationContext.session.events;
@@ -289,7 +281,9 @@ class RequestConfirmationLlmRequestProcessor extends import_base_llm_processor.B
289
281
  foundConfirmation = true;
290
282
  let toolConfirmation = null;
291
283
  if (functionResponse.response && Object.keys(functionResponse.response).length === 1 && "response" in functionResponse.response) {
292
- toolConfirmation = JSON.parse(functionResponse.response["response"]);
284
+ toolConfirmation = JSON.parse(
285
+ functionResponse.response["response"]
286
+ );
293
287
  } else if (functionResponse.response) {
294
288
  toolConfirmation = new import_tool_confirmation.ToolConfirmation({
295
289
  hint: functionResponse.response["hint"],
@@ -353,8 +347,12 @@ class RequestConfirmationLlmRequestProcessor extends import_base_llm_processor.B
353
347
  if (Object.keys(toolsToResumeWithConfirmation).length === 0) {
354
348
  continue;
355
349
  }
356
- const toolsList = await agent.canonicalTools(new import_readonly_context.ReadonlyContext(invocationContext));
357
- 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
+ );
358
356
  const functionResponseEvent = await (0, import_functions.handleFunctionCallList)({
359
357
  invocationContext,
360
358
  functionCalls: Object.values(toolsToResumeWithArgs),
@@ -383,7 +381,7 @@ class CodeExecutionRequestProcessor extends import_base_llm_processor.BaseLlmReq
383
381
  for await (const event of runPreProcessor(invocationContext, llmRequest)) {
384
382
  yield event;
385
383
  }
386
- if (!(invocationContext.agent.codeExecutor instanceof import_base_code_executor.BaseCodeExecutor)) {
384
+ if (!(0, import_base_code_executor.isBaseCodeExecutor)(invocationContext.agent.codeExecutor)) {
387
385
  return;
388
386
  }
389
387
  for (const content of llmRequest.contents) {
@@ -452,7 +450,10 @@ class CodeExecutionResponseProcessor {
452
450
  if (llmResponse.partial) {
453
451
  return;
454
452
  }
455
- for await (const event of runPostProcessor(invocationContext, llmResponse)) {
453
+ for await (const event of runPostProcessor(
454
+ invocationContext,
455
+ llmResponse
456
+ )) {
456
457
  yield event;
457
458
  }
458
459
  }
@@ -460,27 +461,36 @@ class CodeExecutionResponseProcessor {
460
461
  const responseProcessor = new CodeExecutionResponseProcessor();
461
462
  async function* runPreProcessor(invocationContext, llmRequest) {
462
463
  const agent = invocationContext.agent;
463
- if (!(agent instanceof LlmAgent)) {
464
+ if (!isLlmAgent(agent)) {
464
465
  return;
465
466
  }
466
467
  const codeExecutor = agent.codeExecutor;
467
- if (!codeExecutor || !(codeExecutor instanceof import_base_code_executor.BaseCodeExecutor)) {
468
+ if (!codeExecutor || !(0, import_base_code_executor.isBaseCodeExecutor)(codeExecutor)) {
468
469
  return;
469
470
  }
470
- if (codeExecutor instanceof import_built_in_code_executor.BuiltInCodeExecutor) {
471
+ if ((0, import_built_in_code_executor.isBuiltInCodeExecutor)(codeExecutor)) {
471
472
  codeExecutor.processLlmRequest(llmRequest);
472
473
  return;
473
474
  }
474
475
  if (!codeExecutor.optimizeDataFile) {
475
476
  return;
476
477
  }
477
- 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
+ );
478
481
  if (codeExecutorContext.getErrorCount(invocationContext.invocationId) >= codeExecutor.errorRetryAttempts) {
479
482
  return;
480
483
  }
481
- const allInputFiles = extractAndReplaceInlineFiles(codeExecutorContext, llmRequest);
482
- const processedFileNames = new Set(codeExecutorContext.getProcessedFileNames());
483
- 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
+ );
484
494
  for (const file of filesToProcess) {
485
495
  const codeStr = getDataFilePreprocessingCode(file);
486
496
  if (!codeStr) {
@@ -493,14 +503,17 @@ async function* runPreProcessor(invocationContext, llmRequest) {
493
503
  (0, import_code_execution_utils.buildExecutableCodePart)(codeStr)
494
504
  ]
495
505
  };
496
- llmRequest.contents.push((0, import_cloneDeep.default)(codeContent));
506
+ llmRequest.contents.push((0, import_lodash_es.cloneDeep)(codeContent));
497
507
  yield (0, import_event.createEvent)({
498
508
  invocationId: invocationContext.invocationId,
499
509
  author: agent.name,
500
510
  branch: invocationContext.branch,
501
511
  content: codeContent
502
512
  });
503
- const executionId = getOrSetExecutionId(invocationContext, codeExecutorContext);
513
+ const executionId = getOrSetExecutionId(
514
+ invocationContext,
515
+ codeExecutorContext
516
+ );
504
517
  const codeExecutionResult = await codeExecutor.executeCode({
505
518
  invocationContext,
506
519
  codeExecutionInput: {
@@ -522,25 +535,27 @@ async function* runPreProcessor(invocationContext, llmRequest) {
522
535
  codeExecutionResult
523
536
  );
524
537
  yield executionResultEvent;
525
- llmRequest.contents.push((0, import_cloneDeep.default)(executionResultEvent.content));
538
+ llmRequest.contents.push((0, import_lodash_es.cloneDeep)(executionResultEvent.content));
526
539
  }
527
540
  }
528
541
  async function* runPostProcessor(invocationContext, llmResponse) {
529
542
  const agent = invocationContext.agent;
530
- if (!(agent instanceof LlmAgent)) {
543
+ if (!isLlmAgent(agent)) {
531
544
  return;
532
545
  }
533
546
  const codeExecutor = agent.codeExecutor;
534
- if (!codeExecutor || !(codeExecutor instanceof import_base_code_executor.BaseCodeExecutor)) {
547
+ if (!codeExecutor || !(0, import_base_code_executor.isBaseCodeExecutor)(codeExecutor)) {
535
548
  return;
536
549
  }
537
550
  if (!llmResponse || !llmResponse.content) {
538
551
  return;
539
552
  }
540
- if (codeExecutor instanceof import_built_in_code_executor.BuiltInCodeExecutor) {
553
+ if ((0, import_built_in_code_executor.isBuiltInCodeExecutor)(codeExecutor)) {
541
554
  return;
542
555
  }
543
- 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
+ );
544
559
  if (codeExecutorContext.getErrorCount(invocationContext.invocationId) >= codeExecutor.errorRetryAttempts) {
545
560
  return;
546
561
  }
@@ -558,7 +573,10 @@ async function* runPostProcessor(invocationContext, llmResponse) {
558
573
  branch: invocationContext.branch,
559
574
  content: responseContent
560
575
  });
561
- const executionId = getOrSetExecutionId(invocationContext, codeExecutorContext);
576
+ const executionId = getOrSetExecutionId(
577
+ invocationContext,
578
+ codeExecutorContext
579
+ );
562
580
  const codeExecutionResult = await codeExecutor.executeCode({
563
581
  invocationContext,
564
582
  codeExecutionInput: {
@@ -581,7 +599,7 @@ async function* runPostProcessor(invocationContext, llmResponse) {
581
599
  llmResponse.content = null;
582
600
  }
583
601
  function extractAndReplaceInlineFiles(codeExecutorContext, llmRequest) {
584
- var _a;
602
+ var _a2;
585
603
  const allInputFiles = codeExecutorContext.getInputFiles();
586
604
  const savedFileNames = new Set(allInputFiles.map((f) => f.name));
587
605
  for (let i = 0; i < llmRequest.contents.length; i++) {
@@ -591,7 +609,7 @@ function extractAndReplaceInlineFiles(codeExecutorContext, llmRequest) {
591
609
  }
592
610
  for (let j = 0; j < content.parts.length; j++) {
593
611
  const part = content.parts[j];
594
- const mimeType = (_a = part.inlineData) == null ? void 0 : _a.mimeType;
612
+ const mimeType = (_a2 = part.inlineData) == null ? void 0 : _a2.mimeType;
595
613
  if (!mimeType || !part.inlineData || !DATA_FILE_UTIL_MAP[mimeType]) {
596
614
  continue;
597
615
  }
@@ -613,9 +631,9 @@ Available file: \`${fileName}\`
613
631
  return allInputFiles;
614
632
  }
615
633
  function getOrSetExecutionId(invocationContext, codeExecutorContext) {
616
- var _a;
634
+ var _a2;
617
635
  const agent = invocationContext.agent;
618
- if (!(agent instanceof LlmAgent) || !((_a = agent.codeExecutor) == null ? void 0 : _a.stateful)) {
636
+ if (!isLlmAgent(agent) || !((_a2 = agent.codeExecutor) == null ? void 0 : _a2.stateful)) {
619
637
  return void 0;
620
638
  }
621
639
  let executionId = codeExecutorContext.getExecutionId();
@@ -633,7 +651,9 @@ async function postProcessCodeExecutionResult(invocationContext, codeExecutorCon
633
651
  role: "model",
634
652
  parts: [(0, import_code_execution_utils.buildCodeExecutionResultPart)(codeExecutionResult)]
635
653
  };
636
- const eventActions = (0, import_event_actions.createEventActions)({ stateDelta: codeExecutorContext.getStateDelta() });
654
+ const eventActions = (0, import_event_actions.createEventActions)({
655
+ stateDelta: codeExecutorContext.getStateDelta()
656
+ });
637
657
  if (codeExecutionResult.stderr) {
638
658
  codeExecutorContext.incrementErrorCount(invocationContext.invocationId);
639
659
  } else {
@@ -672,10 +692,7 @@ function getDataFilePreprocessingCode(file) {
672
692
  return void 0;
673
693
  }
674
694
  const varName = getNormalizedFileName(file.name);
675
- const loaderCode = DATA_FILE_UTIL_MAP[file.mimeType].loaderCodeTemplate.replace(
676
- "{filename}",
677
- file.name
678
- );
695
+ const loaderCode = DATA_FILE_UTIL_MAP[file.mimeType].loaderCodeTemplate.replace("{filename}", file.name);
679
696
  return `
680
697
  ${DATA_FILE_HELPER_LIB}
681
698
 
@@ -687,13 +704,19 @@ explore_df(${varName})
687
704
  `;
688
705
  }
689
706
  const CODE_EXECUTION_REQUEST_PROCESSOR = new CodeExecutionRequestProcessor();
690
- 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) {
691
712
  constructor(config) {
692
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
713
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
693
714
  super(config);
715
+ /** A unique symbol to identify ADK LLM agent class. */
716
+ this[_a] = true;
694
717
  this.model = config.model;
695
- this.instruction = (_a = config.instruction) != null ? _a : "";
696
- this.globalInstruction = (_b = config.globalInstruction) != null ? _b : "";
718
+ this.instruction = (_a2 = config.instruction) != null ? _a2 : "";
719
+ this.globalInstruction = (_b2 = config.globalInstruction) != null ? _b2 : "";
697
720
  this.tools = (_c = config.tools) != null ? _c : [];
698
721
  this.generateContentConfig = config.generateContentConfig;
699
722
  this.disallowTransferToParent = (_d = config.disallowTransferToParent) != null ? _d : false;
@@ -771,7 +794,7 @@ class LlmAgent extends import_base_agent.BaseAgent {
771
794
  }
772
795
  let ancestorAgent = this.parentAgent;
773
796
  while (ancestorAgent) {
774
- if (ancestorAgent instanceof LlmAgent) {
797
+ if (isLlmAgent(ancestorAgent)) {
775
798
  return ancestorAgent.canonicalModel;
776
799
  }
777
800
  ancestorAgent = ancestorAgent.parentAgent;
@@ -779,12 +802,12 @@ class LlmAgent extends import_base_agent.BaseAgent {
779
802
  throw new Error(`No model found for ${this.name}.`);
780
803
  }
781
804
  /**
782
- * The resolved self.instruction field to construct instruction for this
805
+ * The resolved instruction field to construct instruction for this
783
806
  * agent.
784
807
  *
785
808
  * This method is only for use by Agent Development Kit.
786
809
  * @param context The context to retrieve the session state.
787
- * @returns The resolved self.instruction field.
810
+ * @returns The resolved instruction field.
788
811
  */
789
812
  async canonicalInstruction(context) {
790
813
  if (typeof this.instruction === "string") {
@@ -796,11 +819,11 @@ class LlmAgent extends import_base_agent.BaseAgent {
796
819
  };
797
820
  }
798
821
  /**
799
- * The resolved self.instruction field to construct global instruction.
822
+ * The resolved globalInstruction field to construct global instruction.
800
823
  *
801
824
  * This method is only for use by Agent Development Kit.
802
825
  * @param context The context to retrieve the session state.
803
- * @returns The resolved self.global_instruction field.
826
+ * @returns The resolved globalInstruction field.
804
827
  */
805
828
  async canonicalGlobalInstruction(context) {
806
829
  if (typeof this.globalInstruction === "string") {
@@ -812,7 +835,7 @@ class LlmAgent extends import_base_agent.BaseAgent {
812
835
  };
813
836
  }
814
837
  /**
815
- * 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.
816
839
  *
817
840
  * This method is only for use by Agent Development Kit.
818
841
  */
@@ -840,7 +863,7 @@ class LlmAgent extends import_base_agent.BaseAgent {
840
863
  return [callback];
841
864
  }
842
865
  /**
843
- * The resolved self.before_model_callback field as a list of
866
+ * The resolved beforeModelCallback field as a list of
844
867
  * SingleBeforeModelCallback.
845
868
  *
846
869
  * This method is only for use by Agent Development Kit.
@@ -849,7 +872,7 @@ class LlmAgent extends import_base_agent.BaseAgent {
849
872
  return LlmAgent.normalizeCallbackArray(this.beforeModelCallback);
850
873
  }
851
874
  /**
852
- * The resolved self.after_model_callback field as a list of
875
+ * The resolved afterModelCallback field as a list of
853
876
  * SingleAfterModelCallback.
854
877
  *
855
878
  * This method is only for use by Agent Development Kit.
@@ -858,7 +881,7 @@ class LlmAgent extends import_base_agent.BaseAgent {
858
881
  return LlmAgent.normalizeCallbackArray(this.afterModelCallback);
859
882
  }
860
883
  /**
861
- * The resolved self.before_tool_callback field as a list of
884
+ * The resolved beforeToolCallback field as a list of
862
885
  * BeforeToolCallback.
863
886
  *
864
887
  * This method is only for use by Agent Development Kit.
@@ -867,7 +890,7 @@ class LlmAgent extends import_base_agent.BaseAgent {
867
890
  return LlmAgent.normalizeCallbackArray(this.beforeToolCallback);
868
891
  }
869
892
  /**
870
- * The resolved self.after_tool_callback field as a list of AfterToolCallback.
893
+ * The resolved afterToolCallback field as a list of AfterToolCallback.
871
894
  *
872
895
  * This method is only for use by Agent Development Kit.
873
896
  */
@@ -884,7 +907,7 @@ class LlmAgent extends import_base_agent.BaseAgent {
884
907
  * @param event The event to process.
885
908
  */
886
909
  maybeSaveOutputToState(event) {
887
- var _a, _b;
910
+ var _a2, _b2;
888
911
  if (event.author !== this.name) {
889
912
  import_logger.logger.debug(
890
913
  `Skipping output save for agent ${this.name}: event authored by ${event.author}`
@@ -903,7 +926,7 @@ class LlmAgent extends import_base_agent.BaseAgent {
903
926
  );
904
927
  return;
905
928
  }
906
- 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)) {
907
930
  import_logger.logger.debug(
908
931
  `Skipping output save for agent ${this.name}: event content is empty`
909
932
  );
@@ -963,7 +986,10 @@ class LlmAgent extends import_base_agent.BaseAgent {
963
986
  liveConnectConfig: {}
964
987
  };
965
988
  for (const processor of this.requestProcessors) {
966
- for await (const event of processor.runAsync(invocationContext, llmRequest)) {
989
+ for await (const event of processor.runAsync(
990
+ invocationContext,
991
+ llmRequest
992
+ )) {
967
993
  yield event;
968
994
  }
969
995
  }
@@ -1003,9 +1029,12 @@ class LlmAgent extends import_base_agent.BaseAgent {
1003
1029
  }
1004
1030
  }
1005
1031
  async *postprocess(invocationContext, llmRequest, llmResponse, modelResponseEvent) {
1006
- var _a;
1032
+ var _a2;
1007
1033
  for (const processor of this.responseProcessors) {
1008
- for await (const event of processor.runAsync(invocationContext, llmResponse)) {
1034
+ for await (const event of processor.runAsync(
1035
+ invocationContext,
1036
+ llmResponse
1037
+ )) {
1009
1038
  yield event;
1010
1039
  }
1011
1040
  }
@@ -1026,7 +1055,7 @@ class LlmAgent extends import_base_agent.BaseAgent {
1026
1055
  }
1027
1056
  }
1028
1057
  yield mergedEvent;
1029
- 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)) {
1030
1059
  return;
1031
1060
  }
1032
1061
  const functionResponseEvent = await (0, import_functions.handleFunctionCallsAsync)({
@@ -1039,7 +1068,10 @@ class LlmAgent extends import_base_agent.BaseAgent {
1039
1068
  if (!functionResponseEvent) {
1040
1069
  return;
1041
1070
  }
1042
- const authEvent = (0, import_functions.generateAuthEvent)(invocationContext, functionResponseEvent);
1071
+ const authEvent = (0, import_functions.generateAuthEvent)(
1072
+ invocationContext,
1073
+ functionResponseEvent
1074
+ );
1043
1075
  if (authEvent) {
1044
1076
  yield authEvent;
1045
1077
  }
@@ -1081,7 +1113,7 @@ class LlmAgent extends import_base_agent.BaseAgent {
1081
1113
  return agentToRun;
1082
1114
  }
1083
1115
  async *callLlmAsync(invocationContext, llmRequest, modelResponseEvent) {
1084
- var _a, _b, _c, _d, _e;
1116
+ var _a2, _b2, _c, _d, _e;
1085
1117
  const beforeModelResponse = await this.handleBeforeModelCallback(
1086
1118
  invocationContext,
1087
1119
  llmRequest,
@@ -1091,8 +1123,8 @@ class LlmAgent extends import_base_agent.BaseAgent {
1091
1123
  yield beforeModelResponse;
1092
1124
  return;
1093
1125
  }
1094
- (_a = llmRequest.config) != null ? _a : llmRequest.config = {};
1095
- (_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 = {};
1096
1128
  if (!llmRequest.config.labels[ADK_AGENT_NAME_LABEL_KEY]) {
1097
1129
  llmRequest.config.labels[ADK_AGENT_NAME_LABEL_KEY] = this.name;
1098
1130
  }
@@ -1122,17 +1154,22 @@ class LlmAgent extends import_base_agent.BaseAgent {
1122
1154
  }
1123
1155
  }
1124
1156
  async handleBeforeModelCallback(invocationContext, llmRequest, modelResponseEvent) {
1125
- const callbackContext = new import_callback_context.CallbackContext(
1126
- { invocationContext, eventActions: modelResponseEvent.actions }
1127
- );
1128
- const beforeModelCallbackResponse = await invocationContext.pluginManager.runBeforeModelCallback(
1129
- { callbackContext, llmRequest }
1130
- );
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
+ });
1131
1165
  if (beforeModelCallbackResponse) {
1132
1166
  return beforeModelCallbackResponse;
1133
1167
  }
1134
1168
  for (const callback of this.canonicalBeforeModelCallbacks) {
1135
- const callbackResponse = await callback({ context: callbackContext, request: llmRequest });
1169
+ const callbackResponse = await callback({
1170
+ context: callbackContext,
1171
+ request: llmRequest
1172
+ });
1136
1173
  if (callbackResponse) {
1137
1174
  return callbackResponse;
1138
1175
  }
@@ -1140,17 +1177,22 @@ class LlmAgent extends import_base_agent.BaseAgent {
1140
1177
  return void 0;
1141
1178
  }
1142
1179
  async handleAfterModelCallback(invocationContext, llmResponse, modelResponseEvent) {
1143
- const callbackContext = new import_callback_context.CallbackContext(
1144
- { invocationContext, eventActions: modelResponseEvent.actions }
1145
- );
1146
- const afterModelCallbackResponse = await invocationContext.pluginManager.runAfterModelCallback(
1147
- { callbackContext, llmResponse }
1148
- );
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
+ });
1149
1188
  if (afterModelCallbackResponse) {
1150
1189
  return afterModelCallbackResponse;
1151
1190
  }
1152
1191
  for (const callback of this.canonicalAfterModelCallbacks) {
1153
- const callbackResponse = await callback({ context: callbackContext, response: llmResponse });
1192
+ const callbackResponse = await callback({
1193
+ context: callbackContext,
1194
+ response: llmResponse
1195
+ });
1154
1196
  if (callbackResponse) {
1155
1197
  return callbackResponse;
1156
1198
  }
@@ -1163,9 +1205,10 @@ class LlmAgent extends import_base_agent.BaseAgent {
1163
1205
  yield response;
1164
1206
  }
1165
1207
  } catch (modelError) {
1166
- const callbackContext = new import_callback_context.CallbackContext(
1167
- { invocationContext, eventActions: modelResponseEvent.actions }
1168
- );
1208
+ const callbackContext = new import_callback_context.CallbackContext({
1209
+ invocationContext,
1210
+ eventActions: modelResponseEvent.actions
1211
+ });
1169
1212
  if (modelError instanceof Error) {
1170
1213
  const onModelErrorCallbackResponse = await invocationContext.pluginManager.runOnModelErrorCallback({
1171
1214
  callbackContext,
@@ -1198,5 +1241,6 @@ class LlmAgent extends import_base_agent.BaseAgent {
1198
1241
  0 && (module.exports = {
1199
1242
  LlmAgent,
1200
1243
  REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR,
1244
+ isLlmAgent,
1201
1245
  responseProcessor
1202
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: