@google/adk 0.2.5 → 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 (166) hide show
  1. package/dist/cjs/agents/base_agent.js +43 -21
  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/llm_agent.js +59 -33
  6. package/dist/cjs/agents/loop_agent.js +2 -1
  7. package/dist/cjs/agents/parallel_agent.js +3 -4
  8. package/dist/cjs/artifacts/gcs_artifact_service.js +28 -20
  9. package/dist/cjs/artifacts/in_memory_artifact_service.js +18 -4
  10. package/dist/cjs/auth/auth_handler.js +3 -1
  11. package/dist/cjs/code_executors/base_code_executor.js +3 -1
  12. package/dist/cjs/code_executors/built_in_code_executor.js +7 -3
  13. package/dist/cjs/code_executors/code_executor_context.js +5 -5
  14. package/dist/cjs/common.js +4 -0
  15. package/dist/cjs/events/event.js +1 -3
  16. package/dist/cjs/index.js +19 -19
  17. package/dist/cjs/index.js.map +4 -4
  18. package/dist/cjs/memory/in_memory_memory_service.js +3 -1
  19. package/dist/cjs/models/base_llm.js +8 -4
  20. package/dist/cjs/models/gemini_llm_connection.js +1 -0
  21. package/dist/cjs/models/google_llm.js +3 -3
  22. package/dist/cjs/plugins/base_plugin.js +12 -0
  23. package/dist/cjs/plugins/logging_plugin.js +50 -13
  24. package/dist/cjs/plugins/plugin_manager.js +56 -24
  25. package/dist/cjs/plugins/security_plugin.js +1 -1
  26. package/dist/cjs/runner/runner.js +110 -95
  27. package/dist/cjs/sessions/in_memory_session_service.js +38 -14
  28. package/dist/cjs/telemetry/google_cloud.js +7 -9
  29. package/dist/cjs/telemetry/setup.js +15 -7
  30. package/dist/cjs/telemetry/tracing.js +37 -15
  31. package/dist/cjs/tools/agent_tool.js +8 -4
  32. package/dist/cjs/tools/base_tool.js +4 -2
  33. package/dist/cjs/tools/forwarding_artifact_service.js +1 -1
  34. package/dist/cjs/tools/function_tool.js +1 -2
  35. package/dist/cjs/tools/google_search_tool.js +1 -2
  36. package/dist/cjs/tools/mcp/mcp_session_manager.js +16 -10
  37. package/dist/cjs/tools/mcp/mcp_tool.js +1 -3
  38. package/dist/cjs/tools/mcp/mcp_toolset.js +1 -1
  39. package/dist/cjs/utils/env_aware_utils.js +1 -1
  40. package/dist/cjs/utils/gemini_schema_util.js +9 -4
  41. package/dist/cjs/utils/logger.js +47 -3
  42. package/dist/cjs/utils/simple_zod_to_json.js +100 -141
  43. package/dist/cjs/utils/variant_utils.js +1 -1
  44. package/dist/cjs/version.js +1 -1
  45. package/dist/esm/agents/base_agent.js +48 -22
  46. package/dist/esm/agents/callback_context.js +4 -1
  47. package/dist/esm/agents/content_processor_utils.js +25 -9
  48. package/dist/esm/agents/functions.js +83 -29
  49. package/dist/esm/agents/llm_agent.js +63 -33
  50. package/dist/esm/agents/loop_agent.js +2 -1
  51. package/dist/esm/agents/parallel_agent.js +3 -4
  52. package/dist/esm/artifacts/gcs_artifact_service.js +28 -20
  53. package/dist/esm/artifacts/in_memory_artifact_service.js +18 -4
  54. package/dist/esm/auth/auth_handler.js +3 -1
  55. package/dist/esm/code_executors/base_code_executor.js +3 -1
  56. package/dist/esm/code_executors/built_in_code_executor.js +7 -3
  57. package/dist/esm/code_executors/code_executor_context.js +5 -5
  58. package/dist/esm/common.js +3 -1
  59. package/dist/esm/events/event.js +1 -3
  60. package/dist/esm/index.js +19 -19
  61. package/dist/esm/index.js.map +4 -4
  62. package/dist/esm/memory/in_memory_memory_service.js +3 -1
  63. package/dist/esm/models/base_llm.js +8 -4
  64. package/dist/esm/models/gemini_llm_connection.js +1 -0
  65. package/dist/esm/models/google_llm.js +8 -4
  66. package/dist/esm/plugins/base_plugin.js +12 -0
  67. package/dist/esm/plugins/logging_plugin.js +55 -14
  68. package/dist/esm/plugins/plugin_manager.js +56 -24
  69. package/dist/esm/plugins/security_plugin.js +1 -1
  70. package/dist/esm/runner/runner.js +114 -96
  71. package/dist/esm/sessions/in_memory_session_service.js +41 -15
  72. package/dist/esm/telemetry/google_cloud.js +7 -9
  73. package/dist/esm/telemetry/setup.js +23 -9
  74. package/dist/esm/telemetry/tracing.js +37 -15
  75. package/dist/esm/tools/agent_tool.js +8 -4
  76. package/dist/esm/tools/base_tool.js +4 -2
  77. package/dist/esm/tools/forwarding_artifact_service.js +1 -1
  78. package/dist/esm/tools/function_tool.js +1 -2
  79. package/dist/esm/tools/google_search_tool.js +2 -5
  80. package/dist/esm/tools/long_running_tool.js +3 -1
  81. package/dist/esm/tools/mcp/mcp_session_manager.js +22 -12
  82. package/dist/esm/tools/mcp/mcp_tool.js +1 -3
  83. package/dist/esm/tools/mcp/mcp_toolset.js +1 -1
  84. package/dist/esm/utils/env_aware_utils.js +1 -1
  85. package/dist/esm/utils/gemini_schema_util.js +9 -4
  86. package/dist/esm/utils/logger.js +43 -2
  87. package/dist/esm/utils/simple_zod_to_json.js +102 -141
  88. package/dist/esm/utils/variant_utils.js +1 -1
  89. package/dist/esm/version.js +1 -1
  90. package/dist/types/agents/base_agent.d.ts +2 -1
  91. package/dist/types/agents/callback_context.d.ts +1 -1
  92. package/dist/types/agents/llm_agent.d.ts +1 -1
  93. package/dist/types/agents/loop_agent.d.ts +1 -1
  94. package/dist/types/agents/parallel_agent.d.ts +1 -1
  95. package/dist/types/artifacts/in_memory_artifact_service.d.ts +3 -3
  96. package/dist/types/code_executors/built_in_code_executor.d.ts +1 -1
  97. package/dist/types/code_executors/code_executor_context.d.ts +2 -4
  98. package/dist/types/common.d.ts +2 -1
  99. package/dist/types/index.d.ts +3 -3
  100. package/dist/types/models/base_llm_connection.d.ts +1 -1
  101. package/dist/types/models/llm_response.d.ts +1 -1
  102. package/dist/types/plugins/logging_plugin.d.ts +12 -12
  103. package/dist/types/plugins/plugin_manager.d.ts +12 -12
  104. package/dist/types/plugins/security_plugin.d.ts +1 -1
  105. package/dist/types/runner/runner.d.ts +1 -1
  106. package/dist/types/sessions/in_memory_session_service.d.ts +5 -5
  107. package/dist/types/telemetry/setup.d.ts +1 -1
  108. package/dist/types/telemetry/tracing.d.ts +7 -6
  109. package/dist/types/tools/agent_tool.d.ts +1 -1
  110. package/dist/types/tools/base_tool.d.ts +1 -1
  111. package/dist/types/tools/base_toolset.d.ts +2 -1
  112. package/dist/types/tools/forwarding_artifact_service.d.ts +2 -2
  113. package/dist/types/tools/function_tool.d.ts +4 -3
  114. package/dist/types/tools/google_search_tool.d.ts +3 -3
  115. package/dist/types/tools/mcp/mcp_session_manager.d.ts +10 -3
  116. package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -2
  117. package/dist/types/utils/gemini_schema_util.d.ts +4 -12
  118. package/dist/types/utils/logger.d.ts +11 -10
  119. package/dist/types/utils/simple_zod_to_json.d.ts +5 -4
  120. package/dist/types/version.d.ts +1 -1
  121. package/dist/web/agents/base_agent.js +94 -33
  122. package/dist/web/agents/callback_context.js +4 -1
  123. package/dist/web/agents/content_processor_utils.js +25 -9
  124. package/dist/web/agents/functions.js +83 -29
  125. package/dist/web/agents/llm_agent.js +117 -54
  126. package/dist/web/agents/loop_agent.js +2 -1
  127. package/dist/web/agents/parallel_agent.js +3 -4
  128. package/dist/web/artifacts/gcs_artifact_service.js +25 -17
  129. package/dist/web/artifacts/in_memory_artifact_service.js +18 -4
  130. package/dist/web/auth/auth_handler.js +3 -1
  131. package/dist/web/code_executors/base_code_executor.js +3 -1
  132. package/dist/web/code_executors/built_in_code_executor.js +7 -3
  133. package/dist/web/code_executors/code_executor_context.js +5 -5
  134. package/dist/web/common.js +3 -1
  135. package/dist/web/events/event.js +1 -3
  136. package/dist/web/index.js +1 -1
  137. package/dist/web/index.js.map +4 -4
  138. package/dist/web/memory/in_memory_memory_service.js +3 -1
  139. package/dist/web/models/base_llm.js +8 -4
  140. package/dist/web/models/gemini_llm_connection.js +1 -0
  141. package/dist/web/models/google_llm.js +8 -4
  142. package/dist/web/plugins/base_plugin.js +12 -0
  143. package/dist/web/plugins/logging_plugin.js +55 -14
  144. package/dist/web/plugins/plugin_manager.js +56 -24
  145. package/dist/web/plugins/security_plugin.js +1 -1
  146. package/dist/web/runner/runner.js +159 -108
  147. package/dist/web/sessions/in_memory_session_service.js +41 -15
  148. package/dist/web/telemetry/google_cloud.js +7 -9
  149. package/dist/web/telemetry/setup.js +23 -9
  150. package/dist/web/telemetry/tracing.js +37 -15
  151. package/dist/web/tools/agent_tool.js +8 -4
  152. package/dist/web/tools/base_tool.js +4 -2
  153. package/dist/web/tools/forwarding_artifact_service.js +1 -1
  154. package/dist/web/tools/function_tool.js +1 -2
  155. package/dist/web/tools/google_search_tool.js +2 -5
  156. package/dist/web/tools/long_running_tool.js +3 -1
  157. package/dist/web/tools/mcp/mcp_session_manager.js +22 -12
  158. package/dist/web/tools/mcp/mcp_tool.js +1 -3
  159. package/dist/web/tools/mcp/mcp_toolset.js +1 -1
  160. package/dist/web/utils/env_aware_utils.js +1 -1
  161. package/dist/web/utils/gemini_schema_util.js +9 -4
  162. package/dist/web/utils/logger.js +43 -2
  163. package/dist/web/utils/simple_zod_to_json.js +102 -155
  164. package/dist/web/utils/variant_utils.js +1 -1
  165. package/dist/web/version.js +1 -1
  166. package/package.json +4 -2
@@ -46,53 +46,53 @@ export declare class LoggingPlugin extends BasePlugin {
46
46
  * @param name The name of the plugin instance.
47
47
  */
48
48
  constructor(name?: string);
49
- onUserMessageCallback({ invocationContext, userMessage }: {
49
+ onUserMessageCallback({ invocationContext, userMessage, }: {
50
50
  invocationContext: InvocationContext;
51
51
  userMessage: Content;
52
52
  }): Promise<Content | undefined>;
53
- beforeRunCallback({ invocationContext }: {
53
+ beforeRunCallback({ invocationContext, }: {
54
54
  invocationContext: InvocationContext;
55
55
  }): Promise<Content | undefined>;
56
- onEventCallback({ invocationContext, event }: {
56
+ onEventCallback({ event, }: {
57
57
  invocationContext: InvocationContext;
58
58
  event: Event;
59
59
  }): Promise<Event | undefined>;
60
- afterRunCallback({ invocationContext }: {
60
+ afterRunCallback({ invocationContext, }: {
61
61
  invocationContext: InvocationContext;
62
62
  }): Promise<void>;
63
- beforeAgentCallback({ agent, callbackContext }: {
63
+ beforeAgentCallback({ callbackContext, }: {
64
64
  agent: BaseAgent;
65
65
  callbackContext: CallbackContext;
66
66
  }): Promise<Content | undefined>;
67
- afterAgentCallback({ agent, callbackContext }: {
67
+ afterAgentCallback({ callbackContext, }: {
68
68
  agent: BaseAgent;
69
69
  callbackContext: CallbackContext;
70
70
  }): Promise<Content | undefined>;
71
- beforeModelCallback({ callbackContext, llmRequest }: {
71
+ beforeModelCallback({ callbackContext, llmRequest, }: {
72
72
  callbackContext: CallbackContext;
73
73
  llmRequest: LlmRequest;
74
74
  }): Promise<LlmResponse | undefined>;
75
- afterModelCallback({ callbackContext, llmResponse }: {
75
+ afterModelCallback({ callbackContext, llmResponse, }: {
76
76
  callbackContext: CallbackContext;
77
77
  llmResponse: LlmResponse;
78
78
  }): Promise<LlmResponse | undefined>;
79
- beforeToolCallback({ tool, toolArgs, toolContext }: {
79
+ beforeToolCallback({ tool, toolArgs, toolContext, }: {
80
80
  tool: BaseTool;
81
81
  toolArgs: Record<string, unknown>;
82
82
  toolContext: ToolContext;
83
83
  }): Promise<Record<string, unknown> | undefined>;
84
- afterToolCallback({ tool, toolArgs, toolContext, result }: {
84
+ afterToolCallback({ tool, toolContext, result, }: {
85
85
  tool: BaseTool;
86
86
  toolArgs: Record<string, unknown>;
87
87
  toolContext: ToolContext;
88
88
  result: Record<string, unknown>;
89
89
  }): Promise<Record<string, unknown> | undefined>;
90
- onModelErrorCallback({ callbackContext, llmRequest, error }: {
90
+ onModelErrorCallback({ callbackContext, error, }: {
91
91
  callbackContext: CallbackContext;
92
92
  llmRequest: LlmRequest;
93
93
  error: Error;
94
94
  }): Promise<LlmResponse | undefined>;
95
- onToolErrorCallback({ tool, toolArgs, toolContext, error }: {
95
+ onToolErrorCallback({ tool, toolArgs, toolContext, error, }: {
96
96
  tool: BaseTool;
97
97
  toolArgs: Record<string, unknown>;
98
98
  toolContext: ToolContext;
@@ -67,47 +67,47 @@ export declare class PluginManager {
67
67
  /**
68
68
  * Runs the `onUserMessageCallback` for all plugins.
69
69
  */
70
- runOnUserMessageCallback({ userMessage, invocationContext }: {
70
+ runOnUserMessageCallback({ userMessage, invocationContext, }: {
71
71
  userMessage: Content;
72
72
  invocationContext: InvocationContext;
73
73
  }): Promise<Content | undefined>;
74
74
  /**
75
75
  * Runs the `beforeRunCallback` for all plugins.
76
76
  */
77
- runBeforeRunCallback({ invocationContext }: {
77
+ runBeforeRunCallback({ invocationContext, }: {
78
78
  invocationContext: InvocationContext;
79
79
  }): Promise<Content | undefined>;
80
80
  /**
81
81
  * Runs the `afterRunCallback` for all plugins.
82
82
  */
83
- runAfterRunCallback({ invocationContext }: {
83
+ runAfterRunCallback({ invocationContext, }: {
84
84
  invocationContext: InvocationContext;
85
85
  }): Promise<void>;
86
86
  /**
87
87
  * Runs the `onEventCallback` for all plugins.
88
88
  */
89
- runOnEventCallback({ invocationContext, event }: {
89
+ runOnEventCallback({ invocationContext, event, }: {
90
90
  invocationContext: InvocationContext;
91
91
  event: Event;
92
92
  }): Promise<Event | undefined>;
93
93
  /**
94
94
  * Runs the `beforeAgentCallback` for all plugins.
95
95
  */
96
- runBeforeAgentCallback({ agent, callbackContext }: {
96
+ runBeforeAgentCallback({ agent, callbackContext, }: {
97
97
  agent: BaseAgent;
98
98
  callbackContext: CallbackContext;
99
99
  }): Promise<Content | undefined>;
100
100
  /**
101
101
  * Runs the `afterAgentCallback` for all plugins.
102
102
  */
103
- runAfterAgentCallback({ agent, callbackContext }: {
103
+ runAfterAgentCallback({ agent, callbackContext, }: {
104
104
  agent: BaseAgent;
105
105
  callbackContext: CallbackContext;
106
106
  }): Promise<Content | undefined>;
107
107
  /**
108
108
  * Runs the `beforeToolCallback` for all plugins.
109
109
  */
110
- runBeforeToolCallback({ tool, toolArgs, toolContext }: {
110
+ runBeforeToolCallback({ tool, toolArgs, toolContext, }: {
111
111
  tool: BaseTool;
112
112
  toolArgs: Record<string, unknown>;
113
113
  toolContext: ToolContext;
@@ -115,7 +115,7 @@ export declare class PluginManager {
115
115
  /**
116
116
  * Runs the `afterToolCallback` for all plugins.
117
117
  */
118
- runAfterToolCallback({ tool, toolArgs, toolContext, result }: {
118
+ runAfterToolCallback({ tool, toolArgs, toolContext, result, }: {
119
119
  tool: BaseTool;
120
120
  toolArgs: Record<string, unknown>;
121
121
  toolContext: ToolContext;
@@ -124,7 +124,7 @@ export declare class PluginManager {
124
124
  /**
125
125
  * Runs the `onModelErrorCallback` for all plugins.
126
126
  */
127
- runOnModelErrorCallback({ callbackContext, llmRequest, error }: {
127
+ runOnModelErrorCallback({ callbackContext, llmRequest, error, }: {
128
128
  callbackContext: CallbackContext;
129
129
  llmRequest: LlmRequest;
130
130
  error: Error;
@@ -132,21 +132,21 @@ export declare class PluginManager {
132
132
  /**
133
133
  * Runs the `beforeModelCallback` for all plugins.
134
134
  */
135
- runBeforeModelCallback({ callbackContext, llmRequest }: {
135
+ runBeforeModelCallback({ callbackContext, llmRequest, }: {
136
136
  callbackContext: CallbackContext;
137
137
  llmRequest: LlmRequest;
138
138
  }): Promise<LlmResponse | undefined>;
139
139
  /**
140
140
  * Runs the `afterModelCallback` for all plugins.
141
141
  */
142
- runAfterModelCallback({ callbackContext, llmResponse }: {
142
+ runAfterModelCallback({ callbackContext, llmResponse, }: {
143
143
  callbackContext: CallbackContext;
144
144
  llmResponse: LlmResponse;
145
145
  }): Promise<LlmResponse | undefined>;
146
146
  /**
147
147
  * Runs the `onToolErrorCallback` for all plugins.
148
148
  */
149
- runOnToolErrorCallback({ tool, toolArgs, toolContext, error }: {
149
+ runOnToolErrorCallback({ tool, toolArgs, toolContext, error, }: {
150
150
  tool: BaseTool;
151
151
  toolArgs: Record<string, unknown>;
152
152
  toolContext: ToolContext;
@@ -29,7 +29,7 @@ export interface BasePolicyEngine {
29
29
  evaluate(context: ToolCallPolicyContext): Promise<PolicyCheckResult>;
30
30
  }
31
31
  export declare class InMemoryPolicyEngine implements BasePolicyEngine {
32
- evaluate(context: ToolCallPolicyContext): Promise<PolicyCheckResult>;
32
+ evaluate(): Promise<PolicyCheckResult>;
33
33
  }
34
34
  /**
35
35
  * Security Plugin for running Orcas agents.
@@ -55,7 +55,7 @@ export declare class Runner {
55
55
  userId: string;
56
56
  sessionId: string;
57
57
  newMessage: Content;
58
- stateDelta?: Record<string, any>;
58
+ stateDelta?: Record<string, unknown>;
59
59
  runConfig?: RunConfig;
60
60
  }): AsyncGenerator<Event, void, undefined>;
61
61
  /**
@@ -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>;
@@ -46,6 +46,6 @@ export declare class AgentTool extends BaseTool {
46
46
  private readonly skipSummarization;
47
47
  constructor(config: AgentToolConfig);
48
48
  _getDeclaration(): FunctionDeclaration;
49
- runAsync({ args, toolContext }: RunAsyncToolRequest): Promise<unknown>;
49
+ runAsync({ args, toolContext, }: RunAsyncToolRequest): Promise<unknown>;
50
50
  }
51
51
  export {};
@@ -89,7 +89,7 @@ export declare abstract class BaseTool {
89
89
  *
90
90
  * @param request The request to process the LLM request.
91
91
  */
92
- processLlmRequest({ toolContext, llmRequest }: ToolProcessLlmRequest): Promise<void>;
92
+ processLlmRequest({ llmRequest }: ToolProcessLlmRequest): Promise<void>;
93
93
  /**
94
94
  * The Google API LLM variant to use.
95
95
  */
@@ -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,14 +4,15 @@
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;
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;
15
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.
@@ -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.
@@ -8,8 +8,8 @@ import { BaseTool, RunAsyncToolRequest, ToolProcessLlmRequest } from './base_too
8
8
  */
9
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
15
  * A global instance of {@link GoogleSearchTool}.
@@ -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
  }
@@ -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.5";
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,13 +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
98
  this.beforeAgentCallback = getCannonicalCallback(
64
99
  config.beforeAgentCallback
65
100
  );
66
101
  this.afterAgentCallback = getCannonicalCallback(config.afterAgentCallback);
67
102
  this.setParentAgentForSubAgents();
68
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
+ }
69
111
  /**
70
112
  * Entry method to run an agent via text-based conversation.
71
113
  *
@@ -75,38 +117,48 @@ class BaseAgent {
75
117
  */
76
118
  runAsync(parentContext) {
77
119
  return __asyncGenerator(this, null, function* () {
78
- 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);
79
122
  try {
80
- const context = this.createInvocationContext(parentContext);
81
- const beforeAgentCallbackEvent = yield new __await(this.handleBeforeAgentCallback(context));
82
- if (beforeAgentCallbackEvent) {
83
- yield beforeAgentCallbackEvent;
84
- }
85
- if (context.endInvocation) {
86
- return;
87
- }
88
- try {
89
- for (var iter = __forAwait(this.runAsyncImpl(context)), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
90
- const event = temp.value;
91
- yield event;
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
+ });
92
160
  }
93
- } catch (temp) {
94
- error = [temp];
95
- } finally {
96
- try {
97
- more && (temp = iter.return) && (yield new __await(temp.call(iter)));
98
- } finally {
99
- if (error)
100
- throw error[0];
101
- }
102
- }
103
- if (context.endInvocation) {
104
- return;
105
- }
106
- const afterAgentCallbackEvent = yield new __await(this.handleAfterAgentCallback(context));
107
- if (afterAgentCallbackEvent) {
108
- yield afterAgentCallbackEvent;
109
- }
161
+ ));
110
162
  } finally {
111
163
  span.end();
112
164
  }
@@ -121,8 +173,17 @@ class BaseAgent {
121
173
  */
122
174
  runLive(parentContext) {
123
175
  return __asyncGenerator(this, null, function* () {
124
- 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);
125
178
  try {
179
+ yield* __yieldStar(runAsyncGeneratorWithOtelContext(
180
+ ctx,
181
+ this,
182
+ function() {
183
+ return __asyncGenerator(this, null, function* () {
184
+ });
185
+ }
186
+ ));
126
187
  throw new Error("Live mode is not implemented yet.");
127
188
  } finally {
128
189
  span.end();
@@ -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(