@google/adk 1.4.0 → 1.5.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 (122) hide show
  1. package/dist/cjs/a2a/agent_to_a2a.js +18 -2
  2. package/dist/cjs/a2a/event_converter_utils.js +8 -4
  3. package/dist/cjs/a2a/metadata_converter_utils.js +1 -1
  4. package/dist/cjs/agents/base_agent.js +39 -0
  5. package/dist/cjs/agents/functions.js +6 -21
  6. package/dist/cjs/agents/llm_agent.js +2 -1
  7. package/dist/cjs/agents/loop_agent.js +15 -3
  8. package/dist/cjs/agents/processors/content_processor_utils.js +2 -1
  9. package/dist/cjs/agents/routed_agent.js +31 -0
  10. package/dist/cjs/agents/run_config.js +3 -2
  11. package/dist/cjs/artifacts/in_memory_artifact_service.js +7 -0
  12. package/dist/cjs/common.js +29 -0
  13. package/dist/cjs/context/anchored_context_compactor.js +127 -0
  14. package/dist/cjs/context/compaction_utils.js +52 -0
  15. package/dist/cjs/context/token_based_context_compactor.js +11 -24
  16. package/dist/cjs/events/compacted_event.js +9 -3
  17. package/dist/cjs/events/event.js +28 -0
  18. package/dist/cjs/index.js +4 -0
  19. package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
  20. package/dist/cjs/plugins/global_instruction_plugin.js +97 -0
  21. package/dist/cjs/runner/runner.js +51 -12
  22. package/dist/cjs/tools/enterprise_web_search_tool.js +81 -0
  23. package/dist/cjs/tools/example_tool.js +68 -0
  24. package/dist/cjs/tools/load_web_page.js +250 -0
  25. package/dist/cjs/tools/mcp/load_mcp_resource_tool.js +140 -0
  26. package/dist/cjs/tools/mcp/mcp_toolset.js +63 -0
  27. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
  28. package/dist/cjs/tools/skill/run_skill_inline_script_tool.js +54 -4
  29. package/dist/cjs/tools/skill/skill_toolset.js +4 -2
  30. package/dist/cjs/utils/branch_trie.js +41 -0
  31. package/dist/cjs/utils/streaming_utils.js +5 -5
  32. package/dist/cjs/version.js +1 -1
  33. package/dist/esm/a2a/agent_to_a2a.js +18 -2
  34. package/dist/esm/a2a/event_converter_utils.js +8 -4
  35. package/dist/esm/a2a/metadata_converter_utils.js +1 -1
  36. package/dist/esm/agents/base_agent.js +39 -0
  37. package/dist/esm/agents/functions.js +7 -17
  38. package/dist/esm/agents/llm_agent.js +4 -3
  39. package/dist/esm/agents/loop_agent.js +15 -3
  40. package/dist/esm/agents/processors/content_processor_utils.js +2 -1
  41. package/dist/esm/agents/routed_agent.js +31 -0
  42. package/dist/esm/agents/run_config.js +3 -2
  43. package/dist/esm/artifacts/in_memory_artifact_service.js +7 -0
  44. package/dist/esm/common.js +25 -1
  45. package/dist/esm/context/anchored_context_compactor.js +99 -0
  46. package/dist/esm/context/compaction_utils.js +27 -0
  47. package/dist/esm/context/token_based_context_compactor.js +11 -24
  48. package/dist/esm/events/compacted_event.js +7 -2
  49. package/dist/esm/events/event.js +24 -0
  50. package/dist/esm/index.js +6 -1
  51. package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
  52. package/dist/esm/plugins/global_instruction_plugin.js +69 -0
  53. package/dist/esm/runner/runner.js +51 -12
  54. package/dist/esm/tools/enterprise_web_search_tool.js +55 -0
  55. package/dist/esm/tools/example_tool.js +42 -0
  56. package/dist/esm/tools/load_web_page.js +221 -0
  57. package/dist/esm/tools/mcp/load_mcp_resource_tool.js +114 -0
  58. package/dist/esm/tools/mcp/mcp_toolset.js +63 -0
  59. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
  60. package/dist/esm/tools/skill/run_skill_inline_script_tool.js +53 -4
  61. package/dist/esm/tools/skill/skill_toolset.js +4 -2
  62. package/dist/esm/utils/branch_trie.js +13 -0
  63. package/dist/esm/utils/streaming_utils.js +1 -1
  64. package/dist/esm/version.js +1 -1
  65. package/dist/types/a2a/a2a_remote_agent.d.ts +5 -1
  66. package/dist/types/a2a/agent_to_a2a.d.ts +38 -0
  67. package/dist/types/agents/base_agent.d.ts +29 -1
  68. package/dist/types/agents/functions.d.ts +1 -9
  69. package/dist/types/agents/llm_agent.d.ts +5 -1
  70. package/dist/types/agents/loop_agent.d.ts +2 -2
  71. package/dist/types/agents/routed_agent.d.ts +24 -1
  72. package/dist/types/agents/run_config.d.ts +1 -1
  73. package/dist/types/common.d.ts +9 -2
  74. package/dist/types/context/anchored_context_compactor.d.ts +35 -0
  75. package/dist/types/context/compaction_utils.d.ts +15 -0
  76. package/dist/types/events/compacted_event.d.ts +10 -0
  77. package/dist/types/events/event.d.ts +13 -0
  78. package/dist/types/index.d.ts +3 -2
  79. package/dist/types/plugins/global_instruction_plugin.d.ts +38 -0
  80. package/dist/types/runner/runner.d.ts +1 -1
  81. package/dist/types/tools/enterprise_web_search_tool.d.ts +26 -0
  82. package/dist/types/tools/example_tool.d.ts +21 -0
  83. package/dist/types/tools/load_web_page.d.ts +33 -0
  84. package/dist/types/tools/mcp/load_mcp_resource_tool.d.ts +26 -0
  85. package/dist/types/tools/mcp/mcp_toolset.d.ts +27 -0
  86. package/dist/types/tools/skill/run_skill_inline_script_tool.d.ts +25 -0
  87. package/dist/types/tools/skill/skill_toolset.d.ts +9 -0
  88. package/dist/types/utils/branch_trie.d.ts +14 -0
  89. package/dist/types/version.d.ts +1 -1
  90. package/dist/web/a2a/agent_to_a2a.js +18 -2
  91. package/dist/web/a2a/event_converter_utils.js +8 -4
  92. package/dist/web/a2a/metadata_converter_utils.js +1 -1
  93. package/dist/web/agents/base_agent.js +39 -0
  94. package/dist/web/agents/functions.js +7 -17
  95. package/dist/web/agents/llm_agent.js +4 -3
  96. package/dist/web/agents/loop_agent.js +27 -3
  97. package/dist/web/agents/processors/content_processor_utils.js +2 -1
  98. package/dist/web/agents/routed_agent.js +31 -0
  99. package/dist/web/agents/run_config.js +8 -3
  100. package/dist/web/artifacts/in_memory_artifact_service.js +7 -0
  101. package/dist/web/common.js +25 -1
  102. package/dist/web/context/anchored_context_compactor.js +117 -0
  103. package/dist/web/context/compaction_utils.js +27 -0
  104. package/dist/web/context/token_based_context_compactor.js +11 -24
  105. package/dist/web/events/compacted_event.js +7 -2
  106. package/dist/web/events/event.js +24 -0
  107. package/dist/web/index.js +6 -1
  108. package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
  109. package/dist/web/plugins/global_instruction_plugin.js +67 -0
  110. package/dist/web/runner/runner.js +48 -11
  111. package/dist/web/tools/enterprise_web_search_tool.js +55 -0
  112. package/dist/web/tools/example_tool.js +42 -0
  113. package/dist/web/tools/load_web_page.js +221 -0
  114. package/dist/web/tools/mcp/load_mcp_resource_tool.js +107 -0
  115. package/dist/web/tools/mcp/mcp_toolset.js +63 -0
  116. package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
  117. package/dist/web/tools/skill/run_skill_inline_script_tool.js +51 -4
  118. package/dist/web/tools/skill/skill_toolset.js +4 -2
  119. package/dist/web/utils/branch_trie.js +13 -0
  120. package/dist/web/utils/streaming_utils.js +1 -1
  121. package/dist/web/version.js +1 -1
  122. package/package.json +1 -1
