@google/adk 2.1.0 → 2.2.1

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/a2a/agent_card.js +8 -0
  2. package/dist/cjs/a2a/agent_executor.js +8 -3
  3. package/dist/cjs/a2a/event_converter_utils.js +5 -1
  4. package/dist/cjs/a2a/metadata_converter_utils.js +2 -1
  5. package/dist/cjs/agents/llm_agent.js +15 -1
  6. package/dist/cjs/agents/processors/content_processor_utils.js +10 -2
  7. package/dist/cjs/agents/processors/nl_planning_processor.js +114 -0
  8. package/dist/cjs/artifacts/gcs_artifact_service.js +13 -7
  9. package/dist/cjs/auth/auth_credential.js +12 -2
  10. package/dist/cjs/code_executors/code_execution_utils.js +3 -3
  11. package/dist/cjs/common.js +63 -0
  12. package/dist/cjs/events/abort_events.js +135 -0
  13. package/dist/cjs/events/internal_metadata.js +131 -0
  14. package/dist/cjs/examples/example.js +92 -0
  15. package/dist/cjs/examples/example_util.js +28 -4
  16. package/dist/cjs/examples/index.js +39 -0
  17. package/dist/cjs/examples/vertex_ai_example_store.js +39 -0
  18. package/dist/cjs/index.js +46 -0
  19. package/dist/cjs/memory/vertex_ai_memory_bank_service.js +17 -5
  20. package/dist/cjs/models/base_llm.js +1 -6
  21. package/dist/cjs/models/chrome_prompt_llm.js +16 -2
  22. package/dist/cjs/models/chrome_prompt_utils.js +54 -2
  23. package/dist/cjs/models/gemini_continuation.js +232 -0
  24. package/dist/cjs/models/gemini_llm_connection.js +5 -4
  25. package/dist/cjs/planners/base_planner.js +56 -0
  26. package/dist/cjs/planners/built_in_planner.js +85 -0
  27. package/dist/cjs/planners/plan_re_act_planner.js +172 -0
  28. package/dist/cjs/plugins/base_plugin.js +46 -61
  29. package/dist/cjs/plugins/debug_logging_plugin.js +653 -0
  30. package/dist/cjs/plugins/plugin_manager.js +1 -1
  31. package/dist/cjs/plugins/tool_call_integrity_plugin.js +364 -0
  32. package/dist/cjs/runner/runner.js +17 -3
  33. package/dist/cjs/tools/example_tool.js +1 -1
  34. package/dist/cjs/tools/mcp/mcp_session_manager.js +14 -8
  35. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +281 -2
  36. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +15 -1
  37. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.js +70 -0
  38. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +120 -0
  39. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +10 -10
  40. package/dist/cjs/tools/openapi_tool/common/common.js +139 -0
  41. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +11 -6
  42. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +73 -13
  43. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +146 -34
  44. package/dist/cjs/tools/openapi_tool/openapi_toolset.js +14 -2
  45. package/dist/cjs/tools/openapi_tool/rest_api_tool.js +90 -28
  46. package/dist/cjs/tools/skill/skill_toolset.js +2 -0
  47. package/dist/cjs/tools/tool_context.js +41 -0
  48. package/dist/cjs/tools/webmcp/index.js +37 -0
  49. package/dist/cjs/tools/webmcp/webmcp_tool.js +156 -0
  50. package/dist/cjs/tools/webmcp/webmcp_toolset.js +116 -0
  51. package/dist/cjs/tools/webmcp/webmcp_types.js +50 -0
  52. package/dist/cjs/utils/case_utils.js +52 -2
  53. package/dist/cjs/utils/client_labels.js +67 -0
  54. package/dist/cjs/utils/gemini_schema_util.js +103 -3
  55. package/dist/cjs/utils/hash_utils.js +73 -0
  56. package/dist/cjs/utils/live_connection_utils.js +10 -9
  57. package/dist/cjs/utils/model_name.js +17 -2
  58. package/dist/cjs/utils/simple_zod_to_json.js +5 -0
  59. package/dist/cjs/version.js +1 -1
  60. package/dist/esm/a2a/agent_card.js +8 -0
  61. package/dist/esm/a2a/agent_executor.js +8 -3
  62. package/dist/esm/a2a/event_converter_utils.js +5 -1
  63. package/dist/esm/a2a/metadata_converter_utils.js +2 -1
  64. package/dist/esm/agents/llm_agent.js +18 -1
  65. package/dist/esm/agents/processors/content_processor_utils.js +10 -2
  66. package/dist/esm/agents/processors/nl_planning_processor.js +87 -0
  67. package/dist/esm/artifacts/gcs_artifact_service.js +13 -7
  68. package/dist/esm/auth/auth_credential.js +11 -1
  69. package/dist/esm/code_executors/code_execution_utils.js +3 -3
  70. package/dist/esm/common.js +58 -2
  71. package/dist/esm/events/abort_events.js +110 -0
  72. package/dist/esm/events/internal_metadata.js +97 -0
  73. package/dist/esm/examples/example.js +85 -0
  74. package/dist/esm/examples/example_util.js +25 -3
  75. package/dist/esm/examples/index.js +11 -0
  76. package/dist/esm/examples/vertex_ai_example_store.js +11 -0
  77. package/dist/esm/index.js +51 -1
  78. package/dist/esm/memory/vertex_ai_memory_bank_service.js +17 -5
  79. package/dist/esm/models/base_llm.js +2 -7
  80. package/dist/esm/models/chrome_prompt_llm.js +20 -3
  81. package/dist/esm/models/chrome_prompt_utils.js +51 -2
  82. package/dist/esm/models/gemini_continuation.js +205 -0
  83. package/dist/esm/models/gemini_llm_connection.js +6 -5
  84. package/dist/esm/planners/base_planner.js +28 -0
  85. package/dist/esm/planners/built_in_planner.js +57 -0
  86. package/dist/esm/planners/plan_re_act_planner.js +145 -0
  87. package/dist/esm/plugins/base_plugin.js +46 -61
  88. package/dist/esm/plugins/debug_logging_plugin.js +615 -0
  89. package/dist/esm/plugins/plugin_manager.js +1 -1
  90. package/dist/esm/plugins/tool_call_integrity_plugin.js +339 -0
  91. package/dist/esm/runner/runner.js +20 -3
  92. package/dist/esm/tools/example_tool.js +1 -1
  93. package/dist/esm/tools/mcp/mcp_session_manager.js +14 -8
  94. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +272 -1
  95. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +15 -1
  96. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.js +43 -0
  97. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +93 -0
  98. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +10 -12
  99. package/dist/esm/tools/openapi_tool/common/common.js +112 -0
  100. package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +11 -6
  101. package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +80 -13
  102. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +146 -33
  103. package/dist/esm/tools/openapi_tool/openapi_toolset.js +14 -2
  104. package/dist/esm/tools/openapi_tool/rest_api_tool.js +89 -28
  105. package/dist/esm/tools/skill/skill_toolset.js +2 -0
  106. package/dist/esm/tools/tool_context.js +15 -0
  107. package/dist/esm/tools/webmcp/index.js +10 -0
  108. package/dist/esm/tools/webmcp/webmcp_tool.js +131 -0
  109. package/dist/esm/tools/webmcp/webmcp_toolset.js +89 -0
  110. package/dist/esm/tools/webmcp/webmcp_types.js +22 -0
  111. package/dist/esm/utils/case_utils.js +49 -1
  112. package/dist/esm/utils/client_labels.js +65 -0
  113. package/dist/esm/utils/gemini_schema_util.js +102 -3
  114. package/dist/esm/utils/hash_utils.js +45 -0
  115. package/dist/esm/utils/live_connection_utils.js +11 -10
  116. package/dist/esm/utils/model_name.js +15 -2
  117. package/dist/esm/utils/simple_zod_to_json.js +5 -0
  118. package/dist/esm/version.js +1 -1
  119. package/dist/types/agents/llm_agent.d.ts +12 -1
  120. package/dist/types/agents/processors/nl_planning_processor.d.ts +30 -0
  121. package/dist/types/auth/auth_credential.d.ts +9 -0
  122. package/dist/types/common.d.ts +19 -4
  123. package/dist/types/events/abort_events.d.ts +43 -0
  124. package/dist/types/events/internal_metadata.d.ts +78 -0
  125. package/dist/types/examples/base_example_provider.d.ts +2 -2
  126. package/dist/types/examples/example.d.ts +75 -0
  127. package/dist/types/examples/example_util.d.ts +13 -2
  128. package/dist/types/examples/index.d.ts +18 -0
  129. package/dist/types/examples/vertex_ai_example_store.d.ts +7 -0
  130. package/dist/types/index.d.ts +12 -3
  131. package/dist/types/memory/memory_entry.d.ts +15 -0
  132. package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +9 -0
  133. package/dist/types/models/chrome_prompt_utils.d.ts +29 -0
  134. package/dist/types/models/gemini_continuation.d.ts +59 -0
  135. package/dist/types/planners/base_planner.d.ts +50 -0
  136. package/dist/types/planners/built_in_planner.d.ts +53 -0
  137. package/dist/types/planners/plan_re_act_planner.d.ts +21 -0
  138. package/dist/types/plugins/base_plugin.d.ts +52 -52
  139. package/dist/types/plugins/debug_logging_plugin.d.ts +157 -0
  140. package/dist/types/plugins/tool_call_integrity_plugin.d.ts +116 -0
  141. package/dist/types/skills/skill_registry.d.ts +8 -0
  142. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +110 -1
  143. package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +32 -2
  144. package/dist/types/tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.d.ts +35 -0
  145. package/dist/types/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.d.ts +54 -0
  146. package/dist/types/tools/openapi_tool/common/common.d.ts +60 -0
  147. package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +7 -0
  148. package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +56 -2
  149. package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +73 -5
  150. package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +11 -0
  151. package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +42 -8
  152. package/dist/types/tools/tool_context.d.ts +19 -0
  153. package/dist/types/tools/webmcp/index.d.ts +12 -0
  154. package/dist/types/tools/webmcp/webmcp_tool.d.ts +47 -0
  155. package/dist/types/tools/webmcp/webmcp_toolset.d.ts +67 -0
  156. package/dist/types/tools/webmcp/webmcp_types.d.ts +69 -0
  157. package/dist/types/utils/case_utils.d.ts +36 -0
  158. package/dist/types/utils/client_labels.d.ts +33 -0
  159. package/dist/types/utils/gemini_schema_util.d.ts +13 -0
  160. package/dist/types/utils/hash_utils.d.ts +25 -0
  161. package/dist/types/utils/logger.d.ts +10 -2
  162. package/dist/types/utils/model_name.d.ts +30 -2
  163. package/dist/types/version.d.ts +1 -1
  164. package/dist/web/index_web.js +113 -80
  165. package/dist/web/index_web.js.map +4 -4
  166. package/package.json +8 -2
