@google/adk 1.3.0 → 1.4.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 (165) hide show
  1. package/dist/cjs/agents/active_streaming_tool.js +6 -1
  2. package/dist/cjs/agents/context.js +1 -11
  3. package/dist/cjs/agents/functions.js +35 -16
  4. package/dist/cjs/agents/instructions.js +23 -5
  5. package/dist/cjs/agents/invocation_context.js +2 -5
  6. package/dist/cjs/agents/llm_agent.js +8 -6
  7. package/dist/cjs/agents/processors/code_execution_request_processor.js +0 -3
  8. package/dist/cjs/agents/processors/content_processor_utils.js +16 -3
  9. package/dist/cjs/agents/processors/context_compactor_request_processor.js +4 -2
  10. package/dist/cjs/agents/processors/interactions_request_processor.js +63 -0
  11. package/dist/cjs/apps/app.js +79 -0
  12. package/dist/cjs/apps/resumability_config.js +44 -0
  13. package/dist/cjs/artifacts/file_artifact_service.js +14 -1
  14. package/dist/cjs/artifacts/gcs_artifact_service.js +57 -15
  15. package/dist/cjs/artifacts/in_memory_artifact_service.js +5 -1
  16. package/dist/cjs/artifacts/scoped_artifact_service.js +101 -0
  17. package/dist/cjs/artifacts/session_artifact_service.js +27 -0
  18. package/dist/cjs/auth/oauth2/oauth2_discovery.js +17 -5
  19. package/dist/cjs/auth/oauth2/oauth2_utils.js +12 -1
  20. package/dist/cjs/common.js +47 -0
  21. package/dist/cjs/context/agent_controlled_context_compactor.js +109 -0
  22. package/dist/cjs/context/token_based_context_compactor.js +42 -10
  23. package/dist/cjs/context/trajectory_thought_pruning_compactor.js +71 -0
  24. package/dist/cjs/events/event.js +24 -0
  25. package/dist/cjs/models/google_llm.js +25 -10
  26. package/dist/cjs/models/interactions_utils.js +732 -0
  27. package/dist/cjs/plugins/base_plugin.js +1 -0
  28. package/dist/cjs/runner/in_memory_runner.js +13 -2
  29. package/dist/cjs/runner/runner.js +93 -72
  30. package/dist/cjs/sessions/base_session_service.js +6 -1
  31. package/dist/cjs/sessions/database_session_service.js +24 -7
  32. package/dist/cjs/sessions/vertex_ai_session_service.js +19 -4
  33. package/dist/cjs/skills/loader.js +2 -2
  34. package/dist/cjs/tools/base_toolset.js +1 -1
  35. package/dist/cjs/tools/consolidate_context_tool.js +79 -0
  36. package/dist/cjs/tools/forwarding_artifact_service.js +16 -28
  37. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +2 -12
  38. package/dist/cjs/utils/async_hooks_shim.js +52 -0
  39. package/dist/cjs/utils/client_labels.js +41 -3
  40. package/dist/cjs/utils/env_aware_utils.js +10 -1
  41. package/dist/cjs/utils/streaming_utils.js +10 -4
  42. package/dist/cjs/utils/task.js +62 -0
  43. package/dist/cjs/version.js +1 -1
  44. package/dist/esm/agents/active_streaming_tool.js +6 -1
  45. package/dist/esm/agents/context.js +1 -11
  46. package/dist/esm/agents/functions.js +36 -15
  47. package/dist/esm/agents/instructions.js +23 -5
  48. package/dist/esm/agents/invocation_context.js +2 -5
  49. package/dist/esm/agents/llm_agent.js +8 -6
  50. package/dist/esm/agents/processors/code_execution_request_processor.js +0 -3
  51. package/dist/esm/agents/processors/content_processor_utils.js +14 -2
  52. package/dist/esm/agents/processors/context_compactor_request_processor.js +4 -2
  53. package/dist/esm/agents/processors/interactions_request_processor.js +34 -0
  54. package/dist/esm/apps/app.js +49 -0
  55. package/dist/esm/apps/resumability_config.js +16 -0
  56. package/dist/esm/artifacts/file_artifact_service.js +14 -1
  57. package/dist/esm/artifacts/gcs_artifact_service.js +57 -15
  58. package/dist/esm/artifacts/in_memory_artifact_service.js +5 -1
  59. package/dist/esm/artifacts/scoped_artifact_service.js +73 -0
  60. package/dist/esm/artifacts/session_artifact_service.js +7 -0
  61. package/dist/esm/auth/oauth2/oauth2_discovery.js +14 -4
  62. package/dist/esm/auth/oauth2/oauth2_utils.js +12 -1
  63. package/dist/esm/common.js +42 -2
  64. package/dist/esm/context/agent_controlled_context_compactor.js +81 -0
  65. package/dist/esm/context/token_based_context_compactor.js +42 -10
  66. package/dist/esm/context/trajectory_thought_pruning_compactor.js +43 -0
  67. package/dist/esm/events/event.js +22 -0
  68. package/dist/esm/models/google_llm.js +23 -9
  69. package/dist/esm/models/interactions_utils.js +697 -0
  70. package/dist/esm/plugins/base_plugin.js +1 -0
  71. package/dist/esm/runner/in_memory_runner.js +13 -2
  72. package/dist/esm/runner/runner.js +91 -73
  73. package/dist/esm/sessions/base_session_service.js +6 -1
  74. package/dist/esm/sessions/database_session_service.js +24 -7
  75. package/dist/esm/sessions/vertex_ai_session_service.js +17 -3
  76. package/dist/esm/skills/loader.js +2 -2
  77. package/dist/esm/tools/base_toolset.js +1 -1
  78. package/dist/esm/tools/consolidate_context_tool.js +51 -0
  79. package/dist/esm/tools/forwarding_artifact_service.js +16 -28
  80. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +2 -12
  81. package/dist/esm/utils/async_hooks_shim.js +24 -0
  82. package/dist/esm/utils/client_labels.js +38 -2
  83. package/dist/esm/utils/env_aware_utils.js +10 -1
  84. package/dist/esm/utils/streaming_utils.js +10 -4
  85. package/dist/esm/utils/task.js +34 -0
  86. package/dist/esm/version.js +1 -1
  87. package/dist/types/agents/active_streaming_tool.d.ts +3 -4
  88. package/dist/types/agents/functions.d.ts +12 -9
  89. package/dist/types/agents/invocation_context.d.ts +7 -3
  90. package/dist/types/agents/processors/content_processor_utils.d.ts +8 -0
  91. package/dist/types/agents/processors/interactions_request_processor.d.ts +17 -0
  92. package/dist/types/apps/app.d.ts +52 -0
  93. package/dist/types/apps/resumability_config.d.ts +27 -0
  94. package/dist/types/artifacts/base_artifact_service.d.ts +6 -36
  95. package/dist/types/artifacts/gcs_artifact_service.d.ts +2 -1
  96. package/dist/types/artifacts/scoped_artifact_service.d.ts +25 -0
  97. package/dist/types/artifacts/session_artifact_service.d.ts +25 -0
  98. package/dist/types/auth/oauth2/oauth2_discovery.d.ts +11 -0
  99. package/dist/types/common.d.ts +20 -3
  100. package/dist/types/context/agent_controlled_context_compactor.d.ts +24 -0
  101. package/dist/types/context/base_context_compactor.d.ts +3 -0
  102. package/dist/types/context/token_based_context_compactor.d.ts +6 -1
  103. package/dist/types/context/trajectory_thought_pruning_compactor.d.ts +27 -0
  104. package/dist/types/events/event.d.ts +8 -0
  105. package/dist/types/models/google_llm.d.ts +15 -1
  106. package/dist/types/models/interactions_utils.d.ts +92 -0
  107. package/dist/types/models/llm_request.d.ts +4 -0
  108. package/dist/types/models/llm_response.d.ts +4 -0
  109. package/dist/types/plugins/base_plugin.d.ts +2 -1
  110. package/dist/types/runner/in_memory_runner.d.ts +7 -1
  111. package/dist/types/runner/runner.d.ts +43 -9
  112. package/dist/types/sessions/base_session_service.d.ts +3 -16
  113. package/dist/types/sessions/session.d.ts +11 -0
  114. package/dist/types/sessions/vertex_ai_session_service.d.ts +9 -1
  115. package/dist/types/tools/consolidate_context_tool.d.ts +19 -0
  116. package/dist/types/tools/forwarding_artifact_service.d.ts +3 -2
  117. package/dist/types/utils/async_hooks_shim.d.ts +10 -0
  118. package/dist/types/utils/client_labels.d.ts +10 -0
  119. package/dist/types/utils/env_aware_utils.d.ts +3 -3
  120. package/dist/types/utils/task.d.ts +24 -0
  121. package/dist/types/version.d.ts +1 -1
  122. package/dist/web/agents/active_streaming_tool.js +6 -1
  123. package/dist/web/agents/context.js +1 -11
  124. package/dist/web/agents/functions.js +36 -15
  125. package/dist/web/agents/instructions.js +23 -5
  126. package/dist/web/agents/invocation_context.js +2 -5
  127. package/dist/web/agents/llm_agent.js +8 -6
  128. package/dist/web/agents/processors/code_execution_request_processor.js +0 -3
  129. package/dist/web/agents/processors/content_processor_utils.js +14 -2
  130. package/dist/web/agents/processors/context_compactor_request_processor.js +4 -2
  131. package/dist/web/agents/processors/interactions_request_processor.js +52 -0
  132. package/dist/web/apps/app.js +49 -0
  133. package/dist/web/apps/resumability_config.js +31 -0
  134. package/dist/web/artifacts/file_artifact_service.js +14 -1
  135. package/dist/web/artifacts/gcs_artifact_service.js +55 -15
  136. package/dist/web/artifacts/in_memory_artifact_service.js +5 -1
  137. package/dist/web/artifacts/scoped_artifact_service.js +86 -0
  138. package/dist/web/artifacts/session_artifact_service.js +7 -0
  139. package/dist/web/auth/oauth2/oauth2_discovery.js +14 -4
  140. package/dist/web/auth/oauth2/oauth2_utils.js +12 -1
  141. package/dist/web/common.js +42 -2
  142. package/dist/web/context/agent_controlled_context_compactor.js +81 -0
  143. package/dist/web/context/token_based_context_compactor.js +42 -10
  144. package/dist/web/context/trajectory_thought_pruning_compactor.js +43 -0
  145. package/dist/web/events/event.js +20 -0
  146. package/dist/web/models/google_llm.js +54 -9
  147. package/dist/web/models/interactions_utils.js +728 -0
  148. package/dist/web/plugins/base_plugin.js +1 -0
  149. package/dist/web/runner/in_memory_runner.js +13 -2
  150. package/dist/web/runner/runner.js +111 -75
  151. package/dist/web/sessions/base_session_service.js +6 -1
  152. package/dist/web/sessions/database_session_service.js +24 -7
  153. package/dist/web/sessions/vertex_ai_session_service.js +17 -3
  154. package/dist/web/skills/loader.js +2 -2
  155. package/dist/web/tools/base_toolset.js +1 -1
  156. package/dist/web/tools/consolidate_context_tool.js +51 -0
  157. package/dist/web/tools/forwarding_artifact_service.js +16 -28
  158. package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +2 -12
  159. package/dist/web/utils/async_hooks_shim.js +24 -0
  160. package/dist/web/utils/client_labels.js +38 -2
  161. package/dist/web/utils/env_aware_utils.js +10 -1
  162. package/dist/web/utils/streaming_utils.js +10 -4
  163. package/dist/web/utils/task.js +34 -0
  164. package/dist/web/version.js +1 -1
  165. package/package.json +2 -2