@@ -0,0 +1,35 @@
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
+ import { BaseSummarizer } from './summarizers/base_summarizer.js';
9
+ export interface AnchoredContextCompactorOptions {
10
+ /** The maximum number of tokens to retain in the session history before compaction. */
11
+ tokenThreshold: number;
12
+ /**
13
+ * The minimum number of raw events to keep at the end of the session.
14
+ * Compaction will not affect these tail events (unless needed for tool splits).
15
+ */
16
+ eventRetentionSize: number;
17
+ /** The summarizer used to create the compacted event content. */
18
+ summarizer: BaseSummarizer;
19
+ }
20
+ /**
21
+ * A context compactor that maintains a single persistent 'Scratchpad' or
22
+ * 'State Tracker' event at the top of the context history.
23
+ *
24
+ * When compaction is triggered, it merges new raw events into the existing
25
+ * Scratchpad event and discards them from the active history view.
26
+ */
27
+ export declare class AnchoredContextCompactor implements BaseContextCompactor {
28
+ private readonly tokenThreshold;
29
+ private readonly eventRetentionSize;
30
+ private readonly summarizer;
31
+ constructor(options: AnchoredContextCompactorOptions);
32
+ private getActiveEvents;
33
+ shouldCompact(invocationContext: InvocationContext): boolean | Promise<boolean>;
34
+ compact(invocationContext: InvocationContext): Promise<void>;
35
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Event } from '../events/event.js';
7
+ /**
8
+ * Determines the baseline index to retain from active raw events,
9
+ * ensuring we don't split between a function call and its response.
10
+ *
11
+ * @param rawEvents The active raw events to consider for compaction.
12
+ * @param eventRetentionSize The minimum number of raw events to keep at the end of the session.
13
+ * @returns The index in `rawEvents` at which to split. Events before this index will be compacted.
14
+ */
15
+ export declare function calculateRetainStartIndex(rawEvents: Event[], eventRetentionSize: number): number;
@@ -25,9 +25,19 @@ export interface CompactedEvent extends Event {
25
25
  * The summarized content of the compacted events.
26
26
  */
27
27
  compactedContent: string;
28
+ /**
29
+ * Identifies this compacted event as the persistent context scratchpad.
30
+ */
31
+ isScratchpad?: boolean;
28
32
  }