@@ -3,6 +3,7 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ import { Session } from '../sessions/session.js';
6
7
  import { BaseExampleProvider } from './base_example_provider.js';
7
8
  import { Example } from './example.js';
8
9
  /**
@@ -20,6 +21,15 @@ import { Example } from './example.js';
20
21
  * suitable for inclusion in a system instruction.
21
22
  */
22
23
  export declare function convertExamplesToText(examples: Example[], model?: string): string;
24
+ /**
25
+ * Gets the latest message from the user.
26
+ *
27
+ * @param session - The session to inspect.
28
+ * @returns The latest message from the user. If not found, returns an empty
29
+ * string.
30
+ */
31
+ export declare function getLatestMessageFromUser(session: Session): string;
32
+ export declare const _getLatestMessageFromUser: typeof getLatestMessageFromUser;
23
33
  /**
24
34
  * Builds the few-shot portion of a system instruction from a list of examples
25
35
  * or a {@link BaseExampleProvider}.
@@ -31,8 +41,9 @@ export declare function convertExamplesToText(examples: Example[], model?: strin
31
41
  * when `examples` is a provider. Ignored when `examples` is an array.
32
42
  * @param model - Optional model name forwarded to
33
43
  * {@link convertExamplesToText} to select the function-call fence style.
34
- * @returns A formatted string ready to be appended to a system instruction.
44
+ * @returns A promise resolving to a formatted string ready to be appended to a
45
+ * system instruction.
35
46
  * @throws {Error} When `examples` is neither an array nor a
36
47
  * {@link BaseExampleProvider}.
37
48
  */
