@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
@@ -13,8 +13,17 @@ import { BaseMemoryService } from '../memory/base_memory_service.js';
13
13
  import { BasePlugin } from '../plugins/base_plugin.js';
14
14
  import { PluginManager } from '../plugins/plugin_manager.js';
15
15
  import { BaseSessionService } from '../sessions/base_session_service.js';
16
- interface RunnerInput {
16
+ /**
17
+ * The configuration parameters for the Runner.
18
+ */
19
+ export interface RunnerConfig {
20
+ /**
21
+ * The application name.
22
+ */
17
23
  appName: string;
24
+ /**
25
+ * The agent to run.
26
+ */
18
27
  agent: BaseAgent;
19
28
  plugins?: BasePlugin[];
20
29
  artifactService?: BaseArtifactService;
@@ -30,23 +39,23 @@ export declare class Runner {
30
39
  readonly sessionService: BaseSessionService;
31
40
  readonly memoryService?: BaseMemoryService;
32
41
  readonly credentialService?: BaseCredentialService;
33
- constructor(input: RunnerInput);
42
+ constructor(input: RunnerConfig);
34
43
  /**
35
44
  * Runs the agent with the given message, and returns an async generator of
36
45
  * events.
37
46
  *
38
- * @param userId The user ID of the session.
39
- * @param sessionId The session ID of the session.
40
- * @param newMessage A new message to append to the session.
41
- * @param stateDelta An optional state delta to apply to the session.
42
- * @param runConfig The run config for the agent.
47
+ * @param params.userId The user ID of the session.
48
+ * @param params.sessionId The session ID of the session.
49
+ * @param params.newMessage A new message to append to the session.
50
+ * @param params.stateDelta An optional state delta to apply to the session.
51
+ * @param params.runConfig The run config for the agent.
43
52
  * @yields The events generated by the agent.
44
53
  */
45
- runAsync({ userId, sessionId, newMessage, stateDelta, runConfig, }: {
54
+ runAsync(params: {
46
55
  userId: string;
47
56
  sessionId: string;
48
57
  newMessage: Content;
49
- stateDelta?: Record<string, any>;
58
+ stateDelta?: Record<string, unknown>;
50
59
  runConfig?: RunConfig;
51
60
  }): AsyncGenerator<Event, void, undefined>;
52
61
  /**
@@ -77,4 +86,3 @@ export declare class Runner {
77
86
  */
78
87
  private isRoutableLlmAgent;
79
88
  }
80
- export {};
@@ -18,10 +18,10 @@ export declare class InMemorySessionService extends BaseSessionService {
18
18
  * A map from app name to a map from key to the value.
19
19
  */
20
20
  private appState;
21
- createSession({ appName, userId, state, sessionId }: CreateSessionRequest): Promise<Session>;
22
- getSession({ appName, userId, sessionId, config }: GetSessionRequest): Promise<Session | undefined>;
23
- listSessions({ appName, userId }: ListSessionsRequest): Promise<ListSessionsResponse>;
24
- deleteSession({ appName, userId, sessionId }: DeleteSessionRequest): Promise<void>;
25
- appendEvent({ session, event }: AppendEventRequest): Promise<Event>;
21
+ createSession({ appName, userId, state, sessionId, }: CreateSessionRequest): Promise<Session>;
22
+ getSession({ appName, userId, sessionId, config, }: GetSessionRequest): Promise<Session | undefined>;
23
+ listSessions({ appName, userId, }: ListSessionsRequest): Promise<ListSessionsResponse>;
24
+ deleteSession({ appName, userId, sessionId, }: DeleteSessionRequest): Promise<void>;
25
+ appendEvent({ session, event, }: AppendEventRequest): Promise<Event>;
26
26
  private mergeState;
27
27
  }
@@ -3,9 +3,9 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ import { Resource } from '@opentelemetry/resources';
6
7
  import { LogRecordProcessor } from '@opentelemetry/sdk-logs';
7
8
  import { MetricReader } from '@opentelemetry/sdk-metrics';
8
- import { Resource } from '@opentelemetry/resources';
9
9
  import { SpanProcessor } from '@opentelemetry/sdk-trace-base';
10
10
  export interface OtelExportersConfig {
11
11
  enableTracing?: boolean;
@@ -101,11 +101,12 @@ export interface TraceSendDataParams {
101
101
  */
102
102
  export declare function traceSendData({ invocationContext, eventId, data, }: TraceSendDataParams): void;
103
103
  /**
104
- * Binds an async generator to OpenTelemetry context for trace propagation.
105
- * This is a temporary solution.
106
- * @param ctx - The OpenTelemetry context to bind the generator to
107
- * @param generator - The async generator to be bound to the context
104
+ * Runs an async generator function with both OTEL context and JavaScript 'this' context.
108
105
  *
109
- * @returns A new async generator that executes all operations within the provided context
106
+ * @param otelContext - The OpenTelemetry context to bind the generator to
107
+ * @param generatorFnContext - The 'this' context to bind to the generator function
108
+ * @param generatorFn - The generator function to execute
109
+ *
110
+ * @returns A new async generator that executes within both contexts
110
111
  */
111
- export declare function bindAsyncGenerator<T = unknown, TReturn = any, TNext = unknown>(ctx: Context, generator: AsyncGenerator<T, TReturn, TNext>): AsyncGenerator<T, TReturn, TNext>;
112
+ export declare function runAsyncGeneratorWithOtelContext<TThis, T>(otelContext: Context, generatorFnContext: TThis, generatorFn: (this: TThis) => AsyncGenerator<T, void, void>): AsyncGenerator<T, void, void>;
@@ -19,6 +19,17 @@ export interface AgentToolConfig {
19
19
  */
20
20
  skipSummarization?: boolean;
21
21
  }
22
+ /**
23
+ * A unique symbol to identify ADK agent classes.
24
+ * Defined once and shared by all BaseTool instances.
25
+ */
26
+ declare const AGENT_TOOL_SIGNATURE_SYMBOL: unique symbol;
27
+ /**
28
+ * Type guard to check if an object is an instance of BaseTool.
29
+ * @param obj The object to check.
30
+ * @returns True if the object is an instance of BaseTool, false otherwise.
31
+ */
32
+ export declare function isAgentTool(obj: unknown): obj is AgentTool;
22
33
  /**
23
34
  * A tool that wraps an agent.
24
35
  *
@@ -29,9 +40,12 @@ export interface AgentToolConfig {
29
40
  * @param config: The configuration of the agent tool.
30
41
  */
31
42
  export declare class AgentTool extends BaseTool {
43
+ /** A unique symbol to identify ADK agent tool class. */
44
+ readonly [AGENT_TOOL_SIGNATURE_SYMBOL] = true;
32
45
  private readonly agent;
33
46
  private readonly skipSummarization;
34
47
  constructor(config: AgentToolConfig);
35
48
  _getDeclaration(): FunctionDeclaration;
36
- runAsync({ args, toolContext }: RunAsyncToolRequest): Promise<unknown>;
49
+ runAsync({ args, toolContext, }: RunAsyncToolRequest): Promise<unknown>;
37
50
  }
51
+ export {};
@@ -28,10 +28,23 @@ export interface BaseToolParams {
28
28
  description: string;
29
29
  isLongRunning?: boolean;
30
30
  }
31
+ /**
32
+ * A unique symbol to identify ADK agent classes.
33
+ * Defined once and shared by all BaseTool instances.
34
+ */
35
+ declare const BASE_TOOL_SIGNATURE_SYMBOL: unique symbol;
36
+ /**
37
+ * Type guard to check if an object is an instance of BaseTool.
38
+ * @param obj The object to check.
39
+ * @returns True if the object is an instance of BaseTool, false otherwise.
40
+ */
41
+ export declare function isBaseTool(obj: unknown): obj is BaseTool;
31
42
  /**
32
43
  * The base class for all tools.
33
44
  */
34
45
  export declare abstract class BaseTool {
46
+ /** A unique symbol to identify ADK base tool class. */
47
+ readonly [BASE_TOOL_SIGNATURE_SYMBOL] = true;
35
48
  readonly name: string;
36
49
  readonly description: string;
37
50
  readonly isLongRunning: boolean;
@@ -76,9 +89,10 @@ export declare abstract class BaseTool {
76
89
  *
77
90
  * @param request The request to process the LLM request.
78
91
  */
79
- processLlmRequest({ toolContext, llmRequest }: ToolProcessLlmRequest): Promise<void>;
92
+ processLlmRequest({ llmRequest }: ToolProcessLlmRequest): Promise<void>;
80
93
  /**
81
94
  * The Google API LLM variant to use.
82
95
  */
83
96
  get apiVariant(): import("../utils/variant_utils.js").GoogleLLMVariant;
84
97
  }
98
+ export {};
@@ -60,5 +60,6 @@ export declare abstract class BaseToolset {
60
60
  * @param toolContext The context of the tool.
61
61
  * @param llmRequest The outgoing LLM request, mutable this method.
62
62
  */
63
- processLlmRequest(toolContext: ToolContext, llmRequest: LlmRequest): Promise<void>;
63
+ processLlmRequest(toolContext: ToolContext, // eslint-disable-line @typescript-eslint/no-unused-vars
64
+ llmRequest: LlmRequest): Promise<void>;
64
65
  }
@@ -4,7 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { Part } from '@google/genai';
7
- import { BaseArtifactService, DeleteArtifactRequest, ListArtifactKeysRequest, ListVersionsRequest, LoadArtifactRequest, SaveArtifactRequest } from '../artifacts/base_artifact_service.js';
7
+ import { BaseArtifactService, DeleteArtifactRequest, ListVersionsRequest, LoadArtifactRequest, SaveArtifactRequest } from '../artifacts/base_artifact_service.js';
8
8
  import { ToolContext } from './tool_context.js';
9
9
  /**
10
10
  * Artifact service that forwards to the parent tool context.
@@ -15,7 +15,7 @@ export declare class ForwardingArtifactService implements BaseArtifactService {
15
15
  constructor(toolContext: ToolContext);
16
16
  saveArtifact(request: SaveArtifactRequest): Promise<number>;
17
17
  loadArtifact(request: LoadArtifactRequest): Promise<Part | undefined>;
18
- listArtifactKeys(request: ListArtifactKeysRequest): Promise<string[]>;
18
+ listArtifactKeys(): Promise<string[]>;
19
19
  deleteArtifact(request: DeleteArtifactRequest): Promise<void>;
20
20
  listVersions(request: ListVersionsRequest): Promise<number[]>;
21
21
  }
@@ -4,15 +4,16 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { FunctionDeclaration, Schema } from '@google/genai';
7
- import { type infer as zInfer, ZodObject, type ZodRawShape } from 'zod';
7
+ import { z as z3 } from 'zod/v3';
8
+ import { z as z4 } from 'zod/v4';
8
9
  import { BaseTool, RunAsyncToolRequest } from './base_tool.js';
9
10
  import { ToolContext } from './tool_context.js';
10
11
  /**
11
12
  * Input parameters of the function tool.
12
13
  */
13
- export type ToolInputParameters = undefined | ZodObject<ZodRawShape> | Schema;
14
- export type ToolExecuteArgument<TParameters extends ToolInputParameters> = TParameters extends ZodObject<infer T, infer U, infer V> ? zInfer<ZodObject<T, U, V>> : TParameters extends Schema ? unknown : string;
15
- type ToolExecuteFunction<TParameters extends ToolInputParameters> = (input: ToolExecuteArgument<TParameters>, tool_context?: ToolContext) => Promise<unknown> | unknown;
14
+ export type ToolInputParameters = z3.ZodObject<z3.ZodRawShape> | z4.ZodObject<z4.ZodRawShape> | Schema | undefined;
15
+ export type ToolExecuteArgument<TParameters extends ToolInputParameters> = TParameters extends z3.ZodObject<infer T, infer U, infer V> ? z3.infer<z3.ZodObject<T, U, V>> : TParameters extends z4.ZodObject<infer T> ? z4.infer<z4.ZodObject<T>> : TParameters extends Schema ? unknown : string;
16
+ export type ToolExecuteFunction<TParameters extends ToolInputParameters> = (input: ToolExecuteArgument<TParameters>, tool_context?: ToolContext) => Promise<unknown> | unknown;
16
17
  /**
17
18
  * The configuration options for creating a function-based tool.
18
19
  * The `name`, `description` and `parameters` fields are used to generate the
@@ -28,7 +29,20 @@ export type ToolOptions<TParameters extends ToolInputParameters> = {
28
29
  execute: ToolExecuteFunction<TParameters>;
29
30
  isLongRunning?: boolean;
30
31
  };
32
+ /**
33
+ * A unique symbol to identify ADK agent classes.
34
+ * Defined once and shared by all BaseTool instances.
35
+ */
36
+ declare const FUNCTION_TOOL_SIGNATURE_SYMBOL: unique symbol;
37
+ /**
38
+ * Type guard to check if an object is an instance of BaseTool.
39
+ * @param obj The object to check.
40
+ * @returns True if the object is an instance of BaseTool, false otherwise.
41
+ */
42
+ export declare function isFunctionTool(obj: unknown): obj is FunctionTool;
31
43
  export declare class FunctionTool<TParameters extends ToolInputParameters = undefined> extends BaseTool {
44
+ /** A unique symbol to identify ADK function tool class. */
45
+ readonly [FUNCTION_TOOL_SIGNATURE_SYMBOL] = true;
32
46
  private readonly execute;
33
47
  private readonly parameters?;
34
48
  /**
@@ -1,4 +1,4 @@
1
- import { BaseTool, RunAsyncToolRequest, ToolProcessLlmRequest } from './base_tool.js';
1
+ import { BaseTool, ToolProcessLlmRequest } from './base_tool.js';
2
2
  /**
3
3
  * A built-in tool that is automatically invoked by Gemini 2 models to retrieve
4
4
  * search results from Google Search.
@@ -6,13 +6,12 @@ import { BaseTool, RunAsyncToolRequest, ToolProcessLlmRequest } from './base_too
6
6
  * This tool operates internally within the model and does not require or
7
7
  * perform local code execution.
8
8
  */
9
- declare class GoogleSearchTool extends BaseTool {
9
+ export declare class GoogleSearchTool extends BaseTool {
10
10
  constructor();
11
- runAsync(request: RunAsyncToolRequest): Promise<unknown>;
12
- processLlmRequest({ toolContext, llmRequest }: ToolProcessLlmRequest): Promise<void>;
11
+ runAsync(): Promise<unknown>;
12
+ processLlmRequest({ llmRequest, }: ToolProcessLlmRequest): Promise<void>;
13
13
  }
14
14
  /**
15
- * A global instance of GoogleSearchTool.
15
+ * A global instance of {@link GoogleSearchTool}.
16
16
  */
17
17
  export declare const GOOGLE_SEARCH: GoogleSearchTool;
18
- export {};
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
7
7
  import { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js';
8
+ import { StreamableHTTPClientTransportOptions } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
8
9
  /**
9
10
  * Defines the parameters for establishing a connection to an MCP server using
10
11
  * standard input/output (stdio). This is typically used for running MCP servers
@@ -13,7 +14,7 @@ import { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js
13
14
  export interface StdioConnectionParams {
14
15
  type: 'StdioConnectionParams';
15
16
  serverParams: StdioServerParameters;
16
- timeout?: Number;
17
+ timeout?: number;
17
18
  }
18
19
  /**
19
20
  * Defines the parameters for establishing a connection to an MCP server over
@@ -28,10 +29,16 @@ export interface StdioConnectionParams {
28
29
  export interface StreamableHTTPConnectionParams {
29
30
  type: 'StreamableHTTPConnectionParams';
30
31
  url: string;
32
+ /**
33
+ * @deprecated
34
+ * Use transportOptions.requestInit.headers instead.
35
+ * This field will be ignored if transportOptions is provided even if no headers are specified in transportOptions.
36
+ */
31
37
  header?: Record<string, unknown>;
32
- timeout?: Number;
33
- sseReadTimeout?: Number;
38
+ timeout?: number;
39
+ sseReadTimeout?: number;
34
40
  terminateOnClose?: boolean;
41
+ transportOptions?: StreamableHTTPClientTransportOptions;
35
42
  }
36
43
  /**
37
44
  * A union of all supported MCP connection parameter types.
@@ -3,7 +3,6 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { ReadonlyContext } from '../../agents/readonly_context.js';
7
6
  import { BaseTool } from '../base_tool.js';
8
7
  import { BaseToolset, ToolPredicate } from '../base_toolset.js';
9
8
  import { MCPConnectionParams } from './mcp_session_manager.js';
@@ -34,6 +33,6 @@ import { MCPConnectionParams } from './mcp_session_manager.js';
34
33
  export declare class MCPToolset extends BaseToolset {
35
34
  private readonly mcpSessionManager;
36
35
  constructor(connectionParams: MCPConnectionParams, toolFilter?: ToolPredicate | string[]);
37
- getTools(context?: ReadonlyContext): Promise<BaseTool[]>;
36
+ getTools(): Promise<BaseTool[]>;
38
37
  close(): Promise<void>;
39
38
  }
@@ -24,7 +24,7 @@ export declare class ToolContext extends CallbackContext {
24
24
  * @param params.toolConfirmation The tool confirmation of the current tool
25
25
  * call.
26
26
  */
27
- constructor({ invocationContext, eventActions, functionCallId, toolConfirmation, }: {
27
+ constructor(params: {
28
28
  invocationContext: InvocationContext;
29
29
  eventActions?: EventActions;
30
30
  functionCallId?: string;
@@ -5,19 +5,11 @@
5
5
  */
6
6
  import { Schema } from '@google/genai';
7
7
  import { z } from 'zod';
8
- declare const MCPToolSchema: z.ZodObject<{
8
+ declare const MCPToolSchemaObject: z.ZodObject<{
9
9
  type: z.ZodLiteral<"object">;
10
10
  properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
11
- required: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
12
- }, "strip", z.ZodTypeAny, {
13
- type: "object";
14
- properties?: Record<string, unknown> | undefined;
15
- required?: string[] | undefined;
16
- }, {
17
- type: "object";
18
- properties?: Record<string, unknown> | undefined;
19
- required?: string[] | undefined;
20
- }>;
21
- type MCPToolSchema = z.infer<typeof MCPToolSchema>;
11
+ required: z.ZodOptional<z.ZodArray<z.ZodString>>;
12
+ }, z.core.$strip>;
13
+ type MCPToolSchema = z.infer<typeof MCPToolSchemaObject>;
22
14
  export declare function toGeminiSchema(mcpSchema?: MCPToolSchema): Schema | undefined;
23
15
  export {};
@@ -25,17 +25,18 @@ export interface Logger {
25
25
  */
26
26
  export declare function setLogLevel(level: LogLevel): void;
27
27
  /**
28
- * Simple logger class for ADK.
28
+ * Sets a custom logger for ADK, or null to disable logging.
29
29
  */
30
- declare class SimpleLogger implements Logger {
31
- log(level: LogLevel, ...args: unknown[]): void;
32
- debug(...args: unknown[]): void;
33
- info(...args: unknown[]): void;
34
- warn(...args: unknown[]): void;
35
- error(...args: unknown[]): void;
36
- }
30
+ export declare function setLogger(customLogger: Logger | null): void;
31
+ /**
32
+ * Gets the current logger instance.
33
+ */
34
+ export declare function getLogger(): Logger;
35
+ /**
36
+ * Resets the logger to the default SimpleLogger.
37
+ */
38
+ export declare function resetLogger(): void;
37
39
  /**
38
40
  * The logger instance for ADK.
39
41
  */
40
- export declare const logger: SimpleLogger;
41
- export {};
42
+ export declare const logger: Logger;
@@ -4,9 +4,10 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { Schema } from '@google/genai';
7
- import { ZodObject } from 'zod';
7
+ import { z as z3 } from 'zod/v3';
8
+ import { z as z4 } from 'zod/v4';
8
9
  /**
9
- * Returns true if the given object is a V3 ZodObject.
10
+ * Returns true if the given object is a ZodObject (supports both Zod v3 and v4).
10
11
  */
11
- export declare function isZodObject(obj: unknown): obj is ZodObject<any>;
12
- export declare function zodObjectToSchema(schema: ZodObject<any>): Schema;
12
+ export declare function isZodObject(obj: unknown): obj is z3.ZodObject<z3.ZodRawShape> | z4.ZodObject<z4.ZodRawShape>;
13
+ export declare function zodObjectToSchema(schema: z3.ZodObject<z3.ZodRawShape> | z4.ZodObject<z4.ZodRawShape>): Schema;
@@ -3,4 +3,4 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- export declare const version = "0.2.4";
6
+ export declare const version = "0.3.0";
@@ -5,6 +5,9 @@ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
6
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
7
  var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
8
+ var __typeError = (msg) => {
9
+ throw TypeError(msg);
10
+ };
8
11
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
12
  var __spreadValues = (a, b) => {
10
13
  for (var prop in b || (b = {}))
@@ -33,6 +36,34 @@ var __asyncGenerator = (__this, __arguments, generator) => {
33
36
  }, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
34
37
  return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
35
38
  };
39
+ var __yieldStar = (value) => {
40
+ var obj = value[__knownSymbol("asyncIterator")], isAwait = false, method, it = {};
41
+ if (obj == null) {
42
+ obj = value[__knownSymbol("iterator")]();
43
+ method = (k) => it[k] = (x) => obj[k](x);
44
+ } else {
45
+ obj = obj.call(value);
46
+ method = (k) => it[k] = (v) => {
47
+ if (isAwait) {
48
+ isAwait = false;
49
+ if (k === "throw") throw v;
50
+ return v;
51
+ }
52
+ isAwait = true;
53
+ return {
54
+ done: false,
55
+ value: new __await(new Promise((resolve) => {
56
+ var x = obj[k](v);
57
+ if (!(x instanceof Object)) __typeError("Object expected");
58
+ resolve(x);
59
+ }), 1)
60
+ };
61
+ };
62
+ }
63
+ return it[__knownSymbol("iterator")] = () => it, method("next"), "throw" in obj ? method("throw") : it.throw = (x) => {
64
+ throw x;
65
+ }, "return" in obj && method("return"), it;
66
+ };
36
67
  var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
37
68
  /**
38
69
  * @license
@@ -40,8 +71,13 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
40
71
  * SPDX-License-Identifier: Apache-2.0
41
72
  */
42
73
  var _a;
43
- import { trace } from "@opentelemetry/api";
74
+ import { context, trace } from "@opentelemetry/api";
44
75
  import { createEvent } from "../events/event.js";
76
+ import {
77
+ runAsyncGeneratorWithOtelContext,
78
+ traceAgentInvocation,
79
+ tracer
80
+ } from "../telemetry/tracing.js";
45
81
  import { CallbackContext } from "./callback_context.js";
46
82
  import { InvocationContext } from "./invocation_context.js";
47
83
  const BASE_AGENT_SIGNATURE_SYMBOL = Symbol.for("google.adk.baseAgent");
@@ -59,11 +95,19 @@ class BaseAgent {
59
95
  this.description = config.description;
60
96
  this.parentAgent = config.parentAgent;
61
97
  this.subAgents = config.subAgents || [];
62
- this.rootAgent = getRootAgent(this);
63
- this.beforeAgentCallback = getCannonicalCallback(config.beforeAgentCallback);
98
+ this.beforeAgentCallback = getCannonicalCallback(
99
+ config.beforeAgentCallback
100
+ );
64
101
  this.afterAgentCallback = getCannonicalCallback(config.afterAgentCallback);
65
102
  this.setParentAgentForSubAgents();
66
103
  }
104
+ /**
105
+ * Root agent of this agent.
106
+ * Computed dynamically by traversing up the parent chain.
107
+ */
108
+ get rootAgent() {
109
+ return getRootAgent(this);
110
+ }
67
111
  /**
68
112
  * Entry method to run an agent via text-based conversation.
69
113
  *
@@ -73,38 +117,48 @@ class BaseAgent {
73
117
  */
74
118
  runAsync(parentContext) {
75
119
  return __asyncGenerator(this, null, function* () {
76
- const span = trace.getTracer("gcp.vertex.agent").startSpan("agent_run [".concat(this.name, "]"));
120
+ const span = tracer.startSpan("invoke_agent ".concat(this.name));
121
+ const ctx = trace.setSpan(context.active(), span);
77
122
  try {
78
- const context = this.createInvocationContext(parentContext);
79
- const beforeAgentCallbackEvent = yield new __await(this.handleBeforeAgentCallback(context));
80
- if (beforeAgentCallbackEvent) {
81
- yield beforeAgentCallbackEvent;
82
- }
83
- if (context.endInvocation) {
84
- return;
85
- }
86
- try {
87
- for (var iter = __forAwait(this.runAsyncImpl(context)), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
88
- const event = temp.value;
89
- yield event;
90
- }
91
- } catch (temp) {
92
- error = [temp];
93
- } finally {
94
- try {
95
- more && (temp = iter.return) && (yield new __await(temp.call(iter)));
96
- } finally {
97
- if (error)
98
- throw error[0];
123
+ yield* __yieldStar(runAsyncGeneratorWithOtelContext(
124
+ ctx,
125
+ this,
126
+ function() {
127
+ return __asyncGenerator(this, null, function* () {
128
+ const context2 = this.createInvocationContext(parentContext);
129
+ const beforeAgentCallbackEvent = yield new __await(this.handleBeforeAgentCallback(context2));
130
+ if (beforeAgentCallbackEvent) {
131
+ yield beforeAgentCallbackEvent;
132
+ }
133
+ if (context2.endInvocation) {
134
+ return;
135
+ }
136
+ traceAgentInvocation({ agent: this, invocationContext: context2 });
137
+ try {
138
+ for (var iter = __forAwait(this.runAsyncImpl(context2)), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
139
+ const event = temp.value;
140
+ yield event;
141
+ }
142
+ } catch (temp) {
143
+ error = [temp];
144
+ } finally {
145
+ try {
146
+ more && (temp = iter.return) && (yield new __await(temp.call(iter)));
147
+ } finally {
148
+ if (error)
149
+ throw error[0];
150
+ }
151
+ }
152
+ if (context2.endInvocation) {
153
+ return;
154
+ }
155
+ const afterAgentCallbackEvent = yield new __await(this.handleAfterAgentCallback(context2));
156
+ if (afterAgentCallbackEvent) {
157
+ yield afterAgentCallbackEvent;
158
+ }
159
+ });
99
160
  }
100
- }
101
- if (context.endInvocation) {
102
- return;
103
- }
104
- const afterAgentCallbackEvent = yield new __await(this.handleAfterAgentCallback(context));
105
- if (afterAgentCallbackEvent) {
106
- yield afterAgentCallbackEvent;
107
- }
161
+ ));
108
162
  } finally {
109
163
  span.end();
110
164
  }
@@ -119,8 +173,17 @@ class BaseAgent {
119
173
  */
120
174
  runLive(parentContext) {
121
175
  return __asyncGenerator(this, null, function* () {
122
- const span = trace.getTracer("gcp.vertex.agent").startSpan("agent_run [".concat(this.name, "]"));
176
+ const span = tracer.startSpan("invoke_agent ".concat(this.name));
177
+ const ctx = trace.setSpan(context.active(), span);
123
178
  try {
179
+ yield* __yieldStar(runAsyncGeneratorWithOtelContext(
180
+ ctx,
181
+ this,
182
+ function() {
183
+ return __asyncGenerator(this, null, function* () {
184
+ });
185
+ }
186
+ ));
124
187
  throw new Error("Live mode is not implemented yet.");
125
188
  } finally {
126
189
  span.end();
@@ -237,7 +300,9 @@ class BaseAgent {
237
300
  setParentAgentForSubAgents() {
238
301
  for (const subAgent of this.subAgents) {
239
302
  if (subAgent.parentAgent) {
240
- throw new Error('Agent "'.concat(subAgent.name, '" already has a parent agent, current parent: "').concat(subAgent.parentAgent.name, '", trying to add: "').concat(this.name, '"'));
303
+ throw new Error(
304
+ 'Agent "'.concat(subAgent.name, '" already has a parent agent, current parent: "').concat(subAgent.parentAgent.name, '", trying to add: "').concat(this.name, '"')
305
+ );
241
306
  }
242
307
  subAgent.parentAgent = this;
243
308
  }
@@ -245,7 +310,9 @@ class BaseAgent {
245
310
  }
246
311
  function validateAgentName(name) {
247
312
  if (!isIdentifier(name)) {
248
- throw new Error('Found invalid agent name: "'.concat(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.'));
313
+ throw new Error(
314
+ 'Found invalid agent name: "'.concat(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.')
315
+ );
249
316
  }
250
317
  if (name === "user") {
251
318
  throw new Error(
@@ -7,7 +7,10 @@ import { createEventActions } from "../events/event_actions.js";
7
7
  import { State } from "../sessions/state.js";
8
8
  import { ReadonlyContext } from "./readonly_context.js";
9
9
  class CallbackContext extends ReadonlyContext {
10
- constructor({ invocationContext, eventActions }) {
10
+ constructor({
11
+ invocationContext,
12
+ eventActions
13
+ }) {
11
14
  super(invocationContext);
12
15
  this.eventActions = eventActions || createEventActions();
13
16
  this._state = new State(