29
33
  /**
30
34
  * Type guard to check if an event is a CompactedEvent.
31
35
  */
32
36
  export declare function isCompactedEvent(event: Event): event is CompactedEvent;
37
+ /**
38
+ * Type guard to check if an event is a scratchpad CompactedEvent.
39
+ */
40
+ export declare function isScratchpadEvent(event: Event): event is CompactedEvent & {
41
+ isScratchpad: true;
42
+ };
33
43
  export declare function createCompactedEvent(params?: Partial<CompactedEvent>): CompactedEvent;
@@ -67,6 +67,15 @@ export declare function isFinalResponse(event: Event): boolean;
67
67
  * Returns the function calls in the event.
68
68
  */
69
69
  export declare function getFunctionCalls(event: Event): FunctionCall[];
70
+ export declare const AF_FUNCTION_CALL_ID_PREFIX = "adk-";
71
+ export declare function generateClientFunctionCallId(): string;
72
+ /**
73
+ * Populates client-side function call IDs.
74
+ *
75
+ * It iterates through all function calls in the event and assigns a
76
+ * unique client-side ID to each one that doesn't already have an ID.
77
+ */
78
+ export declare function populateClientFunctionCallId(modelResponseEvent: Event): void;
70
79
  /**
71
80
  * Returns the function responses in the event.
72
81
  */
@@ -82,6 +91,10 @@ export declare function hasTrailingCodeExecutionResult(event: Event): boolean;
82
91
  * @returns A single string with the combined text.
83
92
  */
84
93
  export declare function stringifyContent(event: Event): string;
94
+ /**
95
+ * Estimates the number of tokens in the event based on usage metadata or characters.
96
+ */
97
+ export declare function getEventTokens(event: Event): number;
85
98
  /**
86
99
  * Returns whether the event contains any thought parts.
87
100
  */
@@ -9,7 +9,7 @@ export { getA2AAgentCard } from './a2a/agent_card.js';
9
9
  export { A2AAgentExecutor } from './a2a/agent_executor.js';
10
10
  export type { AfterEventCallback, AfterExecuteCallback, AgentExecutorConfig, BeforeExecuteCallback, RunnerOrRunnerConfig, } from './a2a/agent_executor.js';
11
11
  export { toA2a } from './a2a/agent_to_a2a.js';
12
- export type { ToA2aOptions } from './a2a/agent_to_a2a.js';
12
+ export type { A2aUserBuilder, ToA2aOptions } from './a2a/agent_to_a2a.js';
13
13
  export type { ExecutorContext } from './a2a/executor_context.js';
14
14
  export { InvocationContext } from './agents/invocation_context.js';
15
15
  export { FileArtifactService } from './artifacts/file_artifact_service.js';
@@ -24,11 +24,12 @@ export { getSessionServiceFromUri } from './sessions/registry.js';
24
24
  export { VertexAiSessionService } from './sessions/vertex_ai_session_service.js';
25
25
  export type { VertexAiSessionServiceOptions } from './sessions/vertex_ai_session_service.js';
26
26
  export { loadAllSkillsInDir, loadSkillFromDir, validateSkillDir, } from './skills/loader.js';
27
- export { RunSkillInlineScriptTool } from './tools/skill/run_skill_inline_script_tool.js';
27
+ export { RunSkillInlineScriptErrorCode, RunSkillInlineScriptTool, } from './tools/skill/run_skill_inline_script_tool.js';
28
28
  export { RunSkillScriptTool } from './tools/skill/run_skill_script_tool.js';
29
29
  export * from './integrations/agent_registry/agent_registry.js';
30
30
  export * from './telemetry/google_cloud.js';
31
31
  export * from './telemetry/setup.js';
32
+ export * from './tools/mcp/load_mcp_resource_tool.js';
32
33
  export * from './tools/mcp/mcp_session_manager.js';
33
34
  export * from './tools/mcp/mcp_tool.js';
