@google/adk 0.2.4 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/dist/cjs/agents/base_agent.js +52 -24
  2. package/dist/cjs/agents/callback_context.js +4 -1
  3. package/dist/cjs/agents/content_processor_utils.js +15 -7
  4. package/dist/cjs/agents/functions.js +79 -29
  5. package/dist/cjs/agents/invocation_context.js +3 -1
  6. package/dist/cjs/agents/llm_agent.js +188 -108
  7. package/dist/cjs/agents/loop_agent.js +18 -6
  8. package/dist/cjs/agents/parallel_agent.js +20 -7
  9. package/dist/cjs/agents/readonly_context.js +4 -1
  10. package/dist/cjs/agents/sequential_agent.js +34 -12
  11. package/dist/cjs/artifacts/gcs_artifact_service.js +28 -20
  12. package/dist/cjs/artifacts/in_memory_artifact_service.js +18 -4
  13. package/dist/cjs/auth/auth_handler.js +3 -1
  14. package/dist/cjs/code_executors/base_code_executor.js +14 -2
  15. package/dist/cjs/code_executors/built_in_code_executor.js +21 -5
  16. package/dist/cjs/code_executors/code_executor_context.js +5 -5
  17. package/dist/cjs/common.js +45 -0
  18. package/dist/cjs/events/event.js +1 -3
  19. package/dist/cjs/examples/base_example_provider.js +18 -2
  20. package/dist/cjs/examples/example_util.js +1 -1
  21. package/dist/cjs/index.js +19 -19
  22. package/dist/cjs/index.js.map +4 -4
  23. package/dist/cjs/memory/in_memory_memory_service.js +3 -1
  24. package/dist/cjs/models/base_llm.js +8 -4
  25. package/dist/cjs/models/gemini_llm_connection.js +1 -0
  26. package/dist/cjs/models/google_llm.js +3 -3
  27. package/dist/cjs/plugins/base_plugin.js +71 -49
  28. package/dist/cjs/plugins/logging_plugin.js +50 -13
  29. package/dist/cjs/plugins/plugin_manager.js +56 -24
  30. package/dist/cjs/plugins/security_plugin.js +5 -2
  31. package/dist/cjs/runner/runner.js +126 -101
  32. package/dist/cjs/sessions/in_memory_session_service.js +38 -14
  33. package/dist/cjs/telemetry/google_cloud.js +7 -9
  34. package/dist/cjs/telemetry/setup.js +15 -7
  35. package/dist/cjs/telemetry/tracing.js +37 -15
  36. package/dist/cjs/tools/agent_tool.js +26 -13
  37. package/dist/cjs/tools/base_tool.js +19 -7
  38. package/dist/cjs/tools/forwarding_artifact_service.js +1 -1
  39. package/dist/cjs/tools/function_tool.js +15 -7
  40. package/dist/cjs/tools/google_search_tool.js +8 -4
  41. package/dist/cjs/tools/mcp/mcp_session_manager.js +16 -10
  42. package/dist/cjs/tools/mcp/mcp_tool.js +1 -3
  43. package/dist/cjs/tools/mcp/mcp_toolset.js +1 -1
  44. package/dist/cjs/tools/tool_context.js +4 -9
  45. package/dist/cjs/utils/env_aware_utils.js +1 -1
  46. package/dist/cjs/utils/gemini_schema_util.js +10 -4
  47. package/dist/cjs/utils/logger.js +47 -3
  48. package/dist/cjs/utils/simple_zod_to_json.js +100 -141
  49. package/dist/cjs/utils/variant_utils.js +1 -1
  50. package/dist/cjs/version.js +1 -1
  51. package/dist/esm/agents/base_agent.js +57 -25
  52. package/dist/esm/agents/callback_context.js +4 -1
  53. package/dist/esm/agents/content_processor_utils.js +25 -9
  54. package/dist/esm/agents/functions.js +83 -29
  55. package/dist/esm/agents/invocation_context.js +3 -1
  56. package/dist/esm/agents/llm_agent.js +228 -116
  57. package/dist/esm/agents/loop_agent.js +16 -5
  58. package/dist/esm/agents/parallel_agent.js +18 -6
  59. package/dist/esm/agents/readonly_context.js +4 -1
  60. package/dist/esm/agents/sequential_agent.js +33 -12
  61. package/dist/esm/artifacts/gcs_artifact_service.js +28 -20
  62. package/dist/esm/artifacts/in_memory_artifact_service.js +18 -4
  63. package/dist/esm/auth/auth_handler.js +3 -1
  64. package/dist/esm/code_executors/base_code_executor.js +12 -1
  65. package/dist/esm/code_executors/built_in_code_executor.js +19 -4
  66. package/dist/esm/code_executors/code_executor_context.js +5 -5
  67. package/dist/esm/common.js +56 -11
  68. package/dist/esm/events/event.js +1 -3
  69. package/dist/esm/examples/base_example_provider.js +16 -1
  70. package/dist/esm/examples/example_util.js +4 -2
  71. package/dist/esm/index.js +19 -19
  72. package/dist/esm/index.js.map +4 -4
  73. package/dist/esm/memory/in_memory_memory_service.js +3 -1
  74. package/dist/esm/models/base_llm.js +8 -4
  75. package/dist/esm/models/gemini_llm_connection.js +1 -0
  76. package/dist/esm/models/google_llm.js +8 -4
  77. package/dist/esm/plugins/base_plugin.js +71 -49
  78. package/dist/esm/plugins/logging_plugin.js +55 -14
  79. package/dist/esm/plugins/plugin_manager.js +56 -24
  80. package/dist/esm/plugins/security_plugin.js +5 -2
  81. package/dist/esm/runner/runner.js +139 -105
  82. package/dist/esm/sessions/in_memory_session_service.js +41 -15
  83. package/dist/esm/telemetry/google_cloud.js +7 -9
  84. package/dist/esm/telemetry/setup.js +23 -9
  85. package/dist/esm/telemetry/tracing.js +37 -15
  86. package/dist/esm/tools/agent_tool.js +25 -13
  87. package/dist/esm/tools/base_tool.js +17 -6
  88. package/dist/esm/tools/forwarding_artifact_service.js +1 -1
  89. package/dist/esm/tools/function_tool.js +13 -8
  90. package/dist/esm/tools/google_search_tool.js +6 -3
  91. package/dist/esm/tools/long_running_tool.js +3 -1
  92. package/dist/esm/tools/mcp/mcp_session_manager.js +22 -12
  93. package/dist/esm/tools/mcp/mcp_tool.js +1 -3
  94. package/dist/esm/tools/mcp/mcp_toolset.js +1 -1
  95. package/dist/esm/tools/tool_context.js +4 -9
  96. package/dist/esm/utils/env_aware_utils.js +1 -1
  97. package/dist/esm/utils/gemini_schema_util.js +10 -4
  98. package/dist/esm/utils/logger.js +43 -2
  99. package/dist/esm/utils/simple_zod_to_json.js +102 -141
  100. package/dist/esm/utils/variant_utils.js +1 -1
  101. package/dist/esm/version.js +1 -1
  102. package/dist/types/agents/base_agent.d.ts +16 -4
  103. package/dist/types/agents/callback_context.d.ts +1 -1
  104. package/dist/types/agents/invocation_context.d.ts +4 -2
  105. package/dist/types/agents/llm_agent.d.ts +43 -31
  106. package/dist/types/agents/loop_agent.d.ts +17 -1
  107. package/dist/types/agents/parallel_agent.d.ts +17 -1
  108. package/dist/types/agents/sequential_agent.d.ts +17 -1
  109. package/dist/types/artifacts/in_memory_artifact_service.d.ts +3 -3
  110. package/dist/types/auth/auth_schemes.d.ts +5 -2
  111. package/dist/types/code_executors/base_code_executor.d.ts +14 -0
  112. package/dist/types/code_executors/built_in_code_executor.d.ts +20 -1
  113. package/dist/types/code_executors/code_executor_context.d.ts +2 -4
  114. package/dist/types/common.d.ts +40 -15
  115. package/dist/types/examples/base_example_provider.d.ts +16 -0
  116. package/dist/types/index.d.ts +3 -3
  117. package/dist/types/models/base_llm_connection.d.ts +1 -1
  118. package/dist/types/models/llm_response.d.ts +1 -1
  119. package/dist/types/plugins/base_plugin.d.ts +50 -40
  120. package/dist/types/plugins/logging_plugin.d.ts +12 -12
  121. package/dist/types/plugins/plugin_manager.d.ts +12 -12
  122. package/dist/types/plugins/security_plugin.d.ts +1 -1
  123. package/dist/types/runner/runner.d.ts +18 -10
  124. package/dist/types/sessions/in_memory_session_service.d.ts +5 -5
  125. package/dist/types/telemetry/setup.d.ts +1 -1
  126. package/dist/types/telemetry/tracing.d.ts +7 -6
  127. package/dist/types/tools/agent_tool.d.ts +15 -1
  128. package/dist/types/tools/base_tool.d.ts +15 -1
  129. package/dist/types/tools/base_toolset.d.ts +2 -1
  130. package/dist/types/tools/forwarding_artifact_service.d.ts +2 -2
  131. package/dist/types/tools/function_tool.d.ts +18 -4
  132. package/dist/types/tools/google_search_tool.d.ts +5 -6
  133. package/dist/types/tools/mcp/mcp_session_manager.d.ts +10 -3
  134. package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -2
  135. package/dist/types/tools/tool_context.d.ts +1 -1
  136. package/dist/types/utils/gemini_schema_util.d.ts +4 -12
  137. package/dist/types/utils/logger.d.ts +11 -10
  138. package/dist/types/utils/simple_zod_to_json.d.ts +5 -4
  139. package/dist/types/version.d.ts +1 -1
  140. package/dist/web/agents/base_agent.js +103 -36
  141. package/dist/web/agents/callback_context.js +4 -1
  142. package/dist/web/agents/content_processor_utils.js +25 -9
  143. package/dist/web/agents/functions.js +83 -29
  144. package/dist/web/agents/invocation_context.js +3 -1
  145. package/dist/web/agents/llm_agent.js +282 -137
  146. package/dist/web/agents/loop_agent.js +16 -5
  147. package/dist/web/agents/parallel_agent.js +18 -6
  148. package/dist/web/agents/readonly_context.js +4 -1
  149. package/dist/web/agents/sequential_agent.js +33 -12
  150. package/dist/web/artifacts/gcs_artifact_service.js +25 -17
  151. package/dist/web/artifacts/in_memory_artifact_service.js +18 -4
  152. package/dist/web/auth/auth_handler.js +3 -1
  153. package/dist/web/code_executors/base_code_executor.js +12 -1
  154. package/dist/web/code_executors/built_in_code_executor.js +19 -4
  155. package/dist/web/code_executors/code_executor_context.js +5 -5
  156. package/dist/web/common.js +56 -11
  157. package/dist/web/events/event.js +1 -3
  158. package/dist/web/examples/base_example_provider.js +16 -1
  159. package/dist/web/examples/example_util.js +4 -2
  160. package/dist/web/index.js +1 -1
  161. package/dist/web/index.js.map +4 -4
  162. package/dist/web/memory/in_memory_memory_service.js +3 -1
  163. package/dist/web/models/base_llm.js +8 -4
  164. package/dist/web/models/gemini_llm_connection.js +1 -0
  165. package/dist/web/models/google_llm.js +8 -4
  166. package/dist/web/plugins/base_plugin.js +71 -49
  167. package/dist/web/plugins/logging_plugin.js +55 -14
  168. package/dist/web/plugins/plugin_manager.js +56 -24
  169. package/dist/web/plugins/security_plugin.js +5 -2
  170. package/dist/web/runner/runner.js +186 -119
  171. package/dist/web/sessions/in_memory_session_service.js +41 -15
  172. package/dist/web/telemetry/google_cloud.js +7 -9
  173. package/dist/web/telemetry/setup.js +23 -9
  174. package/dist/web/telemetry/tracing.js +37 -15
  175. package/dist/web/tools/agent_tool.js +25 -13
  176. package/dist/web/tools/base_tool.js +17 -6
  177. package/dist/web/tools/forwarding_artifact_service.js +1 -1
  178. package/dist/web/tools/function_tool.js +13 -8
  179. package/dist/web/tools/google_search_tool.js +6 -3
  180. package/dist/web/tools/long_running_tool.js +3 -1
  181. package/dist/web/tools/mcp/mcp_session_manager.js +22 -12
  182. package/dist/web/tools/mcp/mcp_tool.js +1 -3
  183. package/dist/web/tools/mcp/mcp_toolset.js +1 -1
  184. package/dist/web/tools/tool_context.js +4 -9
  185. package/dist/web/utils/env_aware_utils.js +1 -1
  186. package/dist/web/utils/gemini_schema_util.js +10 -4
  187. package/dist/web/utils/logger.js +43 -2
  188. package/dist/web/utils/simple_zod_to_json.js +102 -155
  189. package/dist/web/utils/variant_utils.js +1 -1
  190. package/dist/web/version.js +1 -1
  191. package/package.json +5 -3