38
- export declare function buildExampleSi(examples: Example[] | BaseExampleProvider, query: string, model?: string): string;
49
+ export declare function buildExampleSi(examples: Example[] | BaseExampleProvider, query: string, model?: string): Promise<string>;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Examples subsystem barrel export.
8
+ *
9
+ * Re-exports all `examples` modules (`Example`, `BaseExampleProvider`,
10
+ * `VertexAiExampleStore`, `example_util`) alongside compatibility references
11
+ * for `BaseCodeExecutor`, `BuiltInCodeExecutor`, `CodeExecutorContext`,
12
+ * `ContainerCodeExecutor`, `UnsafeLocalCodeExecutor`, `VertexAiCodeExecutor`,
13
+ * and `code_execution_utils`.
14
+ */
15
+ export * from './base_example_provider.js';
16
+ export * from './example.js';
17
+ export * from './example_util.js';
18
+ export * from './vertex_ai_example_store.js';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export { VertexAiExampleStore } from './example.js';
7
+ export type { ExampleStoreApiClient, SearchExamplesRequest, SearchExamplesResponse, SearchExamplesResult, StoredContentsExample, } from './example.js';
@@ -29,14 +29,23 @@ export type { GCPSkillRegistryOptions } from './skills/gcp_skill_registry.js';
29
29
  export { loadAllSkillsInDir, loadSkillFromDir, loadSkillFromZipBuffer, validateSkillDir, } from './skills/loader.js';
30
30
  export { LOAD_WEB_PAGE, loadWebPage } from './tools/load_web_page.js';
31
31
  export type { LoadWebPageOptions } from './tools/load_web_page.js';
32
+ export { credentialToParam, dictToAuthScheme, INTERNAL_AUTH_PREFIX, openidDictToSchemeCredential, openidUrlToSchemeCredential, serviceAccountDictToSchemeCredential, serviceAccountSchemeCredential, tokenToSchemeCredential, } from './tools/openapi_tool/auth/auth_helpers.js';
33
+ export { AutoAuthCredentialExchanger } from './tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js';
34
+ export type { CustomCredentialExchangers } from './tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js';
35
+ export { AuthCredentialMissingError, BaseAuthCredentialExchanger, } from './tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.js';
36
+ export { exchangeCredential, OAuth2BearerExchanger, } from './tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js';
37
+ export { ServiceAccountCredentialExchanger } from './tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js';
38
+ export { createApiParameter, generateParamDoc, generateReturnDoc, getTypeHint, } from './tools/openapi_tool/common/common.js';
39
+ export type { ApiParameterInit } from './tools/openapi_tool/common/common.js';
32
40
  export { OpenApiSpecParser } from './tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js';
33
41
  export type { OperationEndpoint, ParsedOperation, } from './tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js';
34
42
  export { OperationParser } from './tools/openapi_tool/openapi_spec_parser/operation_parser.js';
35
43
  export type { ApiParameter } from './tools/openapi_tool/openapi_spec_parser/operation_parser.js';
36
- export { ToolAuthHandler } from './tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js';
37
- export type { AuthPreparationResult } from './tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js';
44
+ export { ToolAuthHandler, ToolContextCredentialStore, } from './tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js';
45
+ export type { AuthPreparationResult, ToolAuthHandlerOptions, } from './tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js';
38
46
  export { OpenAPIToolset } from './tools/openapi_tool/openapi_toolset.js';