34
35
  export * from './tools/mcp/mcp_toolset.js';
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Context } from '../agents/context.js';
7
+ import { InstructionProvider } from '../agents/llm_agent.js';
8
+ import { LlmRequest } from '../models/llm_request.js';
9
+ import { LlmResponse } from '../models/llm_response.js';
10
+ import { BasePlugin } from './base_plugin.js';
11
+ /**
12
+ * Plugin that provides global instructions functionality at the App level.
13
+ *
14
+ * This plugin replaces the deprecated globalInstruction field on LlmAgent.
15
+ * Global instructions are applied to all agents in the application, providing
16
+ * a consistent way to set application-wide instructions, identity, or
17
+ * personality.
18
+ *
19
+ * The plugin operates through the beforeModelCallback, allowing it to modify
20
+ * LLM requests before they are sent to the model.
21
+ */
22
+ export declare class GlobalInstructionPlugin extends BasePlugin {
23
+ private readonly globalInstruction?;
24
+ /**
25
+ * Initializes the GlobalInstructionPlugin.
26
+ *
27
+ * @param globalInstruction The instruction to apply globally. Can be a string
28
+ * or an InstructionProvider function that takes ReadonlyContext and
29
+ * returns a string (sync or async).
30
+ * @param name The name of the plugin (defaults to 'global_instruction').
31
+ */
32
+ constructor(globalInstruction?: string | InstructionProvider, name?: string);
33
+ beforeModelCallback(params: {
34
+ callbackContext: Context;
35
+ llmRequest: LlmRequest;
36
+ }): Promise<LlmResponse | undefined>;
37
+ private resolveGlobalInstruction;
38
+ }
@@ -147,7 +147,7 @@ export declare class Runner {
147
147
  }): AsyncGenerator<Event, void, undefined>;
