@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,114 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ /**
4
+ * @license
5
+ * Copyright 2026 Google LLC
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ import { Type } from "@google/genai";
9
+ import { appendInstructions } from "../../models/llm_request.js";
10
+ import { logger } from "../../utils/logger.js";
11
+ import {
12
+ BaseTool
13
+ } from "../base_tool.js";
14
+ class LoadMcpResourceTool extends BaseTool {
15
+ constructor(mcpToolset) {
16
+ super({
17
+ name: "load_mcp_resource",
18
+ description: `Loads resources from the MCP server.
19
+
20
+ NOTE: Call when you need access to resources.`
21
+ });
22
+ this.mcpToolset = mcpToolset;
23
+ }
24
+ _getDeclaration() {
25
+ return {
26
+ name: this.name,
27
+ description: this.description,
28
+ parameters: {
29
+ type: Type.OBJECT,
30
+ properties: {
31
+ resource_names: {
32
+ type: Type.ARRAY,
33
+ items: {
34
+ type: Type.STRING
35
+ },
36
+ description: "The names of the MCP resources to load."
37
+ }
38
+ }
39
+ }
40
+ };
41
+ }
42
+ async runAsync({ args }) {
43
+ const resourceNames = args["resource_names"] || [];
44
+ return {
45
+ resource_names: resourceNames,
46
+ status: "resource contents temporarily inserted and removed. to access these resources, call load_mcp_resource tool again."
47
+ };
48
+ }
49
+ async processLlmRequest(request) {
50
+ await super.processLlmRequest(request);
51
+ await this.appendResourcesToLlmRequest(request.llmRequest);
52
+ }
53
+ async appendResourcesToLlmRequest(llmRequest) {
54
+ var _a, _b;
55
+ try {
56
+ const availableResourceNames = await this.mcpToolset.listResources();
57
+ if (availableResourceNames.length > 0) {
58
+ appendInstructions(llmRequest, [
59
+ `You have a list of MCP resources:
60
+ ${JSON.stringify(
61
+ availableResourceNames
62
+ )}
63
+
64
+ When the user asks questions about any of the resources, you should call the
65
+ \`load_mcp_resource\` function to load the resource. Always call load_mcp_resource
66
+ before answering questions related to the resources.`
67
+ ]);
68
+ }
69
+ } catch (e) {
70
+ logger.warn(`Failed to list MCP resources: ${e}`);
71
+ }
72
+ const lastContent = llmRequest.contents.at(-1);
73
+ const functionResponse = (_b = (_a = lastContent == null ? void 0 : lastContent.parts) == null ? void 0 : _a[0]) == null ? void 0 : _b.functionResponse;
74
+ if (!functionResponse || functionResponse.name !== this.name) {
75
+ return;
76
+ }
77
+ const response = functionResponse.response || {};
78
+ const requestedResourceNames = response["resource_names"] || [];
79
+ for (const resourceName of requestedResourceNames) {
80
+ try {
81
+ const resourceContents = await this.mcpToolset.readResource(resourceName);
82
+ for (const content of resourceContents) {
83
+ llmRequest.contents.push({
84
+ role: "user",
85
+ parts: [
86
+ { text: `Resource ${resourceName} is:` },
87
+ this.mcpContentToPart(content, resourceName)
88
+ ]
89
+ });
90
+ }
91
+ } catch (e) {
92
+ logger.warn(`Failed to read MCP resource '${resourceName}': ${e}`);
93
+ }
94
+ }
95
+ }
96
+ mcpContentToPart(content, resourceName) {
97
+ var _a;
98
+ if ("text" in content) {
99
+ return { text: content.text };
100
+ }
101
+ if ("blob" in content) {
102
+ return {
103
+ inlineData: {
104
+ data: content.blob,
105
+ mimeType: (_a = content.mimeType) != null ? _a : "application/octet-stream"
106
+ }
107
+ };
108
+ }
109
+ return { text: `[Unknown content type for ${resourceName}]` };
110
+ }
111
+ }
112
+ export {
113
+ LoadMcpResourceTool
114
+ };
@@ -48,6 +48,69 @@ class MCPToolset extends BaseToolset {
48
48
  );
49
49
  return tools;
50
50
  }
51
+ /**
52
+ * Lists the names of the resources advertised by the MCP server.
53
+ *
54
+ * @return The resource names available on the server.
55
+ */
56
+ async listResources() {
57
+ const session = await this.mcpSessionManager.createSession();
58
+ try {
59
+ const result = await session.listResources();
60
+ return result.resources.map((resource) => resource.name);
61
+ } finally {
62
+ await this.mcpSessionManager.closeSession(session);
63
+ }
64
+ }
65
+ /**
66
+ * Returns metadata for the resource whose name matches `name`.
67
+ *
68
+ * @param name The advertised name of the resource.
69
+ * @return The matching MCP `Resource`.
70
+ * @throws If no resource with the given name is advertised by the server.
71
+ */
72
+ async getResourceInfo(name) {
73
+ const session = await this.mcpSessionManager.createSession();
74
+ let result;
75
+ try {
76
+ result = await session.listResources();
77
+ } finally {
78
+ await this.mcpSessionManager.closeSession(session);
79
+ }
80
+ const resource = result.resources.find(
81
+ (candidate) => candidate.name === name
82
+ );
83
+ if (!resource) {
84
+ throw new Error(`Resource with name '${name}' not found.`);
85
+ }
86
+ return resource;
87
+ }
88
+ /**
89
+ * Reads the contents of the named resource from the MCP server.
90
+ *
91
+ * The resource name is resolved to a URI via {@link getResourceInfo} before
92
+ * reading. Binary contents are returned base64-encoded, exactly as provided
93
+ * by the server (never decoded and re-encoded).
94
+ *
95
+ * @param name The advertised name of the resource to read.
96
+ * @return The resource contents (text and/or base64-encoded binary).
97
+ * @throws If the resource is unknown or has no URI.
98
+ */
99
+ async readResource(name) {
100
+ const resourceInfo = await this.getResourceInfo(name);
101
+ if (!resourceInfo.uri) {
102
+ throw new Error(`Resource '${name}' has no URI.`);
103
+ }
104
+ const session = await this.mcpSessionManager.createSession();
105
+ try {
106
+ const result = await session.readResource({
107
+ uri: resourceInfo.uri
108
+ });
109
+ return result.contents;
110
+ } finally {
111
+ await this.mcpSessionManager.closeSession(session);
112
+ }
113
+ }
51
114
  async close() {
52
115
  const sessions = this.mcpSessionManager.getActiveSessions();
53
116
  await Promise.allSettled(
@@ -62,19 +62,22 @@ let ToolAuthHandler = class {
62
62
  rawAuthCredential: this.authCredential,
63
63
  credentialKey: this.credentialKey || "default_openapi_key"
64
64
  };
65
- const credential = this.context.getAuthResponse(authConfig);
66
- if (credential) {
67
- const exchanger = new AutoAuthCredentialExchanger();
68
- const result = await exchanger.exchange({
69
- authScheme: this.authScheme,
70
- authCredential: credential
71
- });
65
+ const authResponseCredential = this.context.getAuthResponse(authConfig);
66
+ const credential = authResponseCredential != null ? authResponseCredential : this.authCredential;
67
+ if (!credential) {
68
+ this.context.requestCredential(authConfig);
69
+ return { state: "pending" };
70
+ }
71
+ const exchanger = new AutoAuthCredentialExchanger();
72
+ const result = await exchanger.exchange({
73
+ authScheme: this.authScheme,
74
+ authCredential: credential
75
+ });
76
+ if (authResponseCredential || result.wasExchanged) {
72
77
  const key = store.getCredentialKey(this.authScheme);
73
78
  store.storeCredential(key, result.credential);
74
- return { state: "done", authCredential: result.credential };
75
79
  }
76
- this.context.requestCredential(authConfig);
77
- return { state: "pending" };
80
+ return { state: "done", authCredential: result.credential };
78
81
  }
79
82
  };
80
83
  __decorateClass([
@@ -21,6 +21,15 @@ import { CodeExecutionLanguage } from "../../code_executors/code_execution_utils
21
21
  import { experimental } from "../../utils/experimental.js";
22
22
  import { materializeFiles } from "../../utils/file_utils.js";
23
23
  import { BaseTool } from "../base_tool.js";
24
+ var RunSkillInlineScriptErrorCode = /* @__PURE__ */ ((RunSkillInlineScriptErrorCode2) => {
25
+ RunSkillInlineScriptErrorCode2["MISSING_SCRIPT_CONTENT"] = "MISSING_SCRIPT_CONTENT";
26
+ RunSkillInlineScriptErrorCode2["MISSING_LANGUAGE"] = "MISSING_LANGUAGE";
27
+ RunSkillInlineScriptErrorCode2["NO_CODE_EXECUTOR"] = "NO_CODE_EXECUTOR";
28
+ RunSkillInlineScriptErrorCode2["EXECUTION_ERROR"] = "EXECUTION_ERROR";
29
+ RunSkillInlineScriptErrorCode2["CONFIRMATION_REJECTED"] = "CONFIRMATION_REJECTED";
30
+ return RunSkillInlineScriptErrorCode2;
31
+ })(RunSkillInlineScriptErrorCode || {});
32
+ const REQUIRE_CONFIRMATION_MESSAGE = "This tool call needs external confirmation before completion.";
24
33
  let RunSkillInlineScriptTool = class extends BaseTool {
25
34
  constructor(toolset) {
26
35
  super({
@@ -70,13 +79,13 @@ let RunSkillInlineScriptTool = class extends BaseTool {
70
79
  if (!inlineScriptContent) {
71
80
  return {
72
81
  error: "Script content is required.",
73
- errorCode: "MISSING_SCRIPT_CONTENT"
82
+ errorCode: "MISSING_SCRIPT_CONTENT" /* MISSING_SCRIPT_CONTENT */
74
83
  };
75
84
  }
76
85
  if (!language) {
77
86
  return {
78
87
  error: "Language is required.",
79
- errorCode: "MISSING_LANGUAGE"
88
+ errorCode: "MISSING_LANGUAGE" /* MISSING_LANGUAGE */
80
89
  };
81
90
  }
82
91
  let codeExecutor = (_a = this.toolset) == null ? void 0 : _a.codeExecutor;
@@ -89,9 +98,17 @@ let RunSkillInlineScriptTool = class extends BaseTool {
89
98
  if (!codeExecutor) {
90
99
  return {
91
100
  error: "No code executor configured.",
92
- errorCode: "NO_CODE_EXECUTOR"
101
+ errorCode: "NO_CODE_EXECUTOR" /* NO_CODE_EXECUTOR */
93
102
  };
94
103
  }
104
+ const confirmationResult = this.enforceConfirmation(
105
+ toolContext,
106
+ inlineScriptContent,
107
+ language
108
+ );
109
+ if (confirmationResult) {
110
+ return confirmationResult;
111
+ }
95
112
  try {
96
113
  const result = await codeExecutor.executeCode({
97
114
  invocationContext: toolContext.invocationContext,
@@ -107,14 +124,46 @@ let RunSkillInlineScriptTool = class extends BaseTool {
107
124
  } catch (e) {
108
125
  return {
109
126
  error: `Failed to execute inline script: ${e.message}`,
110
- errorCode: "EXECUTION_ERROR"
127
+ errorCode: "EXECUTION_ERROR" /* EXECUTION_ERROR */
128
+ };
129
+ }
130
+ }
131
+ /**
132
+ * Enforces a human-in-the-loop confirmation gate before executing an inline
133
+ * script, using the repo's standard tool-confirmation mechanism.
134
+ *
135
+ * - When no confirmation has been provided yet, a confirmation is requested
136
+ * (surfacing the language and script that would run) and an intermediate
137
+ * result is returned so the tool call pauses until the client responds.
138
+ * - When a confirmation exists but was not confirmed, a rejection error is
139
+ * returned and execution is refused.
140
+ * - When the confirmation is confirmed, `undefined` is returned to allow the
141
+ * caller to proceed with execution.
142
+ */
143
+ enforceConfirmation(toolContext, scriptContent, language) {
144
+ const confirmation = toolContext.toolConfirmation;
145
+ if (!confirmation) {
146
+ toolContext.requestConfirmation({
147
+ hint: `Confirmation is required before executing an inline skill script. The agent requested to run the following ${language} script in the code executor. Only approve if you trust its contents:
148
+
149
+ ` + scriptContent,
150
+ payload: { language, scriptContent }
151
+ });
152
+ return { partial: REQUIRE_CONFIRMATION_MESSAGE };
153
+ }
154
+ if (!confirmation.confirmed) {
155
+ return {
156
+ error: "Inline script execution was not confirmed and was rejected.",
157
+ errorCode: "CONFIRMATION_REJECTED" /* CONFIRMATION_REJECTED */
111
158
  };
112
159
  }
160
+ return void 0;
113
161
  }
114
162
  };
115
163
  RunSkillInlineScriptTool = __decorateClass([
116
164
  experimental
117
165
  ], RunSkillInlineScriptTool);
118
166
  export {
167
+ RunSkillInlineScriptErrorCode,
119
168
  RunSkillInlineScriptTool
120
169
  };
@@ -55,9 +55,11 @@ let SkillToolset = class extends BaseToolset {
55
55
  new ListSkillsTool(this),
56
56
  new LoadSkillTool(this),
57
57
  new LoadSkillResourceTool(this),
58
- new RunSkillScriptTool(this),
59
- new RunSkillInlineScriptTool(this)
58
+ new RunSkillScriptTool(this)
60
59
  ];
60
+ if (options.allowInlineScripts) {
61
+ this.tools.push(new RunSkillInlineScriptTool(this));
62
+ }
61
63
  if (this.registry) {
62
64
  this.tools.push(new SearchSkillsTool(this));
63
65
  }
@@ -0,0 +1,13 @@
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
+ function isSegmentPrefix(currentBranch, targetBranch) {
9
+ return !targetBranch || targetBranch === currentBranch || !!currentBranch && currentBranch.startsWith(`${targetBranch}.`);
10
+ }
11
+ export {
12
+ isSegmentPrefix
13
+ };
@@ -9,7 +9,7 @@ import {
9
9
  FinishReason
10
10
  } from "@google/genai";
11
11
  import { JSONPath } from "jsonpath-plus";
12
- import { generateClientFunctionCallId } from "../agents/functions.js";
12
+ import { generateClientFunctionCallId } from "../events/event.js";
13
13
  import { FeatureName, isFeatureEnabled } from "../features/feature_registry.js";
14
14
  import { createLlmResponse } from "../models/llm_response.js";
15
15
  const UNSAFE_PROPERTY_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
@@ -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.4.0";
8
+ const version = "1.5.0";
9
9
  export {
10
10
  version
11
11
  };
@@ -68,8 +68,12 @@ export interface RemoteA2AAgentConfig extends BaseAgentConfig {
68
68
  }
69
69
  /**
70
70
  * RemoteA2AAgent delegates execution to a remote agent using the A2A protocol.
71
+ *
72
+ * @remarks
73
+ * A cloned `RemoteA2AAgent` (via {@link BaseAgent.clone}) is a fresh,
74
+ * uninitialized instance that re-resolves its client and card on first use.
71
75
  */
72
- export declare class RemoteA2AAgent extends BaseAgent {
76
+ export declare class RemoteA2AAgent extends BaseAgent<RemoteA2AAgentConfig> {
73
77
  private readonly a2aConfig;
74
78
  private client?;
75
79
  private card?;
@@ -4,12 +4,25 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { AgentCard } from '@a2a-js/sdk';
7
+ import { UserBuilder } from '@a2a-js/sdk/server/express';
7
8
  import express from 'express';
8
9
  import { BaseAgent } from '../agents/base_agent.js';
9
10
  import { BaseArtifactService } from '../artifacts/base_artifact_service.js';
10
11
  import { BaseMemoryService } from '../memory/base_memory_service.js';
11
12
  import { Runner } from '../runner/runner.js';
12
13
  import { BaseSessionService } from '../sessions/base_session_service.js';
14
+ /**
15
+ * A request authenticator for the A2A surface.
16
+ *
17
+ * This is the `UserBuilder` hook from `@a2a-js/sdk`: an async function that
18
+ * receives the incoming Express request, validates its credentials (for
19
+ * example a bearer token or an OIDC ID token) and resolves to the
20
+ * authenticated `User`. Implementations should reject unauthenticated
21
+ * requests by throwing (or by resolving to a user whose `isAuthenticated` is
22
+ * `false`), which prevents the underlying agent and its tools from being
23
+ * invoked by anonymous callers.
24
+ */
25
+ export type A2aUserBuilder = UserBuilder;
13
26
  /**
14
27
  * Options for the `toA2a` function.
15
28
  */
@@ -34,6 +47,31 @@ export interface ToA2aOptions {
34
47
  artifactService?: BaseArtifactService;
35
48
  /** Optional existing express application */
36
49
  app?: express.Application;
50
+ /**
51
+ * Authenticator used to validate incoming A2A requests.
52
+ *
53
+ * A2A is the production-intended inter-agent surface: any network-reachable
54
+ * caller that can reach it can invoke the agent and its tools with arbitrary
55
+ * input and read the output. Provide a `UserBuilder` (from
56
+ * `@a2a-js/sdk/server/express`) that validates the request's credentials —
57
+ * for example a bearer token or an OIDC ID token — and it will be wired into
58
+ * both the REST and JSON-RPC handlers.
59
+ *
60
+ * When omitted, `toA2a` fails closed and throws unless
61
+ * {@link ToA2aOptions.allowUnauthenticated} is explicitly set to `true`.
62
+ */
63
+ authentication?: A2aUserBuilder;
64
+ /**
65
+ * Explicit escape hatch to mount the A2A surface WITHOUT authentication.
66
+ *
67
+ * This is intentionally insecure and must only be used for local, trusted
68
+ * development where the surface is not network reachable. When set to
69
+ * `true` (and no {@link ToA2aOptions.authentication} is provided), a loud
70
+ * warning is logged and the handlers are mounted with no authentication.
71
+ *
72
+ * Defaults to `false`, which makes `toA2a` fail closed.
73
+ */
74
+ allowUnauthenticated?: boolean;
37
75
  }
38
76
  /**
39
77
  * Converts an ADK agent to an Express application with A2A handlers.
@@ -45,12 +45,25 @@ declare const BASE_AGENT_SIGNATURE_SYMBOL: unique symbol;
45
45
  export declare function isBaseAgent(obj: unknown): obj is BaseAgent;
46
46
  /**
47
47
  * Base class for all agents in Agent Development Kit.
48
+ *
49
+ * The class is generic over its config type so that {@link clone} can be typed
50
+ * per subclass (e.g. `LlmAgent.clone({instruction})`). The default keeps bare
51
+ * `BaseAgent` references valid as `BaseAgent<BaseAgentConfig>`.
48
52
  */
49
- export declare abstract class BaseAgent {
53
+ export declare abstract class BaseAgent<TConfig extends BaseAgentConfig = BaseAgentConfig> {
50
54
  /**
51
55
  * A unique symbol to identify ADK agent classes.
52
56
  */
53
57
  readonly [BASE_AGENT_SIGNATURE_SYMBOL] = true;
58
+ /**
59
+ * The config this agent was constructed from.
60
+ *
61
+ * Stored so {@link clone} can rebuild the agent by re-running the concrete
62
+ * constructor with overrides applied, which re-derives all state correctly
63
+ * instead of copying an already-mutated instance. Shallow-copied so later
64
+ * external mutation of the caller's object does not leak into clones.
65
+ */
66
+ protected readonly config: TConfig;
54
67
  /**
55
68
  * The agent's name.
56
69
  * Agent name must be a JS identifier and unique within the agent tree.
@@ -112,6 +125,21 @@ export declare abstract class BaseAgent {
112
125
  */
113
126
  readonly afterAgentCallback: SingleAgentCallback[];
114
127
  constructor(config: BaseAgentConfig);
128
+ /**
129
+ * Creates a copy of this agent with the given config fields overridden.
130
+ *
131
+ * Mirrors adk-python's `BaseAgent.clone(update=...)`. The clone is a detached
132
+ * root: its `parentAgent` is always `undefined`. Sub-agents are recursively
133
+ * cloned (and re-parented to the clone) unless `subAgents` is overridden.
134
+ * Rebuilding via the concrete constructor re-derives all state, so a cloned
135
+ * `LlmAgent` gets a fresh `requestProcessors` array rather than sharing the
136
+ * original's. See google/adk-js#534.
137
+ *
138
+ * @param overrides Config fields to override on the clone. Overriding
139
+ * `parentAgent` is rejected, matching adk-python.
140
+ * @returns A new detached agent instance of the same concrete class.
141
+ */
142
+ clone(overrides?: Partial<TConfig>): this;
115
143
  /**
116
144
  * Entry method to run an agent via text-based conversation.
117
145
  *
@@ -9,7 +9,7 @@ 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
+ export { AF_FUNCTION_CALL_ID_PREFIX, generateClientFunctionCallId, populateClientFunctionCallId, } from '../events/event.js';
13
13
  export declare const REQUEST_EUC_FUNCTION_CALL_NAME = "adk_request_credential";
14
14
  export declare const REQUEST_CONFIRMATION_FUNCTION_CALL_NAME = "adk_request_confirmation";
15
15
  export declare const functionsExportedForTestingOnly: {
@@ -17,14 +17,6 @@ export declare const functionsExportedForTestingOnly: {
17
17
  generateAuthEvent: typeof generateAuthEvent;
18
18
  generateRequestConfirmationEvent: typeof generateRequestConfirmationEvent;
19
19
  };
20
- export declare function generateClientFunctionCallId(): string;
21
- /**
22
- * Populates client-side function call IDs.
23
- *
24
- * It iterates through all function calls in the event and assigns a
25
- * unique client-side ID to each one that doesn't already have an ID.
26
- */
27
- export declare function populateClientFunctionCallId(modelResponseEvent: Event): void;
28
20
  /**
29
21
  * Returns a set of function call ids of the long running tools.
30
22
  */
@@ -130,6 +130,8 @@ export interface LlmAgentConfig extends BaseAgentConfig {
130
130
  *
131
131
  * For example: use globalInstruction to make all agents have a stable
132
132
  * identity or personality.
133
+ *
134
+ * @deprecated Use GlobalInstructionPlugin instead.
133
135
  */
134
136
  globalInstruction?: string | InstructionProvider;
135
137
  /** Tools available to this agent. */
@@ -224,11 +226,12 @@ export declare function isLlmAgent(obj: unknown): obj is LlmAgent;
224
226
  /**
225
227
  * An agent that uses a large language model to generate responses.
226
228
  */
227
- export declare class LlmAgent extends BaseAgent {
229
+ export declare class LlmAgent extends BaseAgent<LlmAgentConfig> {
228
230
  /** A unique symbol to identify ADK LLM agent class. */
229
231
  readonly [LLM_AGENT_SIGNATURE_SYMBOL] = true;
230
232
  model?: string | BaseLlm;
231
233
  instruction: string | InstructionProvider;
234
+ /** @deprecated Use GlobalInstructionPlugin instead. */
232
235
  globalInstruction: string | InstructionProvider;
233
236
  tools: ToolUnion[];
234
237
  generateContentConfig?: GenerateContentConfig;
@@ -270,6 +273,7 @@ export declare class LlmAgent extends BaseAgent {
270
273
  * This method is only for use by Agent Development Kit.
271
274
  * @param context The context to retrieve the session state.
272
275
  * @returns The resolved globalInstruction field.
276
+ * @deprecated Use GlobalInstructionPlugin instead.
273
277
  */
274
278
  canonicalGlobalInstruction(context: ReadonlyContext): Promise<{
275
279
  instruction: string;
@@ -34,7 +34,7 @@ export declare function isLoopAgent(obj: unknown): obj is LoopAgent;
34
34
  * When sub-agent generates an event with escalate or max_iterations are
35
35
  * reached, the loop agent will stop.
36
36
  */
37
- export declare class LoopAgent extends BaseAgent {
37
+ export declare class LoopAgent extends BaseAgent<LoopAgentConfig> {
38
38
  /**
39
39
  * A unique symbol to identify ADK loop agent class.
40
40
  */
@@ -42,6 +42,6 @@ export declare class LoopAgent extends BaseAgent {
42
42
  readonly maxIterations: number;
43
43
  constructor(config: LoopAgentConfig);
44
44
  protected runAsyncImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
45
- protected runLiveImpl(_context: InvocationContext): AsyncGenerator<Event, void, void>;
45
+ protected runLiveImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
46
46
  }
47
47
  export {};
@@ -41,12 +41,35 @@ export interface RoutedAgentConfig extends BaseAgentConfig {
41
41
  /**
42
42
  * A BaseAgent implementation that delegates to one of multiple agents based on a router function.
43
43
  * Routing is strictly limited to the agents passed in the config.
44
+ *
45
+ * @remarks
46
+ * Cloning is supported: {@link RoutedAgent.clone} deep-clones the routing
47
+ * targets from `config.agents` and re-parents the fresh copies onto the clone,
48
+ * so the clone is a detached root that routes identically to the original while
49
+ * leaving the original agent tree untouched.
44
50
  */
45
- export declare class RoutedAgent extends BaseAgent {
51
+ export declare class RoutedAgent extends BaseAgent<RoutedAgentConfig> {
46
52
  readonly [ROUTED_AGENT_SIGNATURE_SYMBOL] = true;
47
53
  private readonly agents;
48
54
  private readonly router;
49
55
  constructor(config: RoutedAgentConfig);
56
+ /**
57
+ * Creates a detached copy of this routed agent.
58
+ *
59
+ * The inherited {@link BaseAgent.clone} only deep-clones `subAgents`, but a
60
+ * `RoutedAgent` derives its routing targets from `config.agents`. Rebuilding
61
+ * through the base clone alone would re-read the already-parented original
62
+ * agents and throw "already has a parent agent". This override deep-clones the
63
+ * routing targets (unless the caller overrides `agents`) so the rebuilt
64
+ * constructor re-parents fresh, detached copies. The array-vs-record shape
65
+ * and, for records, the keys are preserved so the router keeps selecting the
66
+ * same targets.
67
+ *
68
+ * @param overrides Config fields to override on the clone. Overriding
69
+ * `parentAgent` is rejected by the base implementation.
70
+ * @returns A new detached `RoutedAgent` of the same concrete class.
71
+ */
72
+ clone(overrides?: Partial<RoutedAgentConfig>): this;
50
73
  /**
51
74
  * Runs the selected agent via text-based conversation.
52
75
  */
@@ -94,6 +94,7 @@ export interface RunConfig {
94
94
  * @throws {Error} When `params.maxLlmCalls` exceeds `Number.MAX_SAFE_INTEGER`.
95
95
  */
96
96
  export declare function createRunConfig(params?: Partial<RunConfig>): {
97
+ maxLlmCalls: number;
97
98
  speechConfig?: SpeechConfig | undefined;
98
99
  responseModalities?: Modality[] | undefined;
99
100
  saveInputBlobsAsArtifacts: boolean;
@@ -104,6 +105,5 @@ export declare function createRunConfig(params?: Partial<RunConfig>): {
104
105
  enableAffectiveDialog: boolean;
105
106
  proactivity?: ProactivityConfig | undefined;
106
107
  realtimeInputConfig?: RealtimeInputConfig | undefined;
107
- maxLlmCalls: number;
108
108
  pauseOnToolCalls: boolean;
109
109
  };
@@ -58,6 +58,8 @@ export type { ExecuteCodeParams } from './code_executors/base_code_executor.js';
58
58
  export { BuiltInCodeExecutor } from './code_executors/built_in_code_executor.js';
59
59
  export { CodeExecutionLanguage, FileContentEncoding, type CodeExecutionInput, type CodeExecutionResult, type File, } from './code_executors/code_execution_utils.js';
60
60
  export { AgentControlledContextCompactor } from './context/agent_controlled_context_compactor.js';
61
+ export { AnchoredContextCompactor } from './context/anchored_context_compactor.js';
62
+ export type { AnchoredContextCompactorOptions } from './context/anchored_context_compactor.js';
61
63
  export type { BaseContextCompactor } from './context/base_context_compactor.js';
62
64
  export type { BaseSummarizer } from './context/summarizers/base_summarizer.js';
63
65
  export { LlmSummarizer } from './context/summarizers/llm_summarizer.js';
@@ -68,9 +70,9 @@ export { TrajectoryThoughtPruningCompactor } from './context/trajectory_thought_
68
70
  export type { TrajectoryThoughtPruningCompactorOptions } from './context/trajectory_thought_pruning_compactor.js';
69
71
  export { TruncatingContextCompactor } from './context/truncating_context_compactor.js';
70
72
  export type { TruncatingContextCompactorOptions } from './context/truncating_context_compactor.js';
71
- export { isCompactedEvent } from './events/compacted_event.js';
73
+ export { isCompactedEvent, isScratchpadEvent } from './events/compacted_event.js';
72
74
  export type { CompactedEvent } from './events/compacted_event.js';
73
- export { createEvent, getFunctionCalls, getFunctionResponses, hasTrailingCodeExecutionResult, isFinalResponse, stringifyContent, } from './events/event.js';
75
+ export { createEvent, generateClientFunctionCallId, getFunctionCalls, getFunctionResponses, hasThoughts, hasTrailingCodeExecutionResult, isFinalResponse, populateClientFunctionCallId, pruneThoughts, stringifyContent, } from './events/event.js';
74
76
  export type { Event } from './events/event.js';
75
77
  export { createEventActions } from './events/event_actions.js';
76
78
  export type { EventActions } from './events/event_actions.js';
@@ -96,6 +98,7 @@ export type { BaseLlmType } from './models/registry.js';
96
98
  export { RoutedLlm } from './models/routed_llm.js';
97
99
  export type { LlmRouter } from './models/routed_llm.js';
98
100
  export { BasePlugin, ContextCompactionTrigger } from './plugins/base_plugin.js';
101
+ export { GlobalInstructionPlugin } from './plugins/global_instruction_plugin.js';
99
102
  export { LoggingPlugin } from './plugins/logging_plugin.js';
100
103
  export { PluginManager } from './plugins/plugin_manager.js';
101
104
  export { InMemoryPolicyEngine, PolicyOutcome, REQUEST_CONFIRMATION_FUNCTION_CALL_NAME, SecurityPlugin, getAskUserConfirmationFunctionCalls, } from './plugins/security_plugin.js';
@@ -116,6 +119,8 @@ export type { BaseToolParams, RunAsyncToolRequest, ToolProcessLlmRequest, } from
116
119
  export { BaseToolset, isBaseToolset } from './tools/base_toolset.js';
117
120
  export type { ToolPredicate } from './tools/base_toolset.js';
118
121
  export { ConsolidateContextTool } from './tools/consolidate_context_tool.js';
122
+ export { ENTERPRISE_WEB_SEARCH, EnterpriseWebSearchTool, } from './tools/enterprise_web_search_tool.js';
123
+ export { ExampleTool } from './tools/example_tool.js';
119
124
  export { EXIT_LOOP, ExitLoopTool } from './tools/exit_loop_tool.js';
120
125
  export { FunctionTool, isFunctionTool } from './tools/function_tool.js';
121
126
  export type { ToolExecuteArgument, ToolExecuteFunction, ToolInputParameters, ToolOptions, } from './tools/function_tool.js';
@@ -123,6 +128,8 @@ export { GOOGLE_MAPS_GROUNDING, GoogleMapsGroundingTool, } from './tools/google_
123
128
  export { GOOGLE_SEARCH, GoogleSearchTool } from './tools/google_search_tool.js';
124
129
  export { LOAD_ARTIFACTS, LoadArtifactsTool, } from './tools/load_artifacts_tool.js';
125
130
  export { LOAD_MEMORY, LoadMemoryTool } from './tools/load_memory_tool.js';
131
+ export { LOAD_WEB_PAGE, loadWebPage } from './tools/load_web_page.js';
132
+ export type { LoadWebPageOptions } from './tools/load_web_page.js';
126
133
  export { LongRunningFunctionTool } from './tools/long_running_tool.js';
127
134
  export { PRELOAD_MEMORY, PreloadMemoryTool, } from './tools/preload_memory_tool.js';
128
135
  export { ToolConfirmation } from './tools/tool_confirmation.js';