@@ -330,10 +330,16 @@ class StreamingResponseAggregator {
330
330
  const candidate = (_b = (_a = this.response) == null ? void 0 : _a.candidates) == null ? void 0 : _b[0];
331
331
  const finishReason = (_c = this.finishReason) != null ? _c : candidate == null ? void 0 : candidate.finishReason;
332
332
  return {
333
- content: {
334
- role: "model",
335
- parts: finalParts != null ? finalParts : []
336
- },
333
+ // Only attach a model `content` when there are actual parts to emit. When
334
+ // the turn accumulated no parts (e.g. a function call that was already
335
+ // flushed, followed by a trailing STOP chunk that carries only usage
336
+ // metadata) we still surface that trailing metadata, but MUST NOT emit
337
+ // `content: { parts: [] }`. An empty-parts model turn corrupts the session
338
+ // history: on the next request the Vertex AI backend rejects the whole
339
+ // call with HTTP 400 "Unable to submit request because it must include at
340
+ // least one parts field", which breaks multi-turn tool-using sessions
341
+ // right after the first tool call (google/adk-js#21, #22).
342
+ content: finalParts ? { role: "model", parts: finalParts } : void 0,
337
343
  groundingMetadata: this.groundingMetadata,
338
344
  citationMetadata: this.citationMetadata,
339
345
  errorCode: finishReason === FinishReason.STOP ? void 0 : finishReason,
@@ -0,0 +1,34 @@
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
+ class Task {
9
+ constructor(executable) {
10
+ this.executable = executable;
11
+ this.isDone = false;
12
+ this.abortController = new AbortController();
13
+ const markDone = () => {
14
+ this.isDone = true;
15
+ };
16
+ this.promise = executable(this.abortController.signal);
17
+ this.promise.then(markDone).catch(markDone);
18
+ }
19
+ /**
20
+ * Cancels the task execution.
21
+ */
22
+ cancel() {
23
+ this.abortController.abort();
24
+ }
25
+ /**
26
+ * Returns true if the task has completed (either resolved or rejected).
27
+ */
28
+ done() {
29
+ return this.isDone;
30
+ }
31
+ }
32
+ export {
33
+ Task
34
+ };
@@ -5,7 +5,7 @@ const require = topLevelCreateRequire(import.meta.url);
5
5
  * Copyright 2025 Google LLC
6
6
  * SPDX-License-Identifier: Apache-2.0
7
7
  */
8
- const version = "1.3.0";
8
+ const version = "1.4.0";
9
9
  export {
10
10
  version
11
11
  };
@@ -3,12 +3,13 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ import { Task } from '../utils/task.js';
6
7
  import { LiveRequestQueue } from './live_request_queue.js';
7
8
  /**
8
9
  * The parameters for creating an ActiveStreamingTool.
9
10
  */
10
11
  export interface ActiveStreamingToolParams {
11
- task?: Promise<void>;
12
+ task?: Task<void> | Promise<void>;
12
13
  stream?: LiveRequestQueue;
13
14
  }
14
15
  /**
@@ -17,10 +18,8 @@ export interface ActiveStreamingToolParams {
17
18
  export declare class ActiveStreamingTool {
18
19
  /**
19
20
  * The active task of this streaming tool.
20
- * TODO: Replace 'Promise<void>' with a proper Task type if available in this
21
- * env.
22
21
  */
23
- task?: Promise<void>;
22
+ task?: Task<void>;
24
23
  /**
25
24
  * The active (input) streams of this streaming tool.
26
25
  */
@@ -3,12 +3,13 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { Content, FunctionCall } from '@google/genai';
6
+ import { FunctionCall } from '@google/genai';
7
7
  import { InvocationContext } from '../agents/invocation_context.js';
8
8
  import { Event } from '../events/event.js';
9
9
  import { BaseTool } from '../tools/base_tool.js';
10
10
  import { ToolConfirmation } from '../tools/tool_confirmation.js';
11
11
  import { SingleAfterToolCallback, SingleBeforeToolCallback } from './llm_agent.js';
12
+ export declare const AF_FUNCTION_CALL_ID_PREFIX = "adk-";
12
13
  export declare const REQUEST_EUC_FUNCTION_CALL_NAME = "adk_request_credential";
13
14
  export declare const REQUEST_CONFIRMATION_FUNCTION_CALL_NAME = "adk_request_confirmation";
14
15
  export declare const functionsExportedForTestingOnly: {
@@ -24,14 +25,6 @@ export declare function generateClientFunctionCallId(): string;
24
25
  * unique client-side ID to each one that doesn't already have an ID.
25
26
  */
26
27
  export declare function populateClientFunctionCallId(modelResponseEvent: Event): void;
27
- /**
28
- * Removes the client-generated function call IDs from a given content object.
29
- *
30
- * When sending content back to the server, these IDs are
31
- * specific to the client-side and should not be included in requests to the
32
- * model.
33
- */
34
- export declare function removeClientFunctionCallId(content: Content): void;
35
28
  /**
36
29
  * Returns a set of function call ids of the long running tools.
37
30
  */
@@ -90,3 +83,13 @@ export declare function handleFunctionCallList({ invocationContext, functionCall
90
83
  * Merges a list of function response events into a single event.
91
84
  */
92
85
  export declare function mergeParallelFunctionResponseEvents(functionResponseEvents: Event[]): Event;
86
+ /**
87
+ * Finds the function call event that matches the function call ID.
88
+ * Mirrors Python ADK's `find_event_by_function_call_id`.
89
+ */
90
+ export declare function findEventByFunctionCallId(events: Event[], functionCallId: string, endIndex?: number): Event | undefined;
91
+ /**
92
+ * Finds the function call event that matches the function response ID of the last event.
93
+ * Mirrors Python ADK's `find_matching_function_call`.
94
+ */
95
+ export declare function findMatchingFunctionCall(events: Event[]): Event | undefined;
@@ -4,7 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { Content } from '@google/genai';
7
- import { BaseArtifactService } from '../artifacts/base_artifact_service.js';
7
+ import { SessionArtifactService } from '../artifacts/session_artifact_service.js';
8
8
  import { BaseCredentialService } from '../auth/credential_service/base_credential_service.js';
9
9
  import { BaseMemoryService } from '../memory/base_memory_service.js';
10
10
  import { PluginManager } from '../plugins/plugin_manager.js';
@@ -18,7 +18,7 @@ import { TranscriptionEntry } from './transcription_entry.js';
18
18
  * The parameters for creating an invocation context.
19
19
  */
20
20
  export interface InvocationContextParams {
21
- artifactService?: BaseArtifactService;
21
+ artifactService?: SessionArtifactService;
22
22
  sessionService?: BaseSessionService;
23
23
  memoryService?: BaseMemoryService;
24
24
  credentialService?: BaseCredentialService;
@@ -74,7 +74,7 @@ export interface InvocationContextParams {
74
74
  * ```
75
75
  */
76
76
  export declare class InvocationContext {
77
- readonly artifactService?: BaseArtifactService;
77
+ readonly artifactService?: SessionArtifactService;
78
78
  readonly sessionService?: BaseSessionService;
79
79
  readonly memoryService?: BaseMemoryService;
80
80
  readonly credentialService?: BaseCredentialService;
@@ -120,6 +120,10 @@ export declare class InvocationContext {
120
120
  /**
121
121
  * A container to keep track of different kinds of costs incurred as a part of
122
122
  * this invocation.
123
+ *
124
+ * This is shared across every agent context of the same invocation (see the
125
+ * constructor) so run-wide limits such as `maxLlmCalls` are enforced for the
126
+ * whole invocation rather than resetting for each agent/sub-agent.
123
127
  */
124
128
  private readonly invocationCostManager;
125
129
  /**
@@ -5,6 +5,14 @@
5
5
  */
6
6
  import { Content } from '@google/genai';
7
7
  import { Event } from '../../events/event.js';
8
+ /**
9
+ * Removes the client-generated function call IDs from a given content object.
10
+ *
11
+ * When sending content back to the server, these IDs are
12
+ * specific to the client-side and should not be included in requests to the
13
+ * model.
14
+ */
15
+ export declare function removeClientFunctionCallId(content: Content): void;
8
16
  /**
9
17
  * Get the contents for the LLM request.
10
18
  *
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Event } from '../../events/event.js';
7
+ import { LlmRequest } from '../../models/llm_request.js';
8
+ import { InvocationContext } from '../invocation_context.js';
9
+ import { BaseLlmRequestProcessor } from './base_llm_processor.js';
10
+ /**
11
+ * Request processor for Gemini Interactions API.
12
+ * Resolves the previous interaction ID from the session history.
13
+ */
14
+ export declare class InteractionsRequestProcessor implements BaseLlmRequestProcessor {
15
+ runAsync(invocationContext: InvocationContext, llmRequest: LlmRequest): AsyncGenerator<Event, void, void>;
16
+ }
17
+ export declare const INTERACTIONS_REQUEST_PROCESSOR: InteractionsRequestProcessor;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { BaseAgent } from '../agents/base_agent.js';
7
+ import { BasePlugin } from '../plugins/base_plugin.js';
8
+ import { ResumabilityConfig } from './resumability_config.js';
9
+ /**
10
+ * Ensures the provided application name is safe and intuitive.
11
+ */
12
+ export declare function validateAppName(name: string): void;
13
+ /**
14
+ * A unique symbol to identify ADK App classes.
15
+ * Defined once and shared by all App instances.
16
+ */
17
+ declare const APP_SIGNATURE_SYMBOL: unique symbol;
18
+ /**
19
+ * Type guard to check if an object is an instance of App.
20
+ * @param obj The object to check.
21
+ * @returns True if the object is an instance of App, false otherwise.
22
+ */
23
+ export declare function isApp(obj: unknown): obj is App;
24
+ /**
25
+ * Options for initializing an App.
26
+ */
27
+ export interface AppOptions {
28
+ name: string;
29
+ rootAgent: BaseAgent;
30
+ plugins?: BasePlugin[];
31
+ resumabilityConfig?: ResumabilityConfig;
32
+ }
33
+ /**
34
+ * Represents an LLM-backed agentic application.
35
+ *
36
+ * An `App` is the top-level container for an agentic system powered by LLMs.
37
+ * It manages a root agent (`rootAgent`), which serves as the entry point for execution.
38
+ *
39
+ * Exactly one `rootAgent` must be provided.
40
+ *
41
+ * The `plugins` are application-wide components that provide shared capabilities
42
+ * and services to the entire system.
43
+ */
44
+ export declare class App {
45
+ readonly [APP_SIGNATURE_SYMBOL] = true;
46
+ readonly name: string;
47
+ readonly rootAgent: BaseAgent | any;
48
+ readonly plugins: BasePlugin[];
49
+ readonly resumabilityConfig?: ResumabilityConfig;
50
+ constructor(options: AppOptions);
51
+ }
52
+ export {};
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * The configuration of resumability for an application or runner.
8
+ *
9
+ * The "resumability" in ADK refers to the ability to:
10
+ * 1. pause an invocation upon a long-running function call.
11
+ * 2. resume an invocation from the last event, if it's paused or failed midway
12
+ * through.
13
+ */
14
+ export interface ResumabilityConfig {
15
+ /**
16
+ * Whether the app/runner supports agent resumption.
17
+ * If enabled, resumption routing based on matching function responses will be active.
18
+ */
19
+ isResumable: boolean;
20
+ }
21
+ /**
22
+ * Creates a {@link ResumabilityConfig} with default values.
23
+ *
24
+ * @param params Optional partial {@link ResumabilityConfig} overriding defaults.
25
+ * @returns A merged {@link ResumabilityConfig} object.
26
+ */
27
+ export declare function createResumabilityConfig(params?: Partial<ResumabilityConfig>): ResumabilityConfig;
@@ -4,16 +4,11 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { Part } from '@google/genai';
7
+ import { CompositeSessionKey } from '../sessions/session.js';
7
8
  /**
8
9
  * The parameters for `saveArtifact`.
9
10
  */
10
- export interface SaveArtifactRequest {
11
- /** The app name. */
12
- appName: string;
13
- /** The user ID. */
14
- userId: string;
15
- /** The session ID. */
16
- sessionId: string;
11
+ export interface SaveArtifactRequest extends CompositeSessionKey {
17
12
  /** The filename of the artifact. */
18
13
  filename: string;
19
14
  /** The artifact to save. */
@@ -26,13 +21,7 @@ export interface SaveArtifactRequest {
26
21
  /**
27
22
  * The parameters for `loadArtifact`.
28
23
  */
29
- export interface LoadArtifactRequest {
30
- /** The app name. */
31
- appName: string;
32
- /** The user ID. */
33
- userId: string;
34
- /** The session ID. */
35
- sessionId: string;
24
+ export interface LoadArtifactRequest extends CompositeSessionKey {
36
25
  /** The filename of the artifact. */
37
26
  filename: string;
38
27
  /**
@@ -44,37 +33,18 @@ export interface LoadArtifactRequest {
44
33
  /**
45
34
  * The parameters for `listArtifactKeys`.
46
35
  */
47
- export interface ListArtifactKeysRequest {
48
- /** The app name. */
49
- appName: string;
50
- /** The user ID. */
51
- userId: string;
52
- /** The session ID. */
53
- sessionId: string;
54
- }
36
+ export type ListArtifactKeysRequest = CompositeSessionKey;
55
37
  /**
56
38
  * The parameters for `deleteArtifact`.
57
39
  */
58
- export interface DeleteArtifactRequest {
59
- /** The app name. */
60
- appName: string;
61
- /** The user ID. */
62
- userId: string;
63
- /** The session ID. */
64
- sessionId: string;
40
+ export interface DeleteArtifactRequest extends CompositeSessionKey {
65
41
  /** The filename of the artifact. */
66
42
  filename: string;
67
43
  }
68
44
  /**
69
45
  * The parameters for `listVersions`.
70
46
  */
71
- export interface ListVersionsRequest {
72
- /** The app name. */
73
- appName: string;
74
- /** The user ID. */
75
- userId: string;
76
- /** The session ID. */
77
- sessionId: string;
47
+ export interface ListVersionsRequest extends CompositeSessionKey {
78
48
  /** The filename of the artifact. */
79
49
  filename: string;
80
50
  }
@@ -3,11 +3,12 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ import { StorageOptions } from '@google-cloud/storage';
6
7
  import { Part } from '@google/genai';
7
8
  import { ArtifactVersion, BaseArtifactService, DeleteArtifactRequest, ListArtifactKeysRequest, ListVersionsRequest, LoadArtifactRequest, SaveArtifactRequest } from './base_artifact_service.js';
8
9
  export declare class GcsArtifactService implements BaseArtifactService {
9
10
  private readonly bucket;
10
- constructor(bucket: string);
11
+ constructor(bucket: string, options?: StorageOptions);
11
12
  saveArtifact(request: SaveArtifactRequest): Promise<number>;
12
13
  loadArtifact(request: LoadArtifactRequest): Promise<Part | undefined>;
13
14
  listArtifactKeys(request: ListArtifactKeysRequest): Promise<string[]>;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Part } from '@google/genai';
7
+ import { ArtifactVersion, BaseArtifactService } from './base_artifact_service.js';
8
+ import { SessionArtifactService, SessionLoadArtifactRequest, SessionSaveArtifactRequest } from './session_artifact_service.js';
9
+ /**
10
+ * A wrapper that scopes a BaseArtifactService to a specific session.
11
+ */
12
+ export declare class ScopedArtifactService implements SessionArtifactService {
13
+ private readonly delegate;
14
+ private readonly appName;
15
+ private readonly userId;
16
+ private readonly sessionId;
17
+ constructor(delegate: BaseArtifactService, appName: string, userId: string, sessionId: string);
18
+ saveArtifact(request: SessionSaveArtifactRequest): Promise<number>;
19
+ loadArtifact(request: SessionLoadArtifactRequest): Promise<Part | undefined>;
20
+ listArtifactKeys(): Promise<string[]>;
21
+ deleteArtifact(filename: string): Promise<void>;
22
+ listVersions(filename: string): Promise<number[]>;
23
+ listArtifactVersions(filename: string): Promise<ArtifactVersion[]>;
24
+ getArtifactVersion(request: SessionLoadArtifactRequest): Promise<ArtifactVersion | undefined>;
25
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Part } from '@google/genai';
7
+ import { ArtifactVersion } from './base_artifact_service.js';
8
+ export interface SessionSaveArtifactRequest {
9
+ filename: string;
10
+ artifact: Part;
11
+ customMetadata?: Record<string, unknown>;
12
+ }
13
+ export interface SessionLoadArtifactRequest {
14
+ filename: string;
15
+ version?: number;
16
+ }
17
+ export interface SessionArtifactService {
18
+ saveArtifact(request: SessionSaveArtifactRequest): Promise<number>;
19
+ loadArtifact(request: SessionLoadArtifactRequest): Promise<Part | undefined>;
20
+ listArtifactKeys(): Promise<string[]>;
21
+ deleteArtifact(filename: string): Promise<void>;
22
+ listVersions(filename: string): Promise<number[]>;
23
+ listArtifactVersions(filename: string): Promise<ArtifactVersion[]>;
24
+ getArtifactVersion(request: SessionLoadArtifactRequest): Promise<ArtifactVersion | undefined>;
25
+ }
@@ -36,3 +36,14 @@ export declare class OAuth2DiscoveryManager {
36
36
  */
37
37
  discoverResourceMetadata(resourceUrl: string): Promise<ProtectedResourceMetadata | undefined>;
38
38
  }
39
+ /**
40
+ * Normalises the hostname returned by the WHATWG URL parser so that
41
+ * IPv4-mapped IPv6 addresses (e.g. [::ffff:7f00:1]) are converted to
42
+ * their canonical dotted-decimal IPv4 form (127.0.0.1) before any
43
+ * blocklist checks are applied.
44
+ *
45
+ * Without this step an attacker can bypass every IPv4 block by encoding
46
+ * the address as its IPv4-mapped IPv6 equivalent (CWE-918).
47
+ */
48
+ export declare function normaliseHostname(raw: string): string;
49
+ export declare function validateDiscoveryUrl(urlStr: string): boolean;
@@ -8,7 +8,7 @@ export type { ActiveStreamingToolParams } from './agents/active_streaming_tool.j
8
8
  export { BaseAgent, isBaseAgent } from './agents/base_agent.js';
9
9
  export type { AfterAgentCallback, BaseAgentConfig, BeforeAgentCallback, SingleAgentCallback, } from './agents/base_agent.js';
10
10
  export { Context } from './agents/context.js';
11
- export { functionsExportedForTestingOnly } from './agents/functions.js';
11
+ export { findEventByFunctionCallId, findMatchingFunctionCall, functionsExportedForTestingOnly, } from './agents/functions.js';
12
12
  export { InvocationContext } from './agents/invocation_context.js';
13
13
  export type { InvocationContextParams } from './agents/invocation_context.js';
14
14
  export { LiveRequestQueue } from './agents/live_request_queue.js';
@@ -22,6 +22,7 @@ export { AgentTransferLlmRequestProcessor } from './agents/processors/agent_tran
22
22
  export { BaseLlmRequestProcessor, BaseLlmResponseProcessor, } from './agents/processors/base_llm_processor.js';
23
23
  export { CONTENT_REQUEST_PROCESSOR, ContentRequestProcessor, } from './agents/processors/content_request_processor.js';
24
24
  export { ContextCompactorRequestProcessor } from './agents/processors/context_compactor_request_processor.js';
25
+ export { INTERACTIONS_REQUEST_PROCESSOR, InteractionsRequestProcessor, } from './agents/processors/interactions_request_processor.js';
25
26
  export { ReadonlyContext } from './agents/readonly_context.js';
26
27
  export { RoutedAgent, isRoutedAgent } from './agents/routed_agent.js';
27
28
  export type { AgentRouter, RoutedAgentConfig } from './agents/routed_agent.js';
@@ -29,8 +30,11 @@ export { StreamingMode } from './agents/run_config.js';
29
30
  export type { RunConfig } from './agents/run_config.js';
30
31
  export { SequentialAgent, isSequentialAgent } from './agents/sequential_agent.js';
31
32
  export type { TranscriptionEntry } from './agents/transcription_entry.js';
33
+ export { createResumabilityConfig } from './apps/resumability_config.js';
34
+ export type { ResumabilityConfig } from './apps/resumability_config.js';
32
35
  export type { BaseArtifactService, DeleteArtifactRequest, ListArtifactKeysRequest, ListVersionsRequest, LoadArtifactRequest, SaveArtifactRequest, } from './artifacts/base_artifact_service.js';
33
36
  export { InMemoryArtifactService } from './artifacts/in_memory_artifact_service.js';
37
+ export type { SessionArtifactService, SessionLoadArtifactRequest, SessionSaveArtifactRequest, } from './artifacts/session_artifact_service.js';
34
38
  export { AuthCredentialTypes } from './auth/auth_credential.js';
35
39
  export type { AuthCredential, HttpAuth, HttpCredentials, OAuth2Auth, ServiceAccount, ServiceAccountCredential, } from './auth/auth_credential.js';
36
40
  export { AuthHandler } from './auth/auth_handler.js';
@@ -53,12 +57,15 @@ export { BaseCodeExecutor } from './code_executors/base_code_executor.js';
53
57
  export type { ExecuteCodeParams } from './code_executors/base_code_executor.js';
54
58
  export { BuiltInCodeExecutor } from './code_executors/built_in_code_executor.js';
55
59
  export { CodeExecutionLanguage, FileContentEncoding, type CodeExecutionInput, type CodeExecutionResult, type File, } from './code_executors/code_execution_utils.js';
60
+ export { AgentControlledContextCompactor } from './context/agent_controlled_context_compactor.js';
56
61
  export type { BaseContextCompactor } from './context/base_context_compactor.js';
57
62
  export type { BaseSummarizer } from './context/summarizers/base_summarizer.js';
58
63
  export { LlmSummarizer } from './context/summarizers/llm_summarizer.js';
59
64
  export type { LlmSummarizerOptions } from './context/summarizers/llm_summarizer.js';
60
65
  export { TokenBasedContextCompactor } from './context/token_based_context_compactor.js';
61
66
  export type { TokenBasedContextCompactorOptions } from './context/token_based_context_compactor.js';
67
+ export { TrajectoryThoughtPruningCompactor } from './context/trajectory_thought_pruning_compactor.js';
68
+ export type { TrajectoryThoughtPruningCompactorOptions } from './context/trajectory_thought_pruning_compactor.js';
62
69
  export { TruncatingContextCompactor } from './context/truncating_context_compactor.js';
63
70
  export type { TruncatingContextCompactorOptions } from './context/truncating_context_compactor.js';
64
71
  export { isCompactedEvent } from './events/compacted_event.js';
@@ -94,13 +101,13 @@ export { PluginManager } from './plugins/plugin_manager.js';
94
101
  export { InMemoryPolicyEngine, PolicyOutcome, REQUEST_CONFIRMATION_FUNCTION_CALL_NAME, SecurityPlugin, getAskUserConfirmationFunctionCalls, } from './plugins/security_plugin.js';
95
102
  export type { BasePolicyEngine, PolicyCheckResult, ToolCallPolicyContext, } from './plugins/security_plugin.js';
96
103
  export { InMemoryRunner } from './runner/in_memory_runner.js';
97
- export { Runner, isRunner } from './runner/runner.js';
104
+ export { Runner, determineAgentForResumption, findEventByLastFunctionResponseId, isRoutableLlmAgent, isRunner, } from './runner/runner.js';
98
105
  export type { RunnerConfig } from './runner/runner.js';
99
106
  export { BaseSessionService } from './sessions/base_session_service.js';
100
107
  export type { AppendEventRequest, CreateSessionRequest, DeleteSessionRequest, GetSessionConfig, GetSessionRequest, ListSessionsRequest, ListSessionsResponse, } from './sessions/base_session_service.js';
101
108
  export { InMemorySessionService } from './sessions/in_memory_session_service.js';
102
109
  export { createSession } from './sessions/session.js';
103
- export type { Session } from './sessions/session.js';
110
+ export type { CompositeSessionKey, Session } from './sessions/session.js';
104
111
  export { State } from './sessions/state.js';
105
112
  export { AgentTool, isAgentTool } from './tools/agent_tool.js';
106
113
  export type { AgentToolConfig } from './tools/agent_tool.js';
@@ -108,6 +115,7 @@ export { BaseTool, isBaseTool } from './tools/base_tool.js';
108
115
  export type { BaseToolParams, RunAsyncToolRequest, ToolProcessLlmRequest, } from './tools/base_tool.js';
109
116
  export { BaseToolset, isBaseToolset } from './tools/base_toolset.js';
110
117
  export type { ToolPredicate } from './tools/base_toolset.js';
118
+ export { ConsolidateContextTool } from './tools/consolidate_context_tool.js';
111
119
  export { EXIT_LOOP, ExitLoopTool } from './tools/exit_loop_tool.js';
112
120
  export { FunctionTool, isFunctionTool } from './tools/function_tool.js';
113
121
  export type { ToolExecuteArgument, ToolExecuteFunction, ToolInputParameters, ToolOptions, } from './tools/function_tool.js';
@@ -122,10 +130,13 @@ export { URL_CONTEXT, UrlContextTool } from './tools/url_context_tool.js';
122
130
  export { VertexAiSearchTool } from './tools/vertex_ai_search_tool.js';
123
131
  export type { DataStoreParams, SearchEngineParams, VertexAISearchConfig, VertexAISearchDataStoreSpec, VertexAiSearchToolParams, } from './tools/vertex_ai_search_tool.js';
124
132
  export { VertexRagRetrievalTool } from './tools/vertex_rag_retrieval_tool.js';
133
+ export { getClientLabels, runWithClientLabel } from './utils/client_labels.js';
125
134
  export { LogLevel, getLogger, setLogLevel, setLogger } from './utils/logger.js';
126
135
  export type { Logger } from './utils/logger.js';
127
136
  export { isGemini2OrAbove, isGemini3xFlashLive } from './utils/model_name.js';
128
137
  export { zodObjectToSchema } from './utils/simple_zod_to_json.js';
138
+ export { Task } from './utils/task.js';
139
+ export type { TaskExecutable } from './utils/task.js';
129
140
  export { GoogleLLMVariant } from './utils/variant_utils.js';
130
141
  export { version } from './version.js';
131
142
  export { GCPSkillRegistry } from './skills/gcp_skill_registry.js';
@@ -138,6 +149,11 @@ export { LoadSkillResourceTool } from './tools/skill/load_skill_resource_tool.js
138
149
  export { LoadSkillTool } from './tools/skill/load_skill_tool.js';
139
150
  export { SearchSkillsTool } from './tools/skill/search_skills_tool.js';
140
151
  export { SkillToolset } from './tools/skill/skill_toolset.js';
152
+ export * from './artifacts/base_artifact_service.js';
153
+ export * from './features/feature_registry.js';
154
+ export * from './memory/base_memory_service.js';
155
+ export * from './sessions/base_session_service.js';
156
+ export * from './tools/base_tool.js';
141
157
  export { OpenApiSpecParser } from './tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js';
142
158
  export type { OperationEndpoint, ParsedOperation, } from './tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js';
143
159
  export { OperationParser } from './tools/openapi_tool/openapi_spec_parser/operation_parser.js';
@@ -146,6 +162,7 @@ export { ToolAuthHandler } from './tools/openapi_tool/openapi_spec_parser/tool_a
146
162
  export type { AuthPreparationResult } from './tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js';
147
163
  export { OpenAPIToolset } from './tools/openapi_tool/openapi_toolset.js';
148
164
  export { RestApiTool, createRestApiTool, } from './tools/openapi_tool/rest_api_tool.js';
165
+ export * from './apps/app.js';
149
166
  export * from './artifacts/base_artifact_service.js';
150
167
  export * from './features/feature_registry.js';
151
168
  export * from './memory/base_memory_service.js';
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { InvocationContext } from '../agents/invocation_context.js';
7
+ import { ContextCompactionTrigger } from '../plugins/base_plugin.js';
8
+ import { BaseContextCompactor } from './base_context_compactor.js';
9
+ import { BaseSummarizer } from './summarizers/base_summarizer.js';
10
+ /**
11
+ * A context compactor that triggers compaction when the agent explicitly
12
+ * requests it via the `ConsolidateContextTool`.
13
+ */
14
+ export declare class AgentControlledContextCompactor implements BaseContextCompactor {
15
+ readonly trigger = ContextCompactionTrigger.AgentControlled;
16
+ private readonly summarizer;
17
+ constructor(options: {
18
+ summarizer: BaseSummarizer;
19
+ });
20
+ shouldCompact(invocationContext: InvocationContext): boolean;
21
+ compact(invocationContext: InvocationContext): Promise<void>;
22
+ private clearFlags;
23
+ private getActiveEvents;
24
+ }
@@ -4,10 +4,13 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { InvocationContext } from '../agents/invocation_context.js';
7
+ import { ContextCompactionTrigger } from '../plugins/base_plugin.js';
7
8
  /**
8
9
  * Interface for compacting the context history in an agent session.
9
10
  */
10
11
  export interface BaseContextCompactor {
12
+ /** The trigger associated with this compactor. */
13
+ readonly trigger?: ContextCompactionTrigger;
11
14
  /**
12
15
  * Determines whether the context should be compacted.
13
16
  *
@@ -7,7 +7,12 @@ import { InvocationContext } from '../agents/invocation_context.js';
7
7
  import { BaseContextCompactor } from './base_context_compactor.js';
8
8
  import { BaseSummarizer } from './summarizers/base_summarizer.js';
9
9
  export interface TokenBasedContextCompactorOptions {
10
- /** The maximum number of tokens to retain in the session history before compaction. */
10
+ /**
11
+ * Prompt-size threshold (in tokens) that triggers compaction. Compared
12
+ * against the most recently observed LLM request size
13
+ * (`usageMetadata.promptTokenCount`), falling back to a character-based
14
+ * estimate of the effective contents when no usage metadata is available.
15
+ */
11
16
  tokenThreshold: number;
12
17
  /**
13
18
  * The minimum number of raw events to keep at the end of the session.
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { InvocationContext } from '../agents/invocation_context.js';
7
+ import { BaseContextCompactor } from './base_context_compactor.js';
8
+ /**
9
+ * Options for TrajectoryThoughtPruningCompactor.
10
+ */
11
+ export interface TrajectoryThoughtPruningCompactorOptions {
12
+ /**
13
+ * The minimum number of raw events to keep at the end of the session.
14
+ * Compaction will not affect these tail events.
15
+ */
16
+ eventRetentionSize: number;
17
+ }
18
+ /**
19
+ * A context compactor that prunes thought parts from older events in the session history.
20
+ * Preserves the causal history (actions and observations) while reducing token usage.
21
+ */
22
+ export declare class TrajectoryThoughtPruningCompactor implements BaseContextCompactor {
23
+ private readonly eventRetentionSize;
24
+ constructor(options: TrajectoryThoughtPruningCompactorOptions);
25
+ shouldCompact(invocationContext: InvocationContext): boolean | Promise<boolean>;
26
+ compact(invocationContext: InvocationContext): void | Promise<void>;
27
+ }
@@ -82,6 +82,14 @@ export declare function hasTrailingCodeExecutionResult(event: Event): boolean;
82
82
  * @returns A single string with the combined text.
83
83
  */
84
84
  export declare function stringifyContent(event: Event): string;
85
+ /**
86
+ * Returns whether the event contains any thought parts.
87
+ */
88
+ export declare function hasThoughts(event: Event): boolean;
89
+ /**
90
+ * Returns a copy of the event with all thought parts removed.
91
+ */
92
+ export declare function pruneThoughts(event: Event): Event;
85
93
  /**
86
94
  * Generates a new unique ID for the event.
87
95
  */