148
148
  /**
149
149
  * Saves artifacts from the message parts and replaces the inline data with
150
- * a file name placeholder.
150
+ * a file name placeholder and optional file reference.
151
151
  *
152
152
  * @param invocationId The current invocation ID.
153
153
  * @param userId The user ID of the session.
@@ -0,0 +1,26 @@
1
+ import { LlmRequest } from '../models/llm_request.js';
2
+ import { BaseTool, ToolProcessLlmRequest } from './base_tool.js';
3
+ /**
4
+ * Appends the Enterprise Web Search built-in tool to the LLM request when the
5
+ * target model supports it.
6
+ *
7
+ * NOTE: This is NOT Vertex AI Search (formerly "Enterprise Search"). See
8
+ * https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/web-grounding-enterprise
9
+ */
10
+ export declare function applyEnterpriseWebSearch(llmRequest: LlmRequest): void;
11
+ /**
12
+ * A Gemini 2+ built-in tool that grounds responses on public web data via
13
+ * Vertex AI Search with Enterprise (Sec4) compliance.
14
+ *
15
+ * This tool operates internally within the model and does not require or
16
+ * perform local code execution.
17
+ */
18
+ export declare class EnterpriseWebSearchTool extends BaseTool {
19
+ constructor();
20
+ runAsync(): Promise<unknown>;
21
+ processLlmRequest({ llmRequest, }: ToolProcessLlmRequest): Promise<void>;
22
+ }
23
+ /**
24
+ * A global instance of {@link EnterpriseWebSearchTool}.
25
+ */
26
+ export declare const ENTERPRISE_WEB_SEARCH: EnterpriseWebSearchTool;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { BaseExampleProvider } from '../examples/base_example_provider.js';
7
+ import { Example } from '../examples/example.js';
8
+ import { BaseTool, RunAsyncToolRequest, ToolProcessLlmRequest } from './base_tool.js';
9
+ /**
10
+ * A tool that adds (few-shot) examples to the LLM request.
11
+ *
12
+ * This tool is executed for each LLM request and is never called by the model;
13
+ * it only mutates the outgoing request by appending few-shot instructions built
14
+ * from the latest user query.
15
+ */
16
+ export declare class ExampleTool extends BaseTool {
17
+ readonly examples: Example[] | BaseExampleProvider;
18
+ constructor(examples: Example[] | BaseExampleProvider);
19
+ runAsync(_request: RunAsyncToolRequest): Promise<unknown>;
20
+ processLlmRequest({ toolContext, llmRequest, }: ToolProcessLlmRequest): Promise<void>;
21
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { z } from 'zod';
7
+ import { FunctionTool } from './function_tool.js';
8
+ /** Options for {@link loadWebPage}. */
9
+ export interface LoadWebPageOptions {
10
+ /** Request timeout in milliseconds. Defaults to 30_000 (30s). */
11
+ timeoutMs?: number;
12
+ }
13
+ /**
14
+ * Fetches the content at `url` and returns its extracted, readable text.
15
+ *
16
+ * Hardened against SSRF: only `http`/`https` URLs are fetched, the host is
17
+ * resolved and rejected up front if it is `localhost`-style or resolves to a
18
+ * private / loopback / link-local / shared / reserved / multicast address, and
19
+ * redirects are never followed. Never throws for expected failures (bad scheme,
20
+ * blocked host, non-200, timeout, network error); returns
21
+ * `Failed to fetch url: <url>` instead.
22
+ *
23
+ * Known limitation: global `fetch` performs its own DNS resolution at connect
24
+ * time, so a residual time-of-check/time-of-use (DNS-rebinding) window exists
25
+ * between this pre-flight lookup and fetch's own lookup. Full connection
26
+ * IP-pinning (e.g. an `undici` Agent with a custom `lookup`) is a possible
27
+ * future hardening.
28
+ */
29
+ export declare function loadWebPage(url: string, options?: LoadWebPageOptions): Promise<string>;
30
+ /** A global {@link FunctionTool} exposing {@link loadWebPage} to the model. */
31
+ export declare const LOAD_WEB_PAGE: FunctionTool<z.ZodObject<{
32
+ url: z.ZodString;
33
+ }, z.core.$strip>>;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { FunctionDeclaration } from '@google/genai';
7
+ import { BaseTool, RunAsyncToolRequest, ToolProcessLlmRequest } from '../base_tool.js';
8
+ import { MCPToolset } from './mcp_toolset.js';
9
+ /**
10
+ * A tool that loads MCP server resources and adds them to the session.
11
+ *
12
+ * This mirrors the in-repo `LoadArtifactsTool` idiom: the model calls
13
+ * `load_mcp_resource` with the names of the resources it wants, and on the next
14
+ * turn {@link processLlmRequest} reads those resources over the MCP session and
15
+ * appends their contents (text and base64-encoded binary) to the request
16
+ * context.
17
+ */
18
+ export declare class LoadMcpResourceTool extends BaseTool {
19
+ private readonly mcpToolset;
20
+ constructor(mcpToolset: MCPToolset);
21
+ _getDeclaration(): FunctionDeclaration;
22
+ runAsync({ args }: RunAsyncToolRequest): Promise<unknown>;
23
+ processLlmRequest(request: ToolProcessLlmRequest): Promise<void>;
24
+ private appendResourcesToLlmRequest;
25
+ private mcpContentToPart;
26
+ }
@@ -3,6 +3,7 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ import { BlobResourceContents, Resource, TextResourceContents } from '@modelcontextprotocol/sdk/types.js';
6
7
  import { ReadonlyContext } from '../../agents/readonly_context.js';
7
8
  import { BaseTool } from '../base_tool.js';
8
9
  import { BaseToolset, ToolPredicate } from '../base_toolset.js';
@@ -40,5 +41,31 @@ export declare class MCPToolset extends BaseToolset {
40
41
  private readonly mcpSessionManager;
41
42
  constructor(connectionParams: MCPConnectionParams, toolFilter?: ToolPredicate | string[], prefix?: string);
42
43
  getTools(context?: ReadonlyContext): Promise<BaseTool[]>;
44
+ /**
45
+ * Lists the names of the resources advertised by the MCP server.
46
+ *
47
+ * @return The resource names available on the server.
48
+ */
49
+ listResources(): Promise<string[]>;
50
+ /**
51
+ * Returns metadata for the resource whose name matches `name`.
52
+ *
53
+ * @param name The advertised name of the resource.
54
+ * @return The matching MCP `Resource`.
55
+ * @throws If no resource with the given name is advertised by the server.
56
+ */
57
+ getResourceInfo(name: string): Promise<Resource>;
58
+ /**
59
+ * Reads the contents of the named resource from the MCP server.
60
+ *
61
+ * The resource name is resolved to a URI via {@link getResourceInfo} before
62
+ * reading. Binary contents are returned base64-encoded, exactly as provided
63
+ * by the server (never decoded and re-encoded).
64
+ *
65
+ * @param name The advertised name of the resource to read.
66
+ * @return The resource contents (text and/or base64-encoded binary).
67
+ * @throws If the resource is unknown or has no URI.
68
+ */
69
+ readResource(name: string): Promise<Array<TextResourceContents | BlobResourceContents>>;
43
70
  close(): Promise<void>;
44
71
  }
@@ -6,9 +6,34 @@
6
6
  import { FunctionDeclaration } from '@google/genai';
7
7
  import { BaseTool, RunAsyncToolRequest } from '../base_tool.js';
8
8
  import { SkillToolset } from './skill_toolset.js';
9
+ /**
10
+ * Error codes returned by {@link RunSkillInlineScriptTool} when a call cannot
11
+ * be completed. The string values are part of the tool's response contract and
12
+ * must remain stable.
13
+ */
14
+ export declare enum RunSkillInlineScriptErrorCode {
15
+ MISSING_SCRIPT_CONTENT = "MISSING_SCRIPT_CONTENT",
16
+ MISSING_LANGUAGE = "MISSING_LANGUAGE",
17
+ NO_CODE_EXECUTOR = "NO_CODE_EXECUTOR",
18
+ EXECUTION_ERROR = "EXECUTION_ERROR",
19
+ CONFIRMATION_REJECTED = "CONFIRMATION_REJECTED"
20
+ }
9
21
  export declare class RunSkillInlineScriptTool extends BaseTool {
10
22
  private toolset;
11
23
  constructor(toolset: SkillToolset);
12
24
  _getDeclaration(): FunctionDeclaration;
13
25
  runAsync({ args, toolContext, }: RunAsyncToolRequest): Promise<unknown>;
26
+ /**
27
+ * Enforces a human-in-the-loop confirmation gate before executing an inline
28
+ * script, using the repo's standard tool-confirmation mechanism.
29
+ *
30
+ * - When no confirmation has been provided yet, a confirmation is requested
31
+ * (surfacing the language and script that would run) and an intermediate
32
+ * result is returned so the tool call pauses until the client responds.
33
+ * - When a confirmation exists but was not confirmed, a rejection error is
34
+ * returned and execution is refused.
35
+ * - When the confirmation is confirmed, `undefined` is returned to allow the
36
+ * caller to proceed with execution.
37
+ */
38
+ private enforceConfirmation;
14
39
  }
@@ -23,6 +23,15 @@ export declare class SkillToolset extends BaseToolset {
23
23
  codeExecutor?: BaseCodeExecutor;
24
24
  additionalTools?: Array<BaseTool | BaseToolset>;
25
25
  registry?: SkillRegistry;
26
+ /**
27
+ * Whether to expose the `run_skill_inline_script` tool, which executes
28
+ * model-provided script content in the configured code executor. This is
29
+ * disabled by default because arbitrary inline-script execution is a
30
+ * sensitive capability; opt in explicitly by setting this to `true`.
31
+ * Execution additionally remains gated behind a human-in-the-loop
32
+ * confirmation.
33
+ */
34
+ allowInlineScripts?: boolean;
26
35
  });