@@ -3,12 +3,21 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ var _a, _b;
6
7
  import { BaseAgent } from "./base_agent.js";
7
- class LoopAgent extends BaseAgent {
8
+ const LOOP_AGENT_SIGNATURE_SYMBOL = Symbol.for("google.adk.loopAgent");
9
+ function isLoopAgent(obj) {
10
+ return typeof obj === "object" && obj !== null && LOOP_AGENT_SIGNATURE_SYMBOL in obj && obj[LOOP_AGENT_SIGNATURE_SYMBOL] === true;
11
+ }
12
+ class LoopAgent extends (_b = BaseAgent, _a = LOOP_AGENT_SIGNATURE_SYMBOL, _b) {
8
13
  constructor(config) {
9
- var _a;
14
+ var _a2;
10
15
  super(config);
11
- this.maxIterations = (_a = config.maxIterations) != null ? _a : Number.MAX_SAFE_INTEGER;
16
+ /**
17
+ * A unique symbol to identify ADK loop agent class.
18
+ */
19
+ this[_a] = true;
20
+ this.maxIterations = (_a2 = config.maxIterations) != null ? _a2 : Number.MAX_SAFE_INTEGER;
12
21
  }
13
22
  async *runAsyncImpl(context) {
14
23
  let iteration = 0;
@@ -29,10 +38,12 @@ class LoopAgent extends BaseAgent {
29
38
  }
30
39
  return;
31
40
  }
32
- async *runLiveImpl(context) {
41
+ // eslint-disable-next-line require-yield
42
+ async *runLiveImpl(_context) {
33
43
  throw new Error("This is not supported yet for LoopAgent.");
34
44
  }
35
45
  }
36
46
  export {
37
- LoopAgent
47
+ LoopAgent,
48
+ isLoopAgent
38
49
  };
@@ -3,20 +3,31 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ var _a, _b;
6
7
  import { BaseAgent } from "./base_agent.js";
7
8
  import { InvocationContext } from "./invocation_context.js";
8
- class ParallelAgent extends BaseAgent {
9
+ const PARALLEL_AGENT_SIGNATURE_SYMBOL = Symbol.for("google.adk.parallelAgent");
10
+ function isParallelAgent(obj) {
11
+ return typeof obj === "object" && obj !== null && PARALLEL_AGENT_SIGNATURE_SYMBOL in obj && obj[PARALLEL_AGENT_SIGNATURE_SYMBOL] === true;
12
+ }
13
+ class ParallelAgent extends (_b = BaseAgent, _a = PARALLEL_AGENT_SIGNATURE_SYMBOL, _b) {
14
+ constructor() {
15
+ super(...arguments);
16
+ /**
17
+ * A unique symbol to identify ADK parallel agent class.
18
+ */
19
+ this[_a] = true;
20
+ }
9
21
  async *runAsyncImpl(context) {
10
22
  const agentRuns = this.subAgents.map(
11
- (subAgent) => subAgent.runAsync(
12
- createBranchCtxForSubAgent(this, subAgent, context)
13
- )
23
+ (subAgent) => subAgent.runAsync(createBranchCtxForSubAgent(this, subAgent, context))
14
24
  );
15
25
  for await (const event of mergeAgentRuns(agentRuns)) {
16
26
  yield event;
17
27
  }
18
28
  }
19
- async *runLiveImpl(context) {
29
+ // eslint-disable-next-line require-yield
30
+ async *runLiveImpl(_context) {
20
31
  throw new Error("This is not supported yet for ParallelAgent.");
21
32
  }
22
33
  }
@@ -44,5 +55,6 @@ async function* mergeAgentRuns(agentRuns) {
44
55
  }
45
56
  }
46
57
  export {
47
- ParallelAgent
58
+ ParallelAgent,
59
+ isParallelAgent
48
60
  };
@@ -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 {
@@ -3,12 +3,26 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ var _a, _b;
6
7
  import { FunctionTool } from "../tools/function_tool.js";
7
8
  import { BaseAgent } from "./base_agent.js";
8
- import { LlmAgent } from "./llm_agent.js";
9
+ import { isLlmAgent } from "./llm_agent.js";
9
10
  import { ReadonlyContext } from "./readonly_context.js";
10
11
  const TASK_COMPLETED_TOOL_NAME = "task_completed";
11
- class SequentialAgent extends BaseAgent {
12
+ const SEQUENTIAL_AGENT_SIGNATURE_SYMBOL = Symbol.for(
13
+ "google.adk.sequentialAgent"
14
+ );
15
+ function isSequentialAgent(obj) {
16
+ return typeof obj === "object" && obj !== null && SEQUENTIAL_AGENT_SIGNATURE_SYMBOL in obj && obj[SEQUENTIAL_AGENT_SIGNATURE_SYMBOL] === true;
17
+ }
18
+ class SequentialAgent extends (_b = BaseAgent, _a = SEQUENTIAL_AGENT_SIGNATURE_SYMBOL, _b) {
19
+ constructor() {
20
+ super(...arguments);
21
+ /**
22
+ * A unique symbol to identify ADK sequential agent class.
23
+ */
24
+ this[_a] = true;
25
+ }
12
26
  async *runAsyncImpl(context) {
13
27
  for (const subAgent of this.subAgents) {
14
28
  for await (const event of subAgent.runAsync(context)) {
@@ -25,19 +39,25 @@ class SequentialAgent extends BaseAgent {
25
39
  * the model can call this function to signal that it's finished the task and
26
40
  * we can move on to the next agent.
27
41
  *
28
- * @param context: The invocation context of the agent.
42
+ * @param context The invocation context of the agent.
29
43
  */
30
44
  async *runLiveImpl(context) {
31
45
  for (const subAgent of this.subAgents) {
32
- if (subAgent instanceof LlmAgent) {
33
- const agentTools = await subAgent.canonicalTools(new ReadonlyContext(context));
34
- const taskCompletedToolAlreadyAdded = agentTools.some((tool) => tool.name === TASK_COMPLETED_TOOL_NAME);
46
+ if (isLlmAgent(subAgent)) {
47
+ const agentTools = await subAgent.canonicalTools(
48
+ new ReadonlyContext(context)
49
+ );
50
+ const taskCompletedToolAlreadyAdded = agentTools.some(
51
+ (tool) => tool.name === TASK_COMPLETED_TOOL_NAME
52
+ );
35
53
  if (!taskCompletedToolAlreadyAdded) {
36
- subAgent.tools.push(new FunctionTool({
37
- name: TASK_COMPLETED_TOOL_NAME,
38
- description: `Signals that the model has successfully completed the user's question or task.`,
39
- execute: () => "Task completion signaled."
40
- }));
54
+ subAgent.tools.push(
55
+ new FunctionTool({
56
+ name: TASK_COMPLETED_TOOL_NAME,
57
+ description: `Signals that the model has successfully completed the user's question or task.`,
58
+ execute: () => "Task completion signaled."
59
+ })
60
+ );
41
61
  subAgent.instruction += `If you finished the user's request according to its description, call the ${TASK_COMPLETED_TOOL_NAME} function to exit so the next agents can take over. When calling this function, do not generate any text other than the function call.`;
42
62
  }
43
63
  }
@@ -50,5 +70,6 @@ class SequentialAgent extends BaseAgent {
50
70
  }
51
71
  }
52
72
  export {
53
- SequentialAgent
73
+ SequentialAgent,
74
+ isSequentialAgent
54
75
  };
@@ -12,10 +12,12 @@ class GcsArtifactService {
12
12
  async saveArtifact(request) {
13
13
  const versions = await this.listVersions(request);
14
14
  const version = versions.length > 0 ? Math.max(...versions) + 1 : 0;
15
- const file = this.bucket.file(getFileName({
16
- ...request,
17
- version
18
- }));
15
+ const file = this.bucket.file(
16
+ getFileName({
17
+ ...request,
18
+ version
19
+ })
20
+ );
19
21
  if (request.artifact.inlineData) {
20
22
  await file.save(JSON.stringify(request.artifact.inlineData.data), {
21
23
  contentType: request.artifact.inlineData.mimeType
@@ -39,11 +41,16 @@ class GcsArtifactService {
39
41
  }
40
42
  version = Math.max(...versions);
41
43
  }
42
- const file = this.bucket.file(getFileName({
43
- ...request,
44
- version
45
- }));
46
- const [[metadata], [rawDataBuffer]] = await Promise.all([file.getMetadata(), file.download()]);
44
+ const file = this.bucket.file(
45
+ getFileName({
46
+ ...request,
47
+ version
48
+ })
49
+ );
50
+ const [[metadata], [rawDataBuffer]] = await Promise.all([
51
+ file.getMetadata(),
52
+ file.download()
53
+ ]);
47
54
  if (metadata.contentType === "text/plain") {
48
55
  return createPartFromText(rawDataBuffer.toString("utf-8"));
49
56
  }
@@ -56,10 +63,7 @@ class GcsArtifactService {
56
63
  const fileNames = [];
57
64
  const sessionPrefix = `${request.appName}/${request.userId}/${request.sessionId}/`;
58
65
  const usernamePrefix = `${request.appName}/${request.userId}/user/`;
59
- const [
60
- [sessionFiles],
61
- [userSessionFiles]
62
- ] = await Promise.all([
66
+ const [[sessionFiles], [userSessionFiles]] = await Promise.all([
63
67
  this.bucket.getFiles({ prefix: sessionPrefix }),
64
68
  this.bucket.getFiles({ prefix: usernamePrefix })
65
69
  ]);
@@ -73,13 +77,17 @@ class GcsArtifactService {
73
77
  }
74
78
  async deleteArtifact(request) {
75
79
  const versions = await this.listVersions(request);
76
- await Promise.all(versions.map((version) => {
77
- const file = this.bucket.file(getFileName({
78
- ...request,
79
- version
80
- }));
81
- return file.delete();
82
- }));
80
+ await Promise.all(
81
+ versions.map((version) => {
82
+ const file = this.bucket.file(
83
+ getFileName({
84
+ ...request,
85
+ version
86
+ })
87
+ );
88
+ return file.delete();
89
+ })
90
+ );
83
91
  return;
84
92
  }
85
93
  async listVersions(request) {
@@ -39,7 +39,11 @@ class InMemoryArtifactService {
39
39
  }
40
40
  return Promise.resolve(versions[version]);
41
41
  }
42
- listArtifactKeys({ appName, userId, sessionId }) {
42
+ listArtifactKeys({
43
+ appName,
44
+ userId,
45
+ sessionId
46
+ }) {
43
47
  const sessionPrefix = `${appName}/${userId}/${sessionId}/`;
44
48
  const usernamespacePrefix = `${appName}/${userId}/user/`;
45
49
  const filenames = [];
@@ -54,7 +58,12 @@ class InMemoryArtifactService {
54
58
  }
55
59
  return Promise.resolve(filenames.sort());
56
60
  }
57
- deleteArtifact({ appName, userId, sessionId, filename }) {
61
+ deleteArtifact({
62
+ appName,
63
+ userId,
64
+ sessionId,
65
+ filename
66
+ }) {
58
67
  const path = artifactPath(appName, userId, sessionId, filename);
59
68
  if (!this.artifacts[path]) {
60
69
  return Promise.resolve();
@@ -62,13 +71,18 @@ class InMemoryArtifactService {
62
71
  delete this.artifacts[path];
63
72
  return Promise.resolve();
64
73
  }
65
- listVersions({ appName, userId, sessionId, filename }) {
74
+ listVersions({
75
+ appName,
76
+ userId,
77
+ sessionId,
78
+ filename
79
+ }) {
66
80
  const path = artifactPath(appName, userId, sessionId, filename);
67
81
  const artifacts = this.artifacts[path];
68
82
  if (!artifacts) {
69
83
  return Promise.resolve([]);
70
84
  }
71
- let versions = [];
85
+ const versions = [];
72
86
  for (let i = 0; i < artifacts.length; i++) {
73
87
  versions.push(i);
74
88
  }
@@ -37,7 +37,9 @@ class AuthHandler {
37
37
  };
38
38
  }
39
39
  if (!this.authConfig.rawAuthCredential.oauth2.clientId || !this.authConfig.rawAuthCredential.oauth2.clientSecret) {
40
- throw new Error(`Auth Scheme ${authSchemeType} requires both clientId and clientSecret in authCredential.oauth2.`);
40
+ throw new Error(
41
+ `Auth Scheme ${authSchemeType} requires both clientId and clientSecret in authCredential.oauth2.`
42
+ );
41
43
  }
42
44
  return {
43
45
  credentialKey: this.authConfig.credentialKey,
@@ -3,8 +3,18 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ var _a;
7
+ const BASE_CODE_EXECUTOR_SIGNATURE_SYMBOL = Symbol.for(
8
+ "google.adk.baseCodeExecutor"
9
+ );
10
+ function isBaseCodeExecutor(obj) {
11
+ return typeof obj === "object" && obj !== null && BASE_CODE_EXECUTOR_SIGNATURE_SYMBOL in obj && obj[BASE_CODE_EXECUTOR_SIGNATURE_SYMBOL] === true;
12
+ }
13
+ _a = BASE_CODE_EXECUTOR_SIGNATURE_SYMBOL;
6
14
  class BaseCodeExecutor {
7
15
  constructor() {
16
+ /** A unique symbol to identify BaseCodeExecutor class. */
17
+ this[_a] = true;
8
18
  /**
9
19
  * If true, extract and process data files from the model request
10
20
  * and attach them to the code executor.
@@ -42,5 +52,6 @@ class BaseCodeExecutor {
42
52
  }
43
53
  }
44
54
  export {
45
- BaseCodeExecutor
55
+ BaseCodeExecutor,
56
+ isBaseCodeExecutor
46
57
  };
@@ -3,10 +3,22 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ var _a, _b;
6
7
  import { isGemini2OrAbove } from "../utils/model_name.js";
7
8
  import { BaseCodeExecutor } from "./base_code_executor.js";
8
- class BuiltInCodeExecutor extends BaseCodeExecutor {
9
- executeCode(params) {
9
+ const BUILT_IN_CODE_EXECUTOR_SIGNATURE_SYMBOL = Symbol.for(
10
+ "google.adk.builtInCodeExecutor"
11
+ );
12
+ function isBuiltInCodeExecutor(obj) {
13
+ return typeof obj === "object" && obj !== null && BUILT_IN_CODE_EXECUTOR_SIGNATURE_SYMBOL in obj && obj[BUILT_IN_CODE_EXECUTOR_SIGNATURE_SYMBOL] === true;
14
+ }
15
+ class BuiltInCodeExecutor extends (_b = BaseCodeExecutor, _a = BUILT_IN_CODE_EXECUTOR_SIGNATURE_SYMBOL, _b) {
16
+ constructor() {
17
+ super(...arguments);
18
+ /** A unique symbol to identify BuiltInCodeExecutor class. */
19
+ this[_a] = true;
20
+ }
21
+ executeCode(_params) {
10
22
  return Promise.resolve({
11
23
  stdout: "",
12
24
  stderr: "",
@@ -20,9 +32,12 @@ class BuiltInCodeExecutor extends BaseCodeExecutor {
20
32
  llmRequest.config.tools.push({ codeExecution: {} });
21
33
  return;
22
34
  }
23
- throw new Error(`Gemini code execution tool is not supported for model ${llmRequest.model}`);
35
+ throw new Error(
36
+ `Gemini code execution tool is not supported for model ${llmRequest.model}`
37
+ );
24
38
  }
25
39
  }
26
40
  export {
27
- BuiltInCodeExecutor
41
+ BuiltInCodeExecutor,
42
+ isBuiltInCodeExecutor
28
43
  };
@@ -142,7 +142,9 @@ class CodeExecutorContext {
142
142
  if (!(CODE_EXECUTION_RESULTS_KEY in this.sessionState)) {
143
143
  this.sessionState.set(CODE_EXECUTION_RESULTS_KEY, {});
144
144
  }
145
- const codeExecutionResults = this.sessionState.get(CODE_EXECUTION_RESULTS_KEY);
145
+ const codeExecutionResults = this.sessionState.get(
146
+ CODE_EXECUTION_RESULTS_KEY
147
+ );
146
148
  if (!(invocationId in codeExecutionResults)) {
147
149
  codeExecutionResults[invocationId] = [];
148
150
  }
@@ -154,12 +156,10 @@ class CodeExecutorContext {
154
156
  });
155
157
  }
156
158
  /**
157
- * Gets the code executor context from the session state.
158
- * @param invocationId The session state to get the code executor context
159
- * from.
159
+ * Gets the code execution context from the session state.
160
160
  * @return The code execution context for the given invocation ID.
161
161
  */
162
- getCodeExecutionContext(invocationId) {
162
+ getCodeExecutionContext() {
163
163
  return this.sessionState.get(CONTEXT_KEY) || {};
164
164
  }
165
165
  }
@@ -3,20 +3,39 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ import { ActiveStreamingTool } from "./agents/active_streaming_tool.js";
6
7
  import { BaseAgent, isBaseAgent } from "./agents/base_agent.js";
8
+ import {
9
+ BaseLlmRequestProcessor,
10
+ BaseLlmResponseProcessor
11
+ } from "./agents/base_llm_processor.js";
7
12
  import { CallbackContext } from "./agents/callback_context.js";
8
13
  import { functionsExportedForTestingOnly } from "./agents/functions.js";
9
14
  import { InvocationContext } from "./agents/invocation_context.js";
10
15
  import { LiveRequestQueue } from "./agents/live_request_queue.js";
11
- import { LlmAgent } from "./agents/llm_agent.js";
12
- import { LoopAgent } from "./agents/loop_agent.js";
13
- import { ParallelAgent } from "./agents/parallel_agent.js";
16
+ import { LlmAgent, isLlmAgent } from "./agents/llm_agent.js";
17
+ import { LoopAgent, isLoopAgent } from "./agents/loop_agent.js";
18
+ import { ParallelAgent, isParallelAgent } from "./agents/parallel_agent.js";
19
+ import { ReadonlyContext } from "./agents/readonly_context.js";
14
20
  import { StreamingMode } from "./agents/run_config.js";
15
- import { SequentialAgent } from "./agents/sequential_agent.js";
21
+ import { SequentialAgent, isSequentialAgent } from "./agents/sequential_agent.js";
16
22
  import { InMemoryArtifactService } from "./artifacts/in_memory_artifact_service.js";
23
+ import { AuthCredentialTypes } from "./auth/auth_credential.js";
24
+ import { BaseCodeExecutor } from "./code_executors/base_code_executor.js";
17
25
  import { BuiltInCodeExecutor } from "./code_executors/built_in_code_executor.js";
18
- import { createEvent, getFunctionCalls, getFunctionResponses, hasTrailingCodeExecutionResult, isFinalResponse, stringifyContent } from "./events/event.js";
26
+ import {
27
+ createEvent,
28
+ getFunctionCalls,
29
+ getFunctionResponses,
30
+ hasTrailingCodeExecutionResult,
31
+ isFinalResponse,
32
+ stringifyContent
33
+ } from "./events/event.js";
19
34
  import { createEventActions } from "./events/event_actions.js";
35
+ import {
36
+ BaseExampleProvider,
37
+ isBaseExampleProvider
38
+ } from "./examples/base_example_provider.js";
20
39
  import { InMemoryMemoryService } from "./memory/in_memory_memory_service.js";
21
40
  import { BaseLlm, isBaseLlm } from "./models/base_llm.js";
22
41
  import { Gemini } from "./models/google_llm.js";
@@ -24,32 +43,45 @@ import { LLMRegistry } from "./models/registry.js";
24
43
  import { BasePlugin } from "./plugins/base_plugin.js";
25
44
  import { LoggingPlugin } from "./plugins/logging_plugin.js";
26
45
  import { PluginManager } from "./plugins/plugin_manager.js";
27
- import { getAskUserConfirmationFunctionCalls, InMemoryPolicyEngine, PolicyOutcome, REQUEST_CONFIRMATION_FUNCTION_CALL_NAME, SecurityPlugin } from "./plugins/security_plugin.js";
46
+ import {
47
+ InMemoryPolicyEngine,
48
+ PolicyOutcome,
49
+ REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
50
+ SecurityPlugin,
51
+ getAskUserConfirmationFunctionCalls
52
+ } from "./plugins/security_plugin.js";
28
53
  import { InMemoryRunner } from "./runner/in_memory_runner.js";
29
54
  import { Runner } from "./runner/runner.js";
30
55
  import { InMemorySessionService } from "./sessions/in_memory_session_service.js";
31
56
  import { createSession } from "./sessions/session.js";
32
57
  import { State } from "./sessions/state.js";
33
- import { AgentTool } from "./tools/agent_tool.js";
34
- import { BaseTool } from "./tools/base_tool.js";
58
+ import { AgentTool, isAgentTool } from "./tools/agent_tool.js";
59
+ import { BaseTool, isBaseTool } from "./tools/base_tool.js";
35
60
  import { BaseToolset } from "./tools/base_toolset.js";
36
- import { FunctionTool } from "./tools/function_tool.js";
37
- import { GOOGLE_SEARCH } from "./tools/google_search_tool.js";
61
+ import { FunctionTool, isFunctionTool } from "./tools/function_tool.js";
62
+ import { GOOGLE_SEARCH, GoogleSearchTool } from "./tools/google_search_tool.js";
38
63
  import { LongRunningFunctionTool } from "./tools/long_running_tool.js";
39
64
  import { ToolConfirmation } from "./tools/tool_confirmation.js";
40
65
  import { ToolContext } from "./tools/tool_context.js";
41
- import { LogLevel, setLogLevel } from "./utils/logger.js";
66
+ import { LogLevel, getLogger, setLogLevel, setLogger } from "./utils/logger.js";
42
67
  import { isGemini2OrAbove } from "./utils/model_name.js";
43
68
  import { zodObjectToSchema } from "./utils/simple_zod_to_json.js";
69
+ import { GoogleLLMVariant } from "./utils/variant_utils.js";
44
70
  import { version } from "./version.js";
45
71
  export * from "./artifacts/base_artifact_service.js";
46
72
  export * from "./memory/base_memory_service.js";
47
73
  export * from "./sessions/base_session_service.js";
48
74
  export * from "./tools/base_tool.js";
49
75
  export {
76
+ ActiveStreamingTool,
50
77
  AgentTool,
78
+ AuthCredentialTypes,
51
79
  BaseAgent,
80
+ BaseCodeExecutor,
81
+ BaseExampleProvider,
52
82
  BaseLlm,
83
+ BaseLlmRequestProcessor,
84
+ BaseLlmResponseProcessor,
53
85
  BasePlugin,
54
86
  BaseTool,
55
87
  BaseToolset,
@@ -58,6 +90,8 @@ export {
58
90
  FunctionTool,
59
91
  GOOGLE_SEARCH,
60
92
  Gemini,
93
+ GoogleLLMVariant,
94
+ GoogleSearchTool,
61
95
  InMemoryArtifactService,
62
96
  InMemoryMemoryService,
63
97
  InMemoryPolicyEngine,
@@ -75,6 +109,7 @@ export {
75
109
  PluginManager,
76
110
  PolicyOutcome,
77
111
  REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
112
+ ReadonlyContext,
78
113
  Runner,
79
114
  SecurityPlugin,
80
115
  SequentialAgent,
@@ -89,12 +124,22 @@ export {
89
124
  getAskUserConfirmationFunctionCalls,
90
125
  getFunctionCalls,
91
126
  getFunctionResponses,
127
+ getLogger,
92
128
  hasTrailingCodeExecutionResult,
129
+ isAgentTool,
93
130
  isBaseAgent,
131
+ isBaseExampleProvider,
94
132
  isBaseLlm,
133
+ isBaseTool,
95
134
  isFinalResponse,
135
+ isFunctionTool,
96
136
  isGemini2OrAbove,
137
+ isLlmAgent,
138
+ isLoopAgent,
139
+ isParallelAgent,
140
+ isSequentialAgent,
97
141
  setLogLevel,
142
+ setLogger,
98
143
  stringifyContent,
99
144
  version,
100
145
  zodObjectToSchema
@@ -66,9 +66,7 @@ const ASCII_LETTERS_AND_NUMBERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS
66
66
  function createNewEventId() {
67
67
  let id = "";
68
68
  for (let i = 0; i < 8; i++) {
69
- id += ASCII_LETTERS_AND_NUMBERS[Math.floor(
70
- Math.random() * ASCII_LETTERS_AND_NUMBERS.length
71
- )];
69
+ id += ASCII_LETTERS_AND_NUMBERS[Math.floor(Math.random() * ASCII_LETTERS_AND_NUMBERS.length)];
72
70
  }
73
71
  return id;
74
72
  }
@@ -3,8 +3,23 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ var _a;
7
+ const BASE_EXAMPLE_PROVIDER_SIGNATURE_SYMBOL = Symbol.for(
8
+ "google.adk.baseExampleProvider"
9
+ );
10
+ function isBaseExampleProvider(obj) {
11
+ return typeof obj === "object" && obj !== null && BASE_EXAMPLE_PROVIDER_SIGNATURE_SYMBOL in obj && obj[BASE_EXAMPLE_PROVIDER_SIGNATURE_SYMBOL] === true;
12
+ }
13
+ _a = BASE_EXAMPLE_PROVIDER_SIGNATURE_SYMBOL;
6
14
  class BaseExampleProvider {
15
+ constructor() {
16
+ /**
17
+ * A unique symbol to identify ADK example provider classes.
18
+ */
19
+ this[_a] = true;
20
+ }
7
21
  }
8
22
  export {
9
- BaseExampleProvider
23
+ BaseExampleProvider,
24
+ isBaseExampleProvider
10
25
  };
@@ -3,7 +3,9 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { BaseExampleProvider } from "./base_example_provider.js";
6
+ import {
7
+ isBaseExampleProvider
8
+ } from "./base_example_provider.js";
7
9
  const EXAMPLES_INTRO = "<EXAMPLES>\nBegin few-shot\nThe following are examples of user queries and model responses using the available tools.\n\n";
8
10
  const EXAMPLES_END = "End few-shot\n<EXAMPLES>";
9
11
  const EXAMPLE_START = "EXAMPLE {}:\nBegin example\n";
@@ -65,7 +67,7 @@ function buildExampleSi(examples, query, model) {
65
67
  if (Array.isArray(examples)) {
66
68
  return convertExamplesToText(examples, model);
67
69
  }
68
- if (examples instanceof BaseExampleProvider) {
70
+ if (isBaseExampleProvider(examples)) {
69
71
  return convertExamplesToText(examples.getExamples(query), model);
70
72
  }
71
73
  throw new Error("Invalid example configuration");