39
- export { createRestApiTool, RestApiTool, } from './tools/openapi_tool/rest_api_tool.js';
47
+ export { createRestApiTool, createRestApiToolFromJson, RestApiTool, } from './tools/openapi_tool/rest_api_tool.js';
48
+ export type { ParsedOperationInput } from './tools/openapi_tool/rest_api_tool.js';
40
49
  export { FilesRetrieval } from './tools/retrieval/files_retrieval.js';
41
50
  export type { FilesRetrievalConstructorParams, FilesRetrievalParams, } from './tools/retrieval/files_retrieval.js';
42
51
  export { LoadSkillResourceTool } from './tools/skill/load_skill_resource_tool.js';
@@ -15,6 +15,21 @@ export interface MemoryEntry {
15
15
  * The content of the memory entry, as originally produced during a session.
16
16
  */
17
17
  content: Content;
18
+ /**
19
+ * The unique identifier of the memory.
20
+ *
21
+ * When set on an entry passed to `addMemory`, a service that supports
22
+ * caller-chosen identifiers uses it as the last component of the created
23
+ * memory's resource name instead of generating one.
24
+ */
25
+ id?: string;
26
+ /**
27
+ * Optional custom metadata associated with the memory.
28
+ *
29
+ * A service that also accepts request-level metadata merges this on top of
30
+ * it, so a key declared here wins over the same key on the request.
31
+ */
32
+ customMetadata?: Record<string, unknown>;
18
33
  /**
19
34
  * The author of the memory. Common values are `'user'` and `'model'`, but
20
35
  * this can also be the name of an agent when the content was produced by a
@@ -38,6 +38,15 @@ export declare class VertexAiMemoryBankService implements BaseMemoryService {
38
38
  }): Promise<void>;
39
39
  /**
40
40
  * Adds explicit memory items using Vertex Memory Bank.
41
+ *
42
+ * When a `MemoryEntry.id` is set, it is forwarded as the `memoryId` of the
43
+ * created memory, so the caller picks the last component of the memory
44
+ * resource name instead of letting the service generate one. An explicit
45
+ * `customMetadata['memoryId']` takes precedence over `MemoryEntry.id`.
46
+ *
47
+ * The id is forwarded unvalidated, so an id the API rejects fails the create
48
+ * call. Vertex accepts up to 63 characters from `[a-z0-9-]`, starting with a
49
+ * letter and ending with a letter or number.
41
50
  */
42
51
  addMemory(request: {
43
52
  appName: string;
@@ -16,6 +16,20 @@ export declare function collectFunctionDeclarations(llmRequest: LlmRequest): Fun
16
16
  *
17
17
  * A single-value `enum` is used rather than `const`, because it is semantically
18
18
  * identical and more widely supported across constraint engines.
19
+ *
20
+ * Every branch sets `additionalProperties: false`, and that is load-bearing
21
+ * rather than tidy. Omitted, JSON Schema permits extra keys, so a decoder may
22
+ * emit `,"` after the last required key instead of `}`. The object then never
23
+ * has to close: the model keeps writing until the output runs out, and the
24
+ * reply arrives as truncated JSON. Whether it closes in time is left to
25
+ * sampling, which is why one session can answer a question cleanly and mangle
26
+ * the next. Closing the branch makes `}` the only legal token once `text` is
27
+ * written.
28
+ *
29
+ * It is set on the envelope only, never pushed into a tool's own argument
30
+ * schema. Those belong to the caller; some describe objects that legitimately
31
+ * accept keys they do not list, and forbidding those here would make a valid
32
+ * call impossible to express.
19
33
  */
20
34
  export declare function buildToolChoiceSchema(declarations: FunctionDeclaration[]): Record<string, unknown>;
21
35
  /** Renders tool declarations into instructions the model can act on. */
@@ -66,3 +80,18 @@ export declare function stripAdkIdentityPreamble(systemPrompt: string): string;
66
80
  export declare function isAbortError(error: unknown): boolean;
67
81
  export declare function finalText(text: string): LlmResponse;
68
82
  export declare function errorResponse(error: unknown): LlmResponse;
83
+ /** Shown when a reply is JSON, is broken, and holds no readable answer. */
84
+ export declare const TRUNCATED_REPLY = "The model started an answer and did not finish it. Ask again.";
85
+ /** True when a reply is the JSON envelope rather than plain prose. */
86
+ export declare function looksLikeEnvelope(raw: string): boolean;
87
+ /**
88
+ * Reads the answer out of a truncated `{"kind":"final","text":"…` envelope.
89
+ *
90
+ * A constrained reply that stops early is usually still readable: the answer
91
+ * sits in `text` and only the closing quote and brace are missing. Scanning it
92
+ * out by hand beats `JSON.parse`, which needs the whole document, and beats
93
+ * showing the envelope to the caller.
94
+ *
95
+ * Returns undefined when there is no `text` key to read.
96
+ */
97
+ export declare function salvageFinalText(raw: string): string | undefined;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Content, GenerateContentConfig, GenerateContentResponse, GenerateContentResponseUsageMetadata, Part } from '@google/genai';
7
+ import { LlmResponse } from './llm_response.js';
8
+ /** The most times one generation is resumed after the model pauses it. */
9
+ export declare const MAX_RESUMES = 256;
10
+ /** The contents and config of a request that resumes a paused generation. */
11
+ export interface ResumeRequest {
12
+ contents: Content[];
13
+ config: GenerateContentConfig;
14
+ }
15
+ /**
16
+ * Returns the token that resumes `response`, or undefined if it did not pause
17
+ * or has no token.
18
+ */
19
+ export declare function resumeToken(response: GenerateContentResponse): string | undefined;
20
+ /**
21
+ * One generation, carried across the requests that resume it after the model
22
+ * pauses it.
23
+ */
24
+ export declare class GeminiContinuation {
25
+ private readonly config?;
26
+ private readonly contents;
27
+ private readonly parts;
28
+ private usage?;
29
+ private token?;
30
+ private resumes;
31
+ constructor(contents: Content[], config?: GenerateContentConfig | undefined);
32
+ /**
33
+ * Adds one request's output to the generation: its parts to the content and
34
+ * its usage to the total.
35
+ */
36
+ addOutput(newParts: Part[], newUsage: GenerateContentResponseUsageMetadata | undefined): void;
37
+ /**
38
+ * Returns the request that resumes the generation after a request that
39
+ * ended with `nextToken`. Returns undefined if the request did not pause,
40
+ * returned the previous token again, or the generation was already resumed
41
+ * {@link MAX_RESUMES} times.
42
+ */
43
+ resumeRequest(nextToken: string | undefined): ResumeRequest | undefined;
44
+ /** Returns `response` with the content and usage of all requests, if resumed. */
45
+ complete(response: GenerateContentResponse): LlmResponse;
46
+ /**
47
+ * Returns the final streamed `response`, with usage summed across all
48
+ * requests if resumed.
49
+ */
50
+ withSummedUsage(response: LlmResponse): LlmResponse;
51
+ /** Returns whether a request that ended with `nextToken` is resumed. */
52
+ willResume(nextToken: string): boolean;
53
+ /** Whether the generation took more than one request. */
54
+ private get resumed();
55
+ private content;
56
+ private buildResumeRequest;
57
+ /** Appends `newParts`, joining text as the streaming aggregator does. */
58
+ private appendParts;
59
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Part } from '@google/genai';
7
+ import { Context } from '../agents/context.js';
8
+ import { ReadonlyContext } from '../agents/readonly_context.js';
9
+ import { LlmRequest } from '../models/llm_request.js';
10
+ /**
11
+ * A unique symbol to identify ADK planner classes.
12
+ * Defined once and shared by all BasePlanner instances.
13
+ */
14
+ declare const BASE_PLANNER_SIGNATURE_SYMBOL: unique symbol;
15
+ /**
16
+ * Type guard to check if an object is an instance of BasePlanner.
17
+ * @param obj The object to check.
18
+ * @returns True if the object is an instance of BasePlanner, false otherwise.
19
+ */
20
+ export declare function isBasePlanner(obj: unknown): obj is BasePlanner;
21
+ /**
22
+ * Abstract base class for all planners.
23
+ *
24
+ * The planner allows the agent to generate plans for the queries to guide its
25
+ * action.
26
+ */
27
+ export declare abstract class BasePlanner {
28
+ /** A unique symbol to identify ADK base planner class. */
29
+ readonly [BASE_PLANNER_SIGNATURE_SYMBOL] = true;
30
+ /**
31
+ * Builds the system instruction to be appended to the LLM request for
32
+ * planning.
33
+ *
34
+ * @param readonlyContext The readonly context of the invocation.
35
+ * @param llmRequest The LLM request. Readonly.
36
+ * @returns The planning system instruction, or undefined if no instruction is
37
+ * needed.
38
+ */
39
+ abstract buildPlanningInstruction(readonlyContext: ReadonlyContext, llmRequest: LlmRequest): string | undefined;
40
+ /**
41
+ * Processes the LLM response for planning.
42
+ *
43
+ * @param callbackContext The callback context of the invocation.
44
+ * @param responseParts The LLM response parts. Readonly.
45
+ * @returns The processed response parts, or undefined if no processing is
46
+ * needed.
47
+ */
48
+ abstract processPlanningResponse(callbackContext: Context, responseParts: Part[]): Part[] | undefined;
49
+ }
50
+ export {};
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Part, ThinkingConfig } from '@google/genai';
7
+ import { Context } from '../agents/context.js';
8
+ import { ReadonlyContext } from '../agents/readonly_context.js';
9
+ import { LlmRequest } from '../models/llm_request.js';
10
+ import { BasePlanner } from './base_planner.js';
11
+ /**
12
+ * A unique symbol to identify ADK built-in planner classes.
13
+ * Defined once and shared by all BuiltInPlanner instances.
14
+ */
15
+ declare const BUILT_IN_PLANNER_SIGNATURE_SYMBOL: unique symbol;
16
+ /**
17
+ * Type guard to check if an object is an instance of BuiltInPlanner.
18
+ * @param obj The object to check.
19
+ * @returns True if the object is an instance of BuiltInPlanner, false
20
+ * otherwise.
21
+ */
22
+ export declare function isBuiltInPlanner(obj: unknown): obj is BuiltInPlanner;
23
+ /**
24
+ * The built-in planner that uses model's built-in thinking features.
25
+ */
26
+ export declare class BuiltInPlanner extends BasePlanner {
27
+ /** A unique symbol to identify ADK built-in planner class. */
28
+ readonly [BUILT_IN_PLANNER_SIGNATURE_SYMBOL] = true;
29
+ /**
30
+ * Config for model built-in thinking features. An error will be returned if
31
+ * this field is set for models that don't support thinking.
32
+ */
33
+ thinkingConfig: ThinkingConfig;
34
+ /**
35
+ * Initializes the built-in planner.
36
+ *
37
+ * @param options.thinkingConfig Config for model built-in thinking features.
38
+ * An error will be returned if this field is set for models that don't
39
+ * support thinking.
40
+ */
41
+ constructor(options: {
42
+ thinkingConfig: ThinkingConfig;
43
+ });
44
+ /**
45
+ * Applies the thinking config to the LLM request.
46
+ *
47
+ * @param llmRequest The LLM request to apply the thinking config to.
48
+ */
49
+ applyThinkingConfig(llmRequest: LlmRequest): void;
50
+ buildPlanningInstruction(_readonlyContext: ReadonlyContext, _llmRequest: LlmRequest): string | undefined;
51
+ processPlanningResponse(_callbackContext: Context, _responseParts: Part[]): Part[] | undefined;
52
+ }
53
+ export {};
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Part } from '@google/genai';
7
+ import { Context } from '../agents/context.js';
8
+ import { ReadonlyContext } from '../agents/readonly_context.js';
9
+ import { LlmRequest } from '../models/llm_request.js';
10
+ import { BasePlanner } from './base_planner.js';
11
+ /**
12
+ * Plan-Re-Act planner that constrains the LLM response to generate a plan
13
+ * before any action/observation.
14
+ *
15
+ * Note: this planner does not require the model to support built-in thinking
16
+ * features or setting the thinking config.
17
+ */
18
+ export declare class PlanReActPlanner extends BasePlanner {
19
+ buildPlanningInstruction(_readonlyContext: ReadonlyContext, _llmRequest: LlmRequest): string;
20
+ processPlanningResponse(_callbackContext: Context, responseParts: Part[]): Part[] | undefined;
21
+ }
@@ -121,13 +121,13 @@ export declare abstract class BasePlugin {
121
121
  * This callback helps logging and modifying the user message before the
122
122
  * runner starts the invocation.
123
123
  *
124
- * @param params.invocationContext The context for the entire invocation.
125
- * @param params.userMessage The message content input by user.
124
+ * @param _params.invocationContext The context for the entire invocation.
125
+ * @param _params.userMessage The message content input by user.
126
126
  * @returns An optional `Content` to be returned to the ADK. Returning a
127
127
  * value to replace the user message. Returning `undefined` to proceed
128
128
  * normally.
129
129
  */
130
- onUserMessageCallback(params: {
130
+ onUserMessageCallback(_params: {
131
131
  invocationContext: InvocationContext;
132
132
  userMessage: Content;
133
133
  }): Promise<Content | undefined>;
@@ -137,13 +137,13 @@ export declare abstract class BasePlugin {
137
137
  * This is the first callback to be called in the lifecycle, ideal for global
138
138
  * setup or initialization tasks.
139
139
  *
140
- * @param params.invocationContext The context for the entire invocation, containing
140
+ * @param _params.invocationContext The context for the entire invocation, containing
141
141
  * session information, the root agent, etc.
142
142
  * @returns An optional `Event` to be returned to the ADK. Returning a value
143
143
  * to halt execution of the runner and ends the runner with that event.
144
144
  * Return `undefined` to proceed normally.
145
145
  */
146
- beforeRunCallback(params: {
146
+ beforeRunCallback(_params: {
147
147
  invocationContext: InvocationContext;
148
148
  }): Promise<Content | undefined>;
149
149
  /**
@@ -152,15 +152,15 @@ export declare abstract class BasePlugin {
152
152
  * This is the ideal place to make modification to the event before the event
153
153
  * is handled by the underlying agent app.
154
154
  *
155
- * @param params.invocationContext The context for the entire invocation.
156
- * @param params.event The event raised by the runner.
155
+ * @param _params.invocationContext The context for the entire invocation.
156
+ * @param _params.event The event raised by the runner.
157
157
  * @returns An optional value. A non-`undefined` return may be used by the
158
- * framework to modify or replace the response. Copy `params.event` when
159
- * constructing a replacement to preserve fields that are not being
160
- * modified, such as event actions. Returning `undefined` allows the
158
+ * framework to modify or replace the response. Copy the incoming
159
+ * `event` when constructing a replacement to preserve fields that are not
160
+ * being modified, such as event actions. Returning `undefined` allows the
161
161
  * original response to be used.
162
162
  */
163
- onEventCallback(params: {
163
+ onEventCallback(_params: {
164
164
  invocationContext: InvocationContext;
165
165
  event: Event;
166
166
  }): Promise<Event | undefined>;
@@ -170,10 +170,10 @@ export declare abstract class BasePlugin {
170
170
  * This is the final callback in the ADK lifecycle, suitable for cleanup,
171
171
  * final logging, or reporting tasks.
172
172
  *
173
- * @param params.invocationContext The context for the entire invocation.
173
+ * @param _params.invocationContext The context for the entire invocation.
174
174
  * @returns undefined
175
175
  */
176
- afterRunCallback(params: {
176
+ afterRunCallback(_params: {
177
177
  invocationContext: InvocationContext;
178
178
  }): Promise<void>;
179
179
  /**
@@ -182,13 +182,13 @@ export declare abstract class BasePlugin {
182
182
  * This callback can be used for logging, setup, or to short-circuit the
183
183
  * agent's execution by returning a value.
184
184
  *
185
- * @param params.agent The agent that is about to run.
186
- * @param params.callbackContext The context for the agent invocation.
185
+ * @param _params.agent The agent that is about to run.
186
+ * @param _params.callbackContext The context for the agent invocation.
187
187
  * @returns An optional `Content` object. If a value is returned, it will
188
188
  * bypass the agent's callbacks and its execution, and return this value
189
189
  * directly. Returning `undefined` allows the agent to proceed normally.
190
190
  */
191
- beforeAgentCallback(params: {
191
+ beforeAgentCallback(_params: {
192
192
  agent: BaseAgent;
193
193
  callbackContext: Context;
194
194
  }): Promise<Content | undefined>;
@@ -198,13 +198,13 @@ export declare abstract class BasePlugin {
198
198
  * This callback can be used to inspect, log, or modify the agent's final
199
199
  * result before it is returned.
200
200
  *
201
- * @param params.agent The agent that has just run.
202
- * @param params.callbackContext The context for the agent invocation.
201
+ * @param _params.agent The agent that has just run.
202
+ * @param _params.callbackContext The context for the agent invocation.
203
203
  * @returns An optional `Content` object. If a value is returned, it will
204
204
  * replace the agent's original result. Returning `undefined` uses the
205
205
  * original, unmodified result.
206
206
  */
207
- afterAgentCallback(params: {
207
+ afterAgentCallback(_params: {
208
208
  agent: BaseAgent;
209
209
  callbackContext: Context;
210
210
  }): Promise<Content | undefined>;
@@ -248,13 +248,13 @@ export declare abstract class BasePlugin {
248
248
  * object. It can also be used to implement caching by returning a cached
249
249
  * `LlmResponse`, which would skip the actual model call.
250
250
  *
251
- * @param params.callbackContext The context for the current agent call.
252
- * @param params.llmRequest The prepared request object to be sent to the model.
251
+ * @param _params.callbackContext The context for the current agent call.
252
+ * @param _params.llmRequest The prepared request object to be sent to the model.
253
253
  * @returns An optional value. The interpretation of a non-`undefined`
254
254
  * trigger an early exit and returns the response immediately. Returning
255
255
  * `undefined` allows the LLM request to proceed normally.
256
256
  */
257
- beforeModelCallback(params: {
257
+ beforeModelCallback(_params: {
258
258
  callbackContext: Context;
259
259
  llmRequest: LlmRequest;
260
260
  }): Promise<LlmResponse | undefined>;
@@ -264,13 +264,13 @@ export declare abstract class BasePlugin {
264
264
  * This is the ideal place to log model responses, collect metrics on token
265
265
  * usage, or perform post-processing on the raw `LlmResponse`.
266
266
  *
267
- * @param params.callbackContext The context for the current agent call.
268
- * @param params.llmResponse The response object received from the model.
267
+ * @param _params.callbackContext The context for the current agent call.
268
+ * @param _params.llmResponse The response object received from the model.
269
269
  * @returns An optional value. A non-`undefined` return may be used by the
270
270
  * framework to modify or replace the response. Returning `undefined`
271
271
  * allows the original response to be used.
272
272
  */
273
- afterModelCallback(params: {
273
+ afterModelCallback(_params: {
274
274
  callbackContext: Context;
275
275
  llmResponse: LlmResponse;
276
276
  }): Promise<LlmResponse | undefined>;
@@ -280,15 +280,15 @@ export declare abstract class BasePlugin {
280
280
  * This callback provides an opportunity to handle model errors gracefully,
281
281
  * potentially providing alternative responses or recovery mechanisms.
282
282
  *
283
- * @param params.callbackContext The context for the current agent call.
284
- * @param params.llmRequest The request that was sent to the model when the error
283
+ * @param _params.callbackContext The context for the current agent call.
284
+ * @param _params.llmRequest The request that was sent to the model when the error
285
285
  * occurred.
286
- * @param params.error The exception that was raised during model execution.
286
+ * @param _params.error The exception that was raised during model execution.
287
287
  * @returns An optional LlmResponse. If an LlmResponse is returned, it will be
288
288
  * used instead of propagating the error. Returning `undefined` allows
289
289
  * the original error to be raised.
290
290
  */
291
- onModelErrorCallback(params: {
291
+ onModelErrorCallback(_params: {
292
292
  callbackContext: Context;
293
293
  llmRequest: LlmRequest;
294
294
  error: Error;
@@ -299,13 +299,13 @@ export declare abstract class BasePlugin {
299
299
  * This callback provides an opportunity to inspect, log, or modify the
300
300
  * available tools before they are selected.
301
301
  *
302
- * @param params.callbackContext The context for the current agent call.
303
- * @param params.tools The available tools.
302
+ * @param _params.callbackContext The context for the current agent call.
303
+ * @param _params.tools The available tools.
304
304
  * @returns An optional value. A non-`undefined` return may be used by the
305
305
  * framework to modify or replace the available tools. Returning
306
306
  * `undefined` allows the original tools to be used.
307
307
  */
308
- beforeToolSelection(params: {
308
+ beforeToolSelection(_params: {
309
309
  callbackContext: Context;
310
310
  tools: Readonly<Record<string, BaseTool>>;
311
311
  }): Promise<Readonly<Record<string, BaseTool>> | undefined>;
@@ -315,10 +315,10 @@ export declare abstract class BasePlugin {
315
315
  * This callback provides an opportunity to inspect or modify the context
316
316
  * before it is compacted.
317
317
  *
318
- * @param params.invocationContext The context for the entire invocation.
319
- * @param params.trigger The trigger for the context compaction.
318
+ * @param _params.invocationContext The context for the entire invocation.
319
+ * @param _params.trigger The trigger for the context compaction.
320
320
  */
321
- beforeContextCompaction(params: {
321
+ beforeContextCompaction(_params: {
322
322
  invocationContext: InvocationContext;
323
323
  trigger: ContextCompactionTrigger;
324
324
  }): Promise<void>;
@@ -328,10 +328,10 @@ export declare abstract class BasePlugin {
328
328
  * This callback provides an opportunity to inspect the context
329
329
  * after it has been compacted.
330
330
  *
331
- * @param params.invocationContext The context for the entire invocation.
332
- * @param params.trigger The trigger for the context compaction.
331
+ * @param _params.invocationContext The context for the entire invocation.
332
+ * @param _params.trigger The trigger for the context compaction.
333
333
  */
334
- afterContextCompaction(params: {
334
+ afterContextCompaction(_params: {
335
335
  invocationContext: InvocationContext;
336
336
  trigger: ContextCompactionTrigger;
337
337
  }): Promise<void>;
@@ -341,15 +341,15 @@ export declare abstract class BasePlugin {
341
341
  * This callback is useful for logging tool usage, input validation, or
342
342
  * modifying the arguments before they are passed to the tool.
343
343
  *
344
- * @param params.tool The tool instance that is about to be executed.
345
- * @param params.toolArgs The dictionary of arguments to be used for invoking the
344
+ * @param _params.tool The tool instance that is about to be executed.
345
+ * @param _params.toolArgs The dictionary of arguments to be used for invoking the
346
346
  * tool.
347
- * @param params.toolContext The context specific to the tool execution.
347
+ * @param _params.toolContext The context specific to the tool execution.
348
348
  * @returns An optional dictionary. If a dictionary is returned, it will stop
349
349
  * the tool execution and return this response immediately. Returning
350
350
  * `undefined` uses the original, unmodified arguments.
351
351
  */
352
- beforeToolCallback(params: {
352
+ beforeToolCallback(_params: {
353
353
  tool: BaseTool;
354
354
  toolArgs: Record<string, unknown>;
355
355
  toolContext: Context;
@@ -360,16 +360,16 @@ export declare abstract class BasePlugin {
360
360
  * This callback allows for inspecting, logging, or modifying the result
361
361
  * returned by a tool.
362
362
  *
363
- * @param params.tool The tool instance that has just been executed.
364
- * @param params.toolArgs The original arguments that were passed to the tool.
365
- * @param params.toolContext The context specific to the tool execution.
366
- * @param params.result The dictionary returned by the tool invocation.
363
+ * @param _params.tool The tool instance that has just been executed.
364
+ * @param _params.toolArgs The original arguments that were passed to the tool.
365
+ * @param _params.toolContext The context specific to the tool execution.
366
+ * @param _params.result The dictionary returned by the tool invocation.
367
367
  * @returns An optional dictionary. If a dictionary is returned, it will
368
368
  * **replace** the original result from the tool. This allows for
369
369
  * post-processing or altering tool outputs. Returning `undefined` uses
370
370
  * the original, unmodified result.
371
371
  */
372
- afterToolCallback(params: {
372
+ afterToolCallback(_params: {
373
373
  tool: BaseTool;
374
374
  toolArgs: Record<string, unknown>;
375
375
  toolContext: Context;
@@ -391,15 +391,15 @@ export declare abstract class BasePlugin {
391
391
  * This callback provides an opportunity to handle tool errors gracefully,
392
392
  * potentially providing alternative responses or recovery mechanisms.
393
393
  *
394
- * @param params.tool The tool instance that encountered an error.
395
- * @param params.toolArgs The arguments that were passed to the tool.
396
- * @param params.toolContext The context specific to the tool execution.
397
- * @param params.error The exception that was raised during tool execution.
394
+ * @param _params.tool The tool instance that encountered an error.
395
+ * @param _params.toolArgs The arguments that were passed to the tool.
396
+ * @param _params.toolContext The context specific to the tool execution.
397
+ * @param _params.error The exception that was raised during tool execution.
398
398
  * @returns An optional dictionary. If a dictionary is returned, it will be
399
399
  * used as the tool response instead of propagating the error. Returning
400
400
  * `undefined` allows the original error to be raised.
401
401
  */
402
- onToolErrorCallback(params: {
402
+ onToolErrorCallback(_params: {
403
403
  tool: BaseTool;
404
404
  toolArgs: Record<string, unknown>;
405
405
  toolContext: Context;