27
36
  getTools(context?: ReadonlyContext): Promise<BaseTool[]>;
28
37
  close(): Promise<void>;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Checks whether targetBranch is equal to or an ancestor of currentBranch
8
+ * by verifying segment-by-segment matching without substring false positives.
9
+ *
10
+ * @param currentBranch The branch being evaluated.
11
+ * @param targetBranch The candidate prefix or ancestor branch.
12
+ * @returns true if targetBranch equals currentBranch or is an ancestor of currentBranch.
13
+ */
14
+ export declare function isSegmentPrefix(currentBranch: string, targetBranch: string): boolean;
@@ -3,4 +3,4 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- export declare const version = "1.4.0";
6
+ export declare const version = "1.5.0";
@@ -16,10 +16,26 @@ import {
16
16
  import express from "express";
17
17
  import { StreamingMode } from "../agents/run_config.js";
18
18
  import { InMemorySessionService } from "../sessions/in_memory_session_service.js";
19
+ import { logger } from "../utils/logger.js";
19
20
  import { getA2AAgentCard, resolveAgentCard } from "./agent_card.js";
20
21
  import { A2AAgentExecutor } from "./agent_executor.js";
22
+ function resolveA2aUserBuilder(options) {
23
+ if (options.authentication) {
24
+ return options.authentication;
25
+ }
26
+ if (options.allowUnauthenticated === true) {
27
+ logger.warn(
28
+ "SECURITY WARNING: Mounting the A2A server WITHOUT authentication because `allowUnauthenticated: true` was set. The agent and all of its tools are exposed to any network-reachable caller, which can invoke them with arbitrary input and read the output. Do NOT use this outside of local, trusted development."
29
+ );
30
+ return UserBuilder.noAuthentication;
31
+ }
32
+ throw new Error(
33
+ "toA2a: refusing to mount the A2A server without authentication. The A2A surface lets any network-reachable caller invoke this agent and its tools with arbitrary input and read the output, so it must be authenticated. Provide `authentication` (a UserBuilder that validates the request, e.g. a bearer token or OIDC credential) or, only for local/trusted development, explicitly set `allowUnauthenticated: true`."
34
+ );
35
+ }
21
36
  async function toA2a(agent, options = {}) {
22
37
  var _a, _b, _c, _d;
38
+ const userBuilder = resolveA2aUserBuilder(options);
23
39
  const host = (_a = options.host) != null ? _a : "localhost";
24
40
  const port = (_b = options.port) != null ? _b : 8e3;
25
41
  const protocol = (_c = options.protocol) != null ? _c : "http";
@@ -65,14 +81,14 @@ async function toA2a(agent, options = {}) {
65
81
  "".concat(basePath, "/rest"),
66
82
  restHandler({
67
83
  requestHandler,
68
- userBuilder: UserBuilder.noAuthentication
84
+ userBuilder
69
85
  })
70
86
  );
71
87
  app.use(
72
88
  "".concat(basePath, "/jsonrpc"),
73
89
  jsonRpcHandler({
74
90
  requestHandler,
75
- userBuilder: UserBuilder.noAuthentication
91
+ userBuilder
76
92
  })
77
93
  );
78
94
  return app;
@@ -77,12 +77,13 @@ function toAdkEvent(event, invocationId, agentName) {
77
77
  }
78
78
  return void 0;
79
79
  }
80
- function messageToAdkEvent(msg, invocationId, agentName, parentEvent) {
80
+ function messageToAdkEvent(msg, invocationId, agentName) {
81
81
  const parts = toGenAIParts(msg.parts);
82
- return __spreadProps(__spreadValues({}, createAdkEventFromMetadata(parentEvent || msg)), {
82
+ const content = parts.length === 0 ? void 0 : msg.role === MessageRole.USER ? createUserContent(parts) : createModelContent(parts);
83
+ return __spreadProps(__spreadValues({}, createAdkEventFromMetadata(msg)), {
83
84
  invocationId,
84
85
  author: msg.role === MessageRole.USER ? MessageRole.USER : agentName,
85
- content: msg.role === MessageRole.USER ? createUserContent(parts) : createModelContent(parts),
86
+ content,
86
87
  turnComplete: true,
87
88
  partial: false
88
89
  });
@@ -126,6 +127,9 @@ function taskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
126
127
  return void 0;
127
128
  }
128
129
  const parts = toGenAIParts(msg.parts);
130
+ if (parts.length === 0) {
131
+ return void 0;
132
+ }
129
133
  return __spreadProps(__spreadValues({}, createAdkEventFromMetadata(a2aEvent)), {
130
134
  invocationId,
131
135
  author: agentName,
@@ -155,7 +159,7 @@ function taskToAdkEvent(a2aTask, invocationId, agentName) {
155
159
  }
156
160
  const isTerminal = isTerminalTaskStatusUpdateEvent(a2aTask) || isInputRequiredTaskStatusUpdateEvent(a2aTask);
157
161
  const isFailed = isFailedTaskStatusUpdateEvent(a2aTask);
158
- if (parts.length === 0 && !isTerminal) {
162
+ if (parts.length === 0 && !isFailed) {
159
163
  return void 0;
160
164
  }
161
165
  return __spreadProps(__spreadValues({}, createAdkEventFromMetadata(a2aTask)), {
@@ -73,7 +73,7 @@ function getA2AEventMetadata(adkEvent, {
73
73
  [A2AMetadataKeys.INVOCATION_ID]: adkEvent.invocationId,
74
74
  [A2AMetadataKeys.AUTHOR]: adkEvent.author,
75
75
  [A2AMetadataKeys.BRANCH]: adkEvent.branch,
76
- [A2AMetadataKeys.ERROR_CODE]: adkEvent.errorMessage,
76
+ [A2AMetadataKeys.ERROR_CODE]: adkEvent.errorCode,
77
77
  [A2AMetadataKeys.ERROR_MESSAGE]: adkEvent.errorMessage,
78
78
  [A2AMetadataKeys.CITATION_METADATA]: adkEvent.citationMetadata,
79
79
  [A2AMetadataKeys.GROUNDING_METADATA]: adkEvent.groundingMetadata,
@@ -93,6 +93,7 @@ class BaseAgent {
93
93
  * A unique symbol to identify ADK agent classes.
94
94
  */
95
95
  this[_a] = true;
96
+ this.config = __spreadValues({}, config);
96
97
  this.name = validateAgentName(config.name);
97
98
  this.description = config.description;
98
99
  this.parentAgent = config.parentAgent;
@@ -110,6 +111,44 @@ class BaseAgent {
110
111
  get rootAgent() {
111
112
  return getRootAgent(this);
112
113
  }
114
+ /**
115
+ * Creates a copy of this agent with the given config fields overridden.
116
+ *
117
+ * Mirrors adk-python's `BaseAgent.clone(update=...)`. The clone is a detached
118
+ * root: its `parentAgent` is always `undefined`. Sub-agents are recursively
119
+ * cloned (and re-parented to the clone) unless `subAgents` is overridden.
120
+ * Rebuilding via the concrete constructor re-derives all state, so a cloned
121
+ * `LlmAgent` gets a fresh `requestProcessors` array rather than sharing the
122
+ * original's. See google/adk-js#534.
123
+ *
124
+ * @param overrides Config fields to override on the clone. Overriding
125
+ * `parentAgent` is rejected, matching adk-python.
126
+ * @returns A new detached agent instance of the same concrete class.
127
+ */
128
+ clone(overrides) {
129
+ if (overrides && "parentAgent" in overrides) {
130
+ throw new Error(
131
+ "Cannot update `parentAgent` field in clone. Parent agent is set only when the parent agent is instantiated with the sub-agents."
132
+ );
133
+ }
134
+ const merged = __spreadValues(__spreadValues({}, this.config), overrides);
135
+ merged.parentAgent = void 0;
136
+ const mergedRecord = merged;
137
+ for (const key of Object.keys(mergedRecord)) {
138
+ if (key === "subAgents" || overrides && key in overrides) {
139
+ continue;
140
+ }
141
+ const value = mergedRecord[key];
142
+ if (Array.isArray(value)) {
143
+ mergedRecord[key] = value.slice();
144
+ }
145
+ }
146
+ if (!overrides || !("subAgents" in overrides)) {
147
+ merged.subAgents = this.subAgents.map((subAgent) => subAgent.clone());
148
+ }
149
+ const ctor = this.constructor;
150
+ return new ctor(merged);
151
+ }
113
152
  /**
114
153
  * Entry method to run an agent via text-based conversation.
115
154
  *
@@ -9,11 +9,11 @@ import { createUserContent } from "@google/genai";
9
9
  import { isEmpty } from "lodash-es";
10
10
  import {
11
11
  createEvent,
12
+ generateClientFunctionCallId,
12
13
  getFunctionCalls,
13
14
  getFunctionResponses
14
15
  } from "../events/event.js";
15
16
  import { mergeEventActions } from "../events/event_actions.js";
16
- import { randomUUID } from "../utils/env_aware_utils.js";
17
17
  import { logger } from "../utils/logger.js";
18
18
  import { Context } from "./context.js";
19
19
  import {
@@ -21,7 +21,11 @@ import {
21
21
  tracer,
22
22
  traceToolCall
23
23
  } from "../telemetry/tracing.js";
24
- const AF_FUNCTION_CALL_ID_PREFIX = "adk-";
24
+ import {
25
+ AF_FUNCTION_CALL_ID_PREFIX,
26
+ generateClientFunctionCallId as generateClientFunctionCallId2,
27
+ populateClientFunctionCallId
28
+ } from "../events/event.js";
25
29
  const REQUEST_EUC_FUNCTION_CALL_NAME = "adk_request_credential";
26
30
  const REQUEST_CONFIRMATION_FUNCTION_CALL_NAME = "adk_request_confirmation";
27
31
  const functionsExportedForTestingOnly = {
@@ -29,20 +33,6 @@ const functionsExportedForTestingOnly = {
29
33
  generateAuthEvent,
30
34
  generateRequestConfirmationEvent
31
35
  };
32
- function generateClientFunctionCallId() {
33
- return "".concat(AF_FUNCTION_CALL_ID_PREFIX).concat(randomUUID());
34
- }
35
- function populateClientFunctionCallId(modelResponseEvent) {
36
- const functionCalls = getFunctionCalls(modelResponseEvent);
37
- if (!functionCalls) {
38
- return;
39
- }
40
- for (const functionCall of functionCalls) {
41
- if (!functionCall.id) {
42
- functionCall.id = generateClientFunctionCallId();
43
- }
44
- }
45
- }
46
36
  function getLongRunningFunctionCalls(functionCalls, toolsDict) {
47
37
  const longRunningToolIds = /* @__PURE__ */ new Set();
48
38
  for (const functionCall of functionCalls) {
@@ -420,7 +410,7 @@ export {
420
410
  findMatchingFunctionCall,
421
411
  functionsExportedForTestingOnly,
422
412
  generateAuthEvent,
423
- generateClientFunctionCallId,
413
+ generateClientFunctionCallId2 as generateClientFunctionCallId,
424
414
  generateRequestConfirmationEvent,
425
415
  getLongRunningFunctionCalls,
426
416
  handleFunctionCallList,
@@ -77,7 +77,8 @@ import {
77
77
  createNewEventId,
78
78
  getFunctionCalls,
79
79
  getFunctionResponses,
80
- isFinalResponse
80
+ isFinalResponse,
81
+ populateClientFunctionCallId
81
82
  } from "../events/event.js";
82
83
  import { isBaseLlm } from "../models/base_llm.js";
83
84
  import { LLMRegistry } from "../models/registry.js";
@@ -95,8 +96,7 @@ import {
95
96
  generateAuthEvent,
96
97
  generateRequestConfirmationEvent,
97
98
  getLongRunningFunctionCalls,
98
- handleFunctionCallsAsync,
99
- populateClientFunctionCallId
99
+ handleFunctionCallsAsync
100
100
  } from "./functions.js";
101
101
  import { AUTH_PREPROCESSOR } from "../auth/auth_preprocessor.js";
102
102
  import { AGENT_TRANSFER_LLM_REQUEST_PROCESSOR } from "./processors/agent_transfer_llm_request_processor.js";
@@ -247,6 +247,7 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
247
247
  * This method is only for use by Agent Development Kit.
248
248
  * @param context The context to retrieve the session state.
249
249
  * @returns The resolved globalInstruction field.
250
+ * @deprecated Use GlobalInstructionPlugin instead.
250
251
  */
251
252
  async canonicalGlobalInstruction(context2) {
252
253
  if (typeof this.globalInstruction === "string") {