@google/adk 1.1.0 → 1.2.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 (150) hide show
  1. package/dist/cjs/agents/functions.js +4 -0
  2. package/dist/cjs/auth/oauth2/oauth2_discovery.js +26 -2
  3. package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +305 -0
  4. package/dist/cjs/code_executors/code_execution_utils.js +1 -1
  5. package/dist/cjs/common.js +11 -0
  6. package/dist/cjs/events/event.js +3 -1
  7. package/dist/cjs/index.js +14 -0
  8. package/dist/cjs/integrations/agent_registry/agent_registry.js +362 -0
  9. package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +103 -0
  10. package/dist/cjs/integrations/agent_registry/helpers.js +57 -0
  11. package/dist/cjs/integrations/agent_registry/types.js +50 -0
  12. package/dist/cjs/memory/vertex_ai_memory_bank_service.js +496 -0
  13. package/dist/cjs/runner/in_memory_runner.js +10 -5
  14. package/dist/cjs/runner/runner.js +32 -2
  15. package/dist/cjs/sessions/database_session_service.js +49 -3
  16. package/dist/cjs/sessions/in_memory_session_service.js +70 -14
  17. package/dist/cjs/sessions/registry.js +4 -0
  18. package/dist/cjs/sessions/vertex_ai_session_service.js +428 -0
  19. package/dist/cjs/tools/agent_tool.js +10 -5
  20. package/dist/cjs/tools/exit_loop_tool.js +9 -0
  21. package/dist/cjs/tools/function_tool.js +7 -2
  22. package/dist/cjs/tools/google_maps_grounding_tool.js +80 -0
  23. package/dist/cjs/tools/long_running_tool.js +2 -1
  24. package/dist/cjs/tools/mcp/mcp_session_manager.js +11 -0
  25. package/dist/cjs/tools/mcp/mcp_tool.js +10 -6
  26. package/dist/cjs/tools/mcp/mcp_toolset.js +26 -3
  27. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +78 -0
  28. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +84 -0
  29. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +133 -0
  30. package/dist/cjs/tools/skill/load_skill_resource_tool.js +2 -25
  31. package/dist/cjs/tools/vertex_rag_retrieval_tool.js +64 -0
  32. package/dist/cjs/utils/file_utils.js +28 -0
  33. package/dist/cjs/utils/gemini_schema_util.js +18 -0
  34. package/dist/cjs/utils/partial_copy.js +51 -0
  35. package/dist/cjs/utils/streaming_utils.js +167 -121
  36. package/dist/cjs/utils/vertex_ai_utils.js +50 -0
  37. package/dist/cjs/version.js +1 -1
  38. package/dist/esm/agents/functions.js +4 -0
  39. package/dist/esm/auth/oauth2/oauth2_discovery.js +26 -2
  40. package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +281 -0
  41. package/dist/esm/code_executors/code_execution_utils.js +1 -1
  42. package/dist/esm/common.js +10 -0
  43. package/dist/esm/events/event.js +3 -1
  44. package/dist/esm/index.js +11 -0
  45. package/dist/esm/integrations/agent_registry/agent_registry.js +333 -0
  46. package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +77 -0
  47. package/dist/esm/integrations/agent_registry/helpers.js +28 -0
  48. package/dist/esm/integrations/agent_registry/types.js +20 -0
  49. package/dist/esm/memory/vertex_ai_memory_bank_service.js +468 -0
  50. package/dist/esm/runner/in_memory_runner.js +10 -5
  51. package/dist/esm/runner/runner.js +32 -2
  52. package/dist/esm/sessions/database_session_service.js +49 -3
  53. package/dist/esm/sessions/in_memory_session_service.js +70 -14
  54. package/dist/esm/sessions/registry.js +7 -0
  55. package/dist/esm/sessions/vertex_ai_session_service.js +403 -0
  56. package/dist/esm/tools/agent_tool.js +10 -5
  57. package/dist/esm/tools/exit_loop_tool.js +9 -0
  58. package/dist/esm/tools/function_tool.js +7 -2
  59. package/dist/esm/tools/google_maps_grounding_tool.js +54 -0
  60. package/dist/esm/tools/long_running_tool.js +2 -1
  61. package/dist/esm/tools/mcp/mcp_session_manager.js +11 -0
  62. package/dist/esm/tools/mcp/mcp_tool.js +10 -6
  63. package/dist/esm/tools/mcp/mcp_toolset.js +26 -3
  64. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +48 -0
  65. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
  66. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
  67. package/dist/esm/tools/skill/load_skill_resource_tool.js +1 -24
  68. package/dist/esm/tools/vertex_rag_retrieval_tool.js +36 -0
  69. package/dist/esm/utils/file_utils.js +26 -0
  70. package/dist/esm/utils/gemini_schema_util.js +18 -0
  71. package/dist/esm/utils/partial_copy.js +23 -0
  72. package/dist/esm/utils/streaming_utils.js +165 -120
  73. package/dist/esm/utils/vertex_ai_utils.js +22 -0
  74. package/dist/esm/version.js +1 -1
  75. package/dist/types/a2a/a2a_remote_agent.d.ts +14 -0
  76. package/dist/types/agents/processors/base_llm_processor.d.ts +12 -4
  77. package/dist/types/agents/processors/basic_llm_request_processor.d.ts +5 -0
  78. package/dist/types/agents/processors/identity_llm_request_processor.d.ts +4 -0
  79. package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +5 -0
  80. package/dist/types/agents/run_config.d.ts +15 -0
  81. package/dist/types/code_executors/agent_engine_sandbox_code_executor.d.ts +51 -0
  82. package/dist/types/common.d.ts +4 -0
  83. package/dist/types/events/event_actions.d.ts +24 -6
  84. package/dist/types/events/structured_events.d.ts +13 -0
  85. package/dist/types/examples/example_util.d.ts +25 -0
  86. package/dist/types/index.d.ts +6 -0
  87. package/dist/types/integrations/agent_registry/agent_registry.d.ts +94 -0
  88. package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +43 -0
  89. package/dist/types/integrations/agent_registry/helpers.d.ts +7 -0
  90. package/dist/types/integrations/agent_registry/types.d.ts +101 -0
  91. package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +52 -0
  92. package/dist/types/runner/in_memory_runner.d.ts +28 -1
  93. package/dist/types/runner/runner.d.ts +47 -0
  94. package/dist/types/sessions/base_session_service.d.ts +18 -0
  95. package/dist/types/sessions/database_session_service.d.ts +1 -1
  96. package/dist/types/sessions/in_memory_session_service.d.ts +1 -1
  97. package/dist/types/sessions/vertex_ai_session_service.d.ts +37 -0
  98. package/dist/types/tools/exit_loop_tool.d.ts +9 -0
  99. package/dist/types/tools/function_tool.d.ts +22 -2
  100. package/dist/types/tools/google_maps_grounding_tool.d.ts +22 -0
  101. package/dist/types/tools/long_running_tool.d.ts +11 -1
  102. package/dist/types/tools/mcp/mcp_session_manager.d.ts +3 -0
  103. package/dist/types/tools/mcp/mcp_toolset.d.ts +2 -1
  104. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +25 -0
  105. package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +20 -0
  106. package/dist/types/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.d.ts +20 -0
  107. package/dist/types/tools/vertex_rag_retrieval_tool.d.ts +42 -0
  108. package/dist/types/utils/file_utils.d.ts +2 -0
  109. package/dist/types/utils/partial_copy.d.ts +13 -0
  110. package/dist/types/utils/streaming_utils.d.ts +8 -17
  111. package/dist/types/utils/vertex_ai_utils.d.ts +14 -0
  112. package/dist/types/version.d.ts +1 -1
  113. package/dist/web/agents/functions.js +4 -0
  114. package/dist/web/auth/oauth2/oauth2_discovery.js +26 -2
  115. package/dist/web/code_executors/agent_engine_sandbox_code_executor.js +281 -0
  116. package/dist/web/code_executors/code_execution_utils.js +1 -1
  117. package/dist/web/common.js +10 -0
  118. package/dist/web/events/event.js +3 -1
  119. package/dist/web/index.js +11 -0
  120. package/dist/web/integrations/agent_registry/agent_registry.js +333 -0
  121. package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +90 -0
  122. package/dist/web/integrations/agent_registry/helpers.js +28 -0
  123. package/dist/web/integrations/agent_registry/types.js +20 -0
  124. package/dist/web/memory/vertex_ai_memory_bank_service.js +475 -0
  125. package/dist/web/runner/in_memory_runner.js +10 -5
  126. package/dist/web/runner/runner.js +32 -2
  127. package/dist/web/sessions/database_session_service.js +49 -3
  128. package/dist/web/sessions/in_memory_session_service.js +70 -14
  129. package/dist/web/sessions/registry.js +7 -0
  130. package/dist/web/sessions/vertex_ai_session_service.js +414 -0
  131. package/dist/web/tools/agent_tool.js +10 -5
  132. package/dist/web/tools/exit_loop_tool.js +9 -0
  133. package/dist/web/tools/function_tool.js +7 -2
  134. package/dist/web/tools/google_maps_grounding_tool.js +54 -0
  135. package/dist/web/tools/long_running_tool.js +2 -1
  136. package/dist/web/tools/mcp/mcp_session_manager.js +11 -0
  137. package/dist/web/tools/mcp/mcp_tool.js +10 -6
  138. package/dist/web/tools/mcp/mcp_toolset.js +26 -3
  139. package/dist/web/tools/openapi_tool/auth/auth_helpers.js +48 -0
  140. package/dist/web/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
  141. package/dist/web/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
  142. package/dist/web/tools/skill/load_skill_resource_tool.js +1 -24
  143. package/dist/web/tools/vertex_rag_retrieval_tool.js +36 -0
  144. package/dist/web/utils/file_utils.js +26 -0
  145. package/dist/web/utils/gemini_schema_util.js +18 -0
  146. package/dist/web/utils/partial_copy.js +23 -0
  147. package/dist/web/utils/streaming_utils.js +219 -121
  148. package/dist/web/utils/vertex_ai_utils.js +22 -0
  149. package/dist/web/version.js +1 -1
  150. package/package.json +2 -1
@@ -104,25 +104,81 @@ class InMemorySessionService extends BaseSessionService {
104
104
  }
105
105
  listSessions({
106
106
  appName,
107
- userId
107
+ userId,
108
+ limit,
109
+ offset,
110
+ page,
111
+ order
108
112
  }) {
109
113
  if (!this.sessions[appName] || !this.sessions[appName][userId]) {
110
- return Promise.resolve({ sessions: [] });
114
+ if (limit !== void 0) {
115
+ const effectiveOffset2 = page !== void 0 ? (page - 1) * limit : offset != null ? offset : 0;
116
+ const effectivePage2 = page !== void 0 ? page : limit === 0 ? 1 : Math.floor(effectiveOffset2 / limit) + 1;
117
+ return Promise.resolve({
118
+ sessions: [],
119
+ page: effectivePage2,
120
+ limit,
121
+ totalItems: 0,
122
+ totalPages: 0
123
+ });
124
+ }
125
+ return Promise.resolve({
126
+ sessions: [],
127
+ page: 1,
128
+ limit: 0,
129
+ totalItems: 0,
130
+ totalPages: 0
131
+ });
111
132
  }
112
- const sessionsWithoutEvents = [];
113
- for (const session of Object.values(this.sessions[appName][userId])) {
114
- sessionsWithoutEvents.push(
115
- createSession({
116
- id: session.id,
117
- appName: session.appName,
118
- userId: session.userId,
119
- state: {},
120
- events: [],
121
- lastUpdateTime: session.lastUpdateTime
122
- })
133
+ const all = Object.values(this.sessions[appName][userId]).map(
134
+ (session) => createSession({
135
+ id: session.id,
136
+ appName: session.appName,
137
+ userId: session.userId,
138
+ state: {},
139
+ events: [],
140
+ lastUpdateTime: session.lastUpdateTime
141
+ })
142
+ );
143
+ if (order === "asc") {
144
+ all.sort(
145
+ (a, b) => a.lastUpdateTime - b.lastUpdateTime || a.id.localeCompare(b.id)
146
+ );
147
+ } else if (order === "desc") {
148
+ all.sort(
149
+ (a, b) => b.lastUpdateTime - a.lastUpdateTime || a.id.localeCompare(b.id)
123
150
  );
124
151
  }
125
- return Promise.resolve({ sessions: sessionsWithoutEvents });
152
+ if (limit === void 0) {
153
+ const totalItems2 = all.length;
154
+ const sliced = offset ? all.slice(offset) : all;
155
+ return Promise.resolve({
156
+ sessions: sliced,
157
+ page: 1,
158
+ limit: totalItems2,
159
+ totalItems: totalItems2,
160
+ totalPages: totalItems2 === 0 ? 0 : 1
161
+ });
162
+ }
163
+ const totalItems = all.length;
164
+ const totalPages = limit === 0 ? 0 : Math.ceil(totalItems / limit);
165
+ let effectiveOffset;
166
+ let effectivePage;
167
+ if (page !== void 0) {
168
+ effectiveOffset = (page - 1) * limit;
169
+ effectivePage = page;
170
+ } else {
171
+ effectiveOffset = offset != null ? offset : 0;
172
+ effectivePage = limit === 0 ? 1 : Math.floor(effectiveOffset / limit) + 1;
173
+ }
174
+ const paginated = all.slice(effectiveOffset, effectiveOffset + limit);
175
+ return Promise.resolve({
176
+ sessions: paginated,
177
+ page: effectivePage,
178
+ limit,
179
+ totalItems,
180
+ totalPages
181
+ });
126
182
  }
127
183
  async deleteSession({
128
184
  appName,
@@ -13,6 +13,10 @@ import {
13
13
  InMemorySessionService,
14
14
  isInMemoryConnectionString
15
15
  } from "./in_memory_session_service.js";
16
+ import {
17
+ VertexAiSessionService,
18
+ isVertexAiConnectionString
19
+ } from "./vertex_ai_session_service.js";
16
20
  function getSessionServiceFromUri(uri) {
17
21
  if (isInMemoryConnectionString(uri)) {
18
22
  return new InMemorySessionService();
@@ -20,6 +24,9 @@ function getSessionServiceFromUri(uri) {
20
24
  if (isDatabaseConnectionString(uri)) {
21
25
  return new DatabaseSessionService(uri);
22
26
  }
27
+ if (isVertexAiConnectionString(uri)) {
28
+ return new VertexAiSessionService({});
29
+ }
23
30
  throw new Error(`Unsupported session service URI: ${uri}`);
24
31
  }
25
32
  export {
@@ -0,0 +1,403 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __decorateClass = (decorators, target, key, kind) => {
6
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
7
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
8
+ if (decorator = decorators[i])
9
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
10
+ if (kind && result) __defProp(target, key, result);
11
+ return result;
12
+ };
13
+ /**
14
+ * @license
15
+ * Copyright 2026 Google LLC
16
+ * SPDX-License-Identifier: Apache-2.0
17
+ */
18
+ import { Client } from "@google-cloud/vertexai/build/src/genai/client.js";
19
+ import { isCompactedEvent } from "../events/compacted_event.js";
20
+ import { experimental } from "../utils/experimental.js";
21
+ import { logger } from "../utils/logger.js";
22
+ import { getExpressModeApiKey } from "../utils/vertex_ai_utils.js";
23
+ import { partialCopy } from "../utils/partial_copy.js";
24
+ import {
25
+ BaseSessionService
26
+ } from "./base_session_service.js";
27
+ import { createSession } from "./session.js";
28
+ const DEFAULT_MAX_ATTEMPTS = 30;
29
+ const GRPC_NOT_FOUND = 5;
30
+ const HTTP_NOT_FOUND = 404;
31
+ function isVertexAiConnectionString(uri) {
32
+ return (uri == null ? void 0 : uri.startsWith("vertexai://")) || false;
33
+ }
34
+ let VertexAiSessionService = class extends BaseSessionService {
35
+ constructor(options) {
36
+ super();
37
+ this.agentEngineId = options.agentEngineId;
38
+ this.projectId = options.projectId;
39
+ this.location = options.location;
40
+ this.expressModeApiKey = getExpressModeApiKey(
41
+ this.projectId,
42
+ this.location,
43
+ options.expressModeApiKey
44
+ );
45
+ if (!options.sessions) {
46
+ if (!this.expressModeApiKey && (!this.projectId || !this.location)) {
47
+ throw new Error(
48
+ "Either (Project ID and Location) or an expressModeApiKey is required."
49
+ );
50
+ }
51
+ }
52
+ if (options.sessions) {
53
+ this.sessions = options.sessions;
54
+ } else {
55
+ const client = new Client({
56
+ project: this.projectId,
57
+ location: this.location
58
+ });
59
+ this.sessions = client.agentEnginesInternal.sessions;
60
+ }
61
+ }
62
+ getReasoningEngineId(appName) {
63
+ if (this.agentEngineId) {
64
+ return this.agentEngineId;
65
+ }
66
+ if (/^\d+$/.test(appName)) {
67
+ return appName;
68
+ }
69
+ const pattern = /^projects\/([a-zA-Z0-9-_]+)\/locations\/([a-zA-Z0-9-_]+)\/reasoningEngines\/(\d+)$/;
70
+ const match = appName.match(pattern);
71
+ if (!match) {
72
+ throw new Error(
73
+ `App name ${appName} is not valid. It should either be the full ReasoningEngine resource name, or the reasoning engine id.`
74
+ );
75
+ }
76
+ return match[3];
77
+ }
78
+ async createSession({
79
+ appName,
80
+ userId,
81
+ state,
82
+ sessionId
83
+ }) {
84
+ var _a;
85
+ const reasoningEngineId = this.getReasoningEngineId(appName);
86
+ let apiResponse = await this.sessions.createInternal({
87
+ name: `reasoningEngines/${reasoningEngineId}`,
88
+ userId,
89
+ config: {
90
+ ...state ? { sessionState: state } : {},
91
+ ...sessionId ? { sessionId } : {}
92
+ }
93
+ });
94
+ const operationName = apiResponse.name;
95
+ let attempts = 0;
96
+ while (!apiResponse.done && attempts < DEFAULT_MAX_ATTEMPTS) {
97
+ const [nextResponse] = await Promise.all([
98
+ this.sessions.getSessionOperationInternal({
99
+ operationName
100
+ }),
101
+ new Promise((resolve) => setTimeout(resolve, 1e3))
102
+ ]);
103
+ apiResponse = nextResponse;
104
+ attempts++;
105
+ }
106
+ if (!apiResponse.done) {
107
+ throw new Error(
108
+ `Session creation operation ${operationName} did not complete in time.`
109
+ );
110
+ }
111
+ const getSessionResponse = apiResponse.response;
112
+ const id = ((_a = getSessionResponse.name) == null ? void 0 : _a.split("/").pop()) || "";
113
+ return createSession({
114
+ id,
115
+ appName,
116
+ userId,
117
+ state: getSessionResponse.sessionState,
118
+ events: [],
119
+ lastUpdateTime: getSessionResponse.updateTime ? Date.parse(getSessionResponse.updateTime) : Date.now()
120
+ });
121
+ }
122
+ async getSession({
123
+ appName,
124
+ userId,
125
+ sessionId,
126
+ config
127
+ }) {
128
+ const reasoningEngineId = this.getReasoningEngineId(appName);
129
+ const sessionResourceName = `reasoningEngines/${reasoningEngineId}/sessions/${sessionId}`;
130
+ try {
131
+ let getSessionResponse;
132
+ let eventsIterator = [];
133
+ if (config && config.numRecentEvents === 0) {
134
+ getSessionResponse = await this.sessions.get({
135
+ name: sessionResourceName
136
+ });
137
+ } else {
138
+ const listConfig = {};
139
+ if (config && config.afterTimestamp) {
140
+ listConfig.filter = `timestamp>="${new Date(
141
+ config.afterTimestamp
142
+ ).toISOString()}"`;
143
+ }
144
+ const [sessionRes, eventsRes] = await Promise.all([
145
+ this.sessions.get({ name: sessionResourceName }),
146
+ this.sessions.events.listInternal({
147
+ name: sessionResourceName,
148
+ config: listConfig
149
+ })
150
+ ]);
151
+ getSessionResponse = sessionRes;
152
+ eventsIterator = eventsRes.sessionEvents || [];
153
+ }
154
+ const sessionObj = getSessionResponse;
155
+ if (sessionObj.userId !== userId) {
156
+ throw new Error(
157
+ `Session ${sessionId} does not belong to user ${userId}.`
158
+ );
159
+ }
160
+ const session = createSession({
161
+ id: sessionId,
162
+ appName,
163
+ userId,
164
+ state: sessionObj.sessionState,
165
+ events: [],
166
+ lastUpdateTime: sessionObj.updateTime ? Date.parse(sessionObj.updateTime) : Date.now()
167
+ });
168
+ for (const event of eventsIterator) {
169
+ session.events.push(_fromApiEvent(event));
170
+ }
171
+ if (config && config.numRecentEvents) {
172
+ session.events = session.events.slice(-config.numRecentEvents);
173
+ }
174
+ return session;
175
+ } catch (error) {
176
+ const err = error;
177
+ if (err.code === GRPC_NOT_FOUND || err.code === HTTP_NOT_FOUND) {
178
+ return void 0;
179
+ }
180
+ logger.error(`Error getting session from Vertex AI: ${err.message}`);
181
+ throw error;
182
+ }
183
+ }
184
+ async listSessions({
185
+ appName,
186
+ userId,
187
+ limit,
188
+ offset,
189
+ page,
190
+ order
191
+ }) {
192
+ var _a;
193
+ const reasoningEngineId = this.getReasoningEngineId(appName);
194
+ const adkSessions = [];
195
+ let pageToken = void 0;
196
+ do {
197
+ const response = await this.sessions.listInternal({
198
+ name: `reasoningEngines/${reasoningEngineId}`,
199
+ config: {
200
+ ...userId ? { filter: `user_id="${userId}"` } : {},
201
+ ...pageToken ? { pageToken } : {}
202
+ }
203
+ });
204
+ const sessions = response.sessions || [];
205
+ for (const sessionObj of sessions) {
206
+ const id = ((_a = sessionObj.name) == null ? void 0 : _a.split("/").pop()) || "";
207
+ adkSessions.push(
208
+ createSession({
209
+ id,
210
+ appName,
211
+ userId: sessionObj.userId,
212
+ state: sessionObj.sessionState,
213
+ events: [],
214
+ lastUpdateTime: sessionObj.updateTime ? new Date(sessionObj.updateTime).getTime() : Date.now()
215
+ })
216
+ );
217
+ }
218
+ pageToken = response.nextPageToken;
219
+ } while (pageToken);
220
+ if (order === "asc") {
221
+ adkSessions.sort(
222
+ (a, b) => a.lastUpdateTime - b.lastUpdateTime || a.id.localeCompare(b.id)
223
+ );
224
+ } else if (order === "desc") {
225
+ adkSessions.sort(
226
+ (a, b) => b.lastUpdateTime - a.lastUpdateTime || a.id.localeCompare(b.id)
227
+ );
228
+ }
229
+ if (limit === void 0) {
230
+ const totalItems2 = adkSessions.length;
231
+ const sliced = offset ? adkSessions.slice(offset) : adkSessions;
232
+ return {
233
+ sessions: sliced,
234
+ page: 1,
235
+ limit: totalItems2,
236
+ totalItems: totalItems2,
237
+ totalPages: totalItems2 === 0 ? 0 : 1
238
+ };
239
+ }
240
+ const totalItems = adkSessions.length;
241
+ const totalPages = limit === 0 ? 0 : Math.ceil(totalItems / limit);
242
+ let effectiveOffset;
243
+ let effectivePage;
244
+ if (page !== void 0) {
245
+ effectiveOffset = (page - 1) * limit;
246
+ effectivePage = page;
247
+ } else {
248
+ effectiveOffset = offset != null ? offset : 0;
249
+ effectivePage = limit === 0 ? 1 : Math.floor(effectiveOffset / limit) + 1;
250
+ }
251
+ return {
252
+ sessions: adkSessions.slice(effectiveOffset, effectiveOffset + limit),
253
+ page: effectivePage,
254
+ limit,
255
+ totalItems,
256
+ totalPages
257
+ };
258
+ }
259
+ async deleteSession({
260
+ appName,
261
+ userId: _userId,
262
+ sessionId
263
+ }) {
264
+ const reasoningEngineId = this.getReasoningEngineId(appName);
265
+ await this.sessions.delete({
266
+ name: `reasoningEngines/${reasoningEngineId}/sessions/${sessionId}`
267
+ });
268
+ }
269
+ async appendEvent({
270
+ session,
271
+ event
272
+ }) {
273
+ await super.appendEvent({ session, event });
274
+ session.lastUpdateTime = event.timestamp;
275
+ const reasoningEngineId = this.getReasoningEngineId(session.appName);
276
+ const customMetadata = { ...event.customMetadata };
277
+ if (isCompactedEvent(event)) {
278
+ customMetadata._compaction = {
279
+ startTime: event.startTime,
280
+ endTime: event.endTime,
281
+ compactedContent: event.compactedContent
282
+ };
283
+ }
284
+ if (event.usageMetadata) {
285
+ customMetadata._usage_metadata = event.usageMetadata;
286
+ }
287
+ const config = partialCopy(event, [
288
+ "content",
289
+ "actions",
290
+ "errorCode",
291
+ "errorMessage"
292
+ ]);
293
+ config.eventMetadata = {
294
+ ...partialCopy(event, [
295
+ "partial",
296
+ "turnComplete",
297
+ "interrupted",
298
+ "branch",
299
+ "longRunningToolIds",
300
+ "groundingMetadata"
301
+ ]),
302
+ customMetadata: Object.keys(customMetadata).length > 0 ? customMetadata : void 0
303
+ };
304
+ config.rawEvent = JSON.parse(JSON.stringify(event));
305
+ const params = {
306
+ name: `reasoningEngines/${reasoningEngineId}/sessions/${session.id}`,
307
+ author: event.author || "user",
308
+ invocationId: event.invocationId || `inv-${Date.now()}`,
309
+ timestamp: new Date(event.timestamp).toISOString(),
310
+ config
311
+ };
312
+ try {
313
+ await this.sessions.events.append(params);
314
+ } catch (error) {
315
+ logger.warn(
316
+ "Failed to append event with rawEvent, falling back...",
317
+ error
318
+ );
319
+ delete config.rawEvent;
320
+ await this.sessions.events.append({
321
+ name: `reasoningEngines/${reasoningEngineId}/sessions/${session.id}`,
322
+ author: event.author || "user",
323
+ invocationId: event.invocationId || `inv-${Date.now()}`,
324
+ timestamp: new Date(event.timestamp).toISOString(),
325
+ config
326
+ });
327
+ }
328
+ return event;
329
+ }
330
+ };
331
+ VertexAiSessionService = __decorateClass([
332
+ experimental
333
+ ], VertexAiSessionService);
334
+ function _fromApiEvent(apiEventObj) {
335
+ var _a, _b, _c;
336
+ const rawEvent = apiEventObj.rawEvent;
337
+ if (rawEvent) {
338
+ const event2 = JSON.parse(JSON.stringify(rawEvent));
339
+ event2.id = ((_a = apiEventObj.name) == null ? void 0 : _a.split("/").pop()) || "";
340
+ event2.invocationId = apiEventObj.invocationId || "";
341
+ event2.author = apiEventObj.author;
342
+ if (apiEventObj.timestamp) {
343
+ event2.timestamp = new Date(apiEventObj.timestamp).getTime();
344
+ }
345
+ return event2;
346
+ }
347
+ const actions = apiEventObj.actions || {};
348
+ const eventMetadata = apiEventObj.eventMetadata || {};
349
+ let customMetadata = eventMetadata.customMetadata;
350
+ let compactionData = null;
351
+ let usageMetadataData = null;
352
+ if (customMetadata) {
353
+ if (customMetadata._compaction) {
354
+ compactionData = customMetadata._compaction;
355
+ delete customMetadata._compaction;
356
+ }
357
+ if (customMetadata._usage_metadata) {
358
+ usageMetadataData = customMetadata._usage_metadata;
359
+ delete customMetadata._usage_metadata;
360
+ }
361
+ if (Object.keys(customMetadata).length === 0) {
362
+ customMetadata = void 0;
363
+ }
364
+ }
365
+ const eventActions = {
366
+ stateDelta: actions["stateDelta"] || {},
367
+ artifactDelta: actions["artifactDelta"] || {},
368
+ requestedAuthConfigs: actions.requestedAuthConfigs || {},
369
+ requestedToolConfirmations: actions["requestedToolConfirmations"] || {},
370
+ skipSummarization: actions["skipSummarization"],
371
+ transferToAgent: actions["transferAgent"],
372
+ escalate: actions["escalate"],
373
+ compaction: compactionData || void 0
374
+ };
375
+ const event = {
376
+ id: ((_b = apiEventObj.name) == null ? void 0 : _b.split("/").pop()) || "",
377
+ invocationId: apiEventObj.invocationId || "",
378
+ author: apiEventObj.author,
379
+ actions: eventActions,
380
+ content: apiEventObj.content,
381
+ timestamp: apiEventObj.timestamp ? new Date(apiEventObj.timestamp).getTime() : Date.now(),
382
+ errorCode: (_c = apiEventObj.errorCode) == null ? void 0 : _c.toString(),
383
+ errorMessage: apiEventObj.errorMessage,
384
+ partial: eventMetadata["partial"],
385
+ turnComplete: eventMetadata["turnComplete"],
386
+ interrupted: eventMetadata["interrupted"],
387
+ branch: eventMetadata["branch"],
388
+ customMetadata,
389
+ longRunningToolIds: eventMetadata["longRunningToolIds"],
390
+ usageMetadata: usageMetadataData
391
+ };
392
+ if (compactionData) {
393
+ event.isCompacted = true;
394
+ event.startTime = compactionData.startTime;
395
+ event.endTime = compactionData.endTime;
396
+ event.compactedContent = compactionData.compactedContent;
397
+ }
398
+ return event;
399
+ }
400
+ export {
401
+ VertexAiSessionService,
402
+ isVertexAiConnectionString
403
+ };
@@ -12,6 +12,7 @@ import { InMemoryMemoryService } from "../memory/in_memory_memory_service.js";
12
12
  import { Runner } from "../runner/runner.js";
13
13
  import { InMemorySessionService } from "../sessions/in_memory_session_service.js";
14
14
  import { GoogleLLMVariant } from "../utils/variant_utils.js";
15
+ import { State } from "../sessions/state.js";
15
16
  import { BaseTool } from "./base_tool.js";
16
17
  import { ForwardingArtifactService } from "./forwarding_artifact_service.js";
17
18
  const AGENT_TOOL_SIGNATURE_SYMBOL = Symbol.for("google.adk.agentTool");
@@ -66,9 +67,6 @@ class AgentTool extends (_b = BaseTool, _a = AGENT_TOOL_SIGNATURE_SYMBOL, _b) {
66
67
  toolContext
67
68
  }) {
68
69
  var _a2, _b2, _c, _d, _e, _f;
69
- if (this.skipSummarization) {
70
- toolContext.actions.skipSummarization = true;
71
- }
72
70
  const hasInputSchema = isLlmAgent(this.agent) && this.agent.inputSchema;
73
71
  const content = {
74
72
  role: "user",
@@ -108,7 +106,14 @@ class AgentTool extends (_b = BaseTool, _a = AGENT_TOOL_SIGNATURE_SYMBOL, _b) {
108
106
  return;
109
107
  }
110
108
  if (event.actions.stateDelta) {
111
- toolContext.state.update(event.actions.stateDelta);
109
+ const filteredDelta = Object.fromEntries(
110
+ Object.entries(event.actions.stateDelta).filter(
111
+ ([key]) => !key.startsWith(State.TEMP_PREFIX)
112
+ )
113
+ );
114
+ if (Object.keys(filteredDelta).length > 0) {
115
+ toolContext.state.update(filteredDelta);
116
+ }
112
117
  }
113
118
  lastEvent = event;
114
119
  }
@@ -116,7 +121,7 @@ class AgentTool extends (_b = BaseTool, _a = AGENT_TOOL_SIGNATURE_SYMBOL, _b) {
116
121
  return "";
117
122
  }
118
123
  const hasOutputSchema = isLlmAgent(this.agent) && this.agent.outputSchema;
119
- const mergedText = lastEvent.content.parts.map((part) => part.text).filter((text) => text).join("\n");
124
+ const mergedText = lastEvent.content.parts.filter((part) => !part.thought).map((part) => part.text).filter((text) => text).join("\n");
120
125
  return hasOutputSchema ? JSON.parse(mergedText) : mergedText;
121
126
  }
122
127
  }
@@ -7,18 +7,27 @@ const require = topLevelCreateRequire(import.meta.url);
7
7
  */
8
8
  import { BaseTool } from "./base_tool.js";
9
9
  class ExitLoopTool extends BaseTool {
10
+ /** Creates an ExitLoopTool with its fixed name and description. */
10
11
  constructor() {
11
12
  super({
12
13
  name: "exit_loop",
13
14
  description: "Exits the loop.\n\nCall this function only when you are instructed to do so."
14
15
  });
15
16
  }
17
+ /** Returns the function declaration for this tool. */
16
18
  _getDeclaration() {
17
19
  return {
18
20
  name: this.name,
19
21
  description: this.description
20
22
  };
21
23
  }
24
+ /**
25
+ * Sets `escalate` and `skipSummarization` on the event actions, signalling
26
+ * the {@link LoopAgent} to stop iterating.
27
+ *
28
+ * @param request The tool request containing the current tool context.
29
+ * @returns An empty string response.
30
+ */
22
31
  async runAsync({
23
32
  toolContext
24
33
  }) {
@@ -46,7 +46,8 @@ class FunctionTool extends (_b = BaseTool, _a = FUNCTION_TOOL_SIGNATURE_SYMBOL,
46
46
  this.parameters = options.parameters;
47
47
  }
48
48
  /**
49
- * Provide a schema for the function.
49
+ * Returns the function declaration derived from the tool's name, description,
50
+ * and parameter schema.
50
51
  */
51
52
  _getDeclaration() {
52
53
  return {
@@ -56,7 +57,11 @@ class FunctionTool extends (_b = BaseTool, _a = FUNCTION_TOOL_SIGNATURE_SYMBOL,
56
57
  };
57
58
  }
58
59
  /**
59
- * Logic for running the tool.
60
+ * Validates the model-provided arguments against the parameter schema and
61
+ * invokes the user-defined `execute` function.
62
+ *
63
+ * @param req The tool request containing arguments and tool context.
64
+ * @returns A promise resolving to the function's return value.
60
65
  */
61
66
  async runAsync(req) {
62
67
  try {
@@ -0,0 +1,54 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ /**
4
+ * @license
5
+ * Copyright 2026 Google LLC
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ import {
9
+ isGemini1Model,
10
+ isGeminiModel,
11
+ isGeminiModelIdCheckDisabled
12
+ } from "../utils/model_name.js";
13
+ import { BaseTool } from "./base_tool.js";
14
+ function applyGoogleMapsGrounding(llmRequest) {
15
+ if (!llmRequest.model) {
16
+ return;
17
+ }
18
+ const modelCheckDisabled = isGeminiModelIdCheckDisabled();
19
+ llmRequest.config = llmRequest.config || {};
20
+ llmRequest.config.tools = llmRequest.config.tools || [];
21
+ if (isGemini1Model(llmRequest.model)) {
22
+ throw new Error(
23
+ "Google Maps grounding tool cannot be used with Gemini 1.x models."
24
+ );
25
+ }
26
+ if (isGeminiModel(llmRequest.model) || modelCheckDisabled) {
27
+ llmRequest.config.tools.push({
28
+ googleMaps: {}
29
+ });
30
+ return;
31
+ }
32
+ throw new Error(
33
+ `Google maps tool is not supported for model ${llmRequest.model}`
34
+ );
35
+ }
36
+ class GoogleMapsGroundingTool extends BaseTool {
37
+ constructor() {
38
+ super({ name: "google_maps", description: "Google Maps Grounding Tool" });
39
+ }
40
+ runAsync() {
41
+ return Promise.resolve();
42
+ }
43
+ async processLlmRequest({
44
+ llmRequest
45
+ }) {
46
+ applyGoogleMapsGrounding(llmRequest);
47
+ }
48
+ }
49
+ const GOOGLE_MAPS_GROUNDING = new GoogleMapsGroundingTool();
50
+ export {
51
+ GOOGLE_MAPS_GROUNDING,
52
+ GoogleMapsGroundingTool,
53
+ applyGoogleMapsGrounding
54
+ };
@@ -20,7 +20,8 @@ class LongRunningFunctionTool extends FunctionTool {
20
20
  super({ ...options, isLongRunning: true });
21
21
  }
22
22
  /**
23
- * Provide a schema for the function.
23
+ * Returns the function declaration with an appended instruction warning the
24
+ * model not to re-invoke the tool while it is still running.
24
25
  */
25
26
  _getDeclaration() {
26
27
  const declaration = super._getDeclaration();