@google/adk 1.3.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.
- package/dist/cjs/a2a/agent_to_a2a.js +18 -2
- package/dist/cjs/a2a/event_converter_utils.js +8 -4
- package/dist/cjs/a2a/metadata_converter_utils.js +1 -1
- package/dist/cjs/agents/active_streaming_tool.js +6 -1
- package/dist/cjs/agents/base_agent.js +39 -0
- package/dist/cjs/agents/context.js +1 -11
- package/dist/cjs/agents/functions.js +39 -35
- package/dist/cjs/agents/instructions.js +23 -5
- package/dist/cjs/agents/invocation_context.js +2 -5
- package/dist/cjs/agents/llm_agent.js +10 -7
- package/dist/cjs/agents/loop_agent.js +15 -3
- package/dist/cjs/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/cjs/agents/processors/content_processor_utils.js +18 -4
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +4 -2
- package/dist/cjs/agents/processors/interactions_request_processor.js +63 -0
- package/dist/cjs/agents/routed_agent.js +31 -0
- package/dist/cjs/agents/run_config.js +3 -2
- package/dist/cjs/apps/app.js +79 -0
- package/dist/cjs/apps/resumability_config.js +44 -0
- package/dist/cjs/artifacts/file_artifact_service.js +14 -1
- package/dist/cjs/artifacts/gcs_artifact_service.js +57 -15
- package/dist/cjs/artifacts/in_memory_artifact_service.js +12 -1
- package/dist/cjs/artifacts/scoped_artifact_service.js +101 -0
- package/dist/cjs/artifacts/session_artifact_service.js +27 -0
- package/dist/cjs/auth/oauth2/oauth2_discovery.js +17 -5
- package/dist/cjs/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/cjs/common.js +76 -0
- package/dist/cjs/context/agent_controlled_context_compactor.js +109 -0
- package/dist/cjs/context/anchored_context_compactor.js +127 -0
- package/dist/cjs/context/compaction_utils.js +52 -0
- package/dist/cjs/context/token_based_context_compactor.js +52 -33
- package/dist/cjs/context/trajectory_thought_pruning_compactor.js +71 -0
- package/dist/cjs/events/compacted_event.js +9 -3
- package/dist/cjs/events/event.js +52 -0
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/cjs/models/google_llm.js +25 -10
- package/dist/cjs/models/interactions_utils.js +732 -0
- package/dist/cjs/plugins/base_plugin.js +1 -0
- package/dist/cjs/plugins/global_instruction_plugin.js +97 -0
- package/dist/cjs/runner/in_memory_runner.js +13 -2
- package/dist/cjs/runner/runner.js +143 -83
- package/dist/cjs/sessions/base_session_service.js +6 -1
- package/dist/cjs/sessions/database_session_service.js +24 -7
- package/dist/cjs/sessions/vertex_ai_session_service.js +19 -4
- package/dist/cjs/skills/loader.js +2 -2
- package/dist/cjs/tools/base_toolset.js +1 -1
- package/dist/cjs/tools/consolidate_context_tool.js +79 -0
- package/dist/cjs/tools/enterprise_web_search_tool.js +81 -0
- package/dist/cjs/tools/example_tool.js +68 -0
- package/dist/cjs/tools/forwarding_artifact_service.js +16 -28
- package/dist/cjs/tools/load_web_page.js +250 -0
- package/dist/cjs/tools/mcp/load_mcp_resource_tool.js +140 -0
- package/dist/cjs/tools/mcp/mcp_toolset.js +63 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -22
- package/dist/cjs/tools/skill/run_skill_inline_script_tool.js +54 -4
- package/dist/cjs/tools/skill/skill_toolset.js +4 -2
- package/dist/cjs/utils/async_hooks_shim.js +52 -0
- package/dist/cjs/utils/branch_trie.js +41 -0
- package/dist/cjs/utils/client_labels.js +41 -3
- package/dist/cjs/utils/env_aware_utils.js +10 -1
- package/dist/cjs/utils/streaming_utils.js +15 -9
- package/dist/cjs/utils/task.js +62 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/agent_to_a2a.js +18 -2
- package/dist/esm/a2a/event_converter_utils.js +8 -4
- package/dist/esm/a2a/metadata_converter_utils.js +1 -1
- package/dist/esm/agents/active_streaming_tool.js +6 -1
- package/dist/esm/agents/base_agent.js +39 -0
- package/dist/esm/agents/context.js +1 -11
- package/dist/esm/agents/functions.js +43 -32
- package/dist/esm/agents/instructions.js +23 -5
- package/dist/esm/agents/invocation_context.js +2 -5
- package/dist/esm/agents/llm_agent.js +12 -9
- package/dist/esm/agents/loop_agent.js +15 -3
- package/dist/esm/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/esm/agents/processors/content_processor_utils.js +16 -3
- package/dist/esm/agents/processors/context_compactor_request_processor.js +4 -2
- package/dist/esm/agents/processors/interactions_request_processor.js +34 -0
- package/dist/esm/agents/routed_agent.js +31 -0
- package/dist/esm/agents/run_config.js +3 -2
- package/dist/esm/apps/app.js +49 -0
- package/dist/esm/apps/resumability_config.js +16 -0
- package/dist/esm/artifacts/file_artifact_service.js +14 -1
- package/dist/esm/artifacts/gcs_artifact_service.js +57 -15
- package/dist/esm/artifacts/in_memory_artifact_service.js +12 -1
- package/dist/esm/artifacts/scoped_artifact_service.js +73 -0
- package/dist/esm/artifacts/session_artifact_service.js +7 -0
- package/dist/esm/auth/oauth2/oauth2_discovery.js +14 -4
- package/dist/esm/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/esm/common.js +67 -3
- package/dist/esm/context/agent_controlled_context_compactor.js +81 -0
- package/dist/esm/context/anchored_context_compactor.js +99 -0
- package/dist/esm/context/compaction_utils.js +27 -0
- package/dist/esm/context/token_based_context_compactor.js +52 -33
- package/dist/esm/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/esm/events/compacted_event.js +7 -2
- package/dist/esm/events/event.js +46 -0
- package/dist/esm/index.js +6 -1
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/esm/models/google_llm.js +23 -9
- package/dist/esm/models/interactions_utils.js +697 -0
- package/dist/esm/plugins/base_plugin.js +1 -0
- package/dist/esm/plugins/global_instruction_plugin.js +69 -0
- package/dist/esm/runner/in_memory_runner.js +13 -2
- package/dist/esm/runner/runner.js +141 -84
- package/dist/esm/sessions/base_session_service.js +6 -1
- package/dist/esm/sessions/database_session_service.js +24 -7
- package/dist/esm/sessions/vertex_ai_session_service.js +17 -3
- package/dist/esm/skills/loader.js +2 -2
- package/dist/esm/tools/base_toolset.js +1 -1
- package/dist/esm/tools/consolidate_context_tool.js +51 -0
- package/dist/esm/tools/enterprise_web_search_tool.js +55 -0
- package/dist/esm/tools/example_tool.js +42 -0
- package/dist/esm/tools/forwarding_artifact_service.js +16 -28
- package/dist/esm/tools/load_web_page.js +221 -0
- package/dist/esm/tools/mcp/load_mcp_resource_tool.js +114 -0
- package/dist/esm/tools/mcp/mcp_toolset.js +63 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -22
- package/dist/esm/tools/skill/run_skill_inline_script_tool.js +53 -4
- package/dist/esm/tools/skill/skill_toolset.js +4 -2
- package/dist/esm/utils/async_hooks_shim.js +24 -0
- package/dist/esm/utils/branch_trie.js +13 -0
- package/dist/esm/utils/client_labels.js +38 -2
- package/dist/esm/utils/env_aware_utils.js +10 -1
- package/dist/esm/utils/streaming_utils.js +11 -5
- package/dist/esm/utils/task.js +34 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +5 -1
- package/dist/types/a2a/agent_to_a2a.d.ts +38 -0
- package/dist/types/agents/active_streaming_tool.d.ts +3 -4
- package/dist/types/agents/base_agent.d.ts +29 -1
- package/dist/types/agents/functions.d.ts +12 -17
- package/dist/types/agents/invocation_context.d.ts +7 -3
- package/dist/types/agents/llm_agent.d.ts +5 -1
- package/dist/types/agents/loop_agent.d.ts +2 -2
- package/dist/types/agents/processors/content_processor_utils.d.ts +8 -0
- package/dist/types/agents/processors/interactions_request_processor.d.ts +17 -0
- package/dist/types/agents/routed_agent.d.ts +24 -1
- package/dist/types/agents/run_config.d.ts +1 -1
- package/dist/types/apps/app.d.ts +52 -0
- package/dist/types/apps/resumability_config.d.ts +27 -0
- package/dist/types/artifacts/base_artifact_service.d.ts +6 -36
- package/dist/types/artifacts/gcs_artifact_service.d.ts +2 -1
- package/dist/types/artifacts/scoped_artifact_service.d.ts +25 -0
- package/dist/types/artifacts/session_artifact_service.d.ts +25 -0
- package/dist/types/auth/oauth2/oauth2_discovery.d.ts +11 -0
- package/dist/types/common.d.ts +29 -5
- package/dist/types/context/agent_controlled_context_compactor.d.ts +24 -0
- package/dist/types/context/anchored_context_compactor.d.ts +35 -0
- package/dist/types/context/base_context_compactor.d.ts +3 -0
- package/dist/types/context/compaction_utils.d.ts +15 -0
- package/dist/types/context/token_based_context_compactor.d.ts +6 -1
- package/dist/types/context/trajectory_thought_pruning_compactor.d.ts +27 -0
- package/dist/types/events/compacted_event.d.ts +10 -0
- package/dist/types/events/event.d.ts +21 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/models/google_llm.d.ts +15 -1
- package/dist/types/models/interactions_utils.d.ts +92 -0
- package/dist/types/models/llm_request.d.ts +4 -0
- package/dist/types/models/llm_response.d.ts +4 -0
- package/dist/types/plugins/base_plugin.d.ts +2 -1
- package/dist/types/plugins/global_instruction_plugin.d.ts +38 -0
- package/dist/types/runner/in_memory_runner.d.ts +7 -1
- package/dist/types/runner/runner.d.ts +44 -10
- package/dist/types/sessions/base_session_service.d.ts +3 -16
- package/dist/types/sessions/session.d.ts +11 -0
- package/dist/types/sessions/vertex_ai_session_service.d.ts +9 -1
- package/dist/types/tools/consolidate_context_tool.d.ts +19 -0
- package/dist/types/tools/enterprise_web_search_tool.d.ts +26 -0
- package/dist/types/tools/example_tool.d.ts +21 -0
- package/dist/types/tools/forwarding_artifact_service.d.ts +3 -2
- package/dist/types/tools/load_web_page.d.ts +33 -0
- package/dist/types/tools/mcp/load_mcp_resource_tool.d.ts +26 -0
- package/dist/types/tools/mcp/mcp_toolset.d.ts +27 -0
- package/dist/types/tools/skill/run_skill_inline_script_tool.d.ts +25 -0
- package/dist/types/tools/skill/skill_toolset.d.ts +9 -0
- package/dist/types/utils/async_hooks_shim.d.ts +10 -0
- package/dist/types/utils/branch_trie.d.ts +14 -0
- package/dist/types/utils/client_labels.d.ts +10 -0
- package/dist/types/utils/env_aware_utils.d.ts +3 -3
- package/dist/types/utils/task.d.ts +24 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/agent_to_a2a.js +18 -2
- package/dist/web/a2a/event_converter_utils.js +8 -4
- package/dist/web/a2a/metadata_converter_utils.js +1 -1
- package/dist/web/agents/active_streaming_tool.js +6 -1
- package/dist/web/agents/base_agent.js +39 -0
- package/dist/web/agents/context.js +1 -11
- package/dist/web/agents/functions.js +43 -32
- package/dist/web/agents/instructions.js +23 -5
- package/dist/web/agents/invocation_context.js +2 -5
- package/dist/web/agents/llm_agent.js +12 -9
- package/dist/web/agents/loop_agent.js +27 -3
- package/dist/web/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/web/agents/processors/content_processor_utils.js +16 -3
- package/dist/web/agents/processors/context_compactor_request_processor.js +4 -2
- package/dist/web/agents/processors/interactions_request_processor.js +52 -0
- package/dist/web/agents/routed_agent.js +31 -0
- package/dist/web/agents/run_config.js +8 -3
- package/dist/web/apps/app.js +49 -0
- package/dist/web/apps/resumability_config.js +31 -0
- package/dist/web/artifacts/file_artifact_service.js +14 -1
- package/dist/web/artifacts/gcs_artifact_service.js +55 -15
- package/dist/web/artifacts/in_memory_artifact_service.js +12 -1
- package/dist/web/artifacts/scoped_artifact_service.js +86 -0
- package/dist/web/artifacts/session_artifact_service.js +7 -0
- package/dist/web/auth/oauth2/oauth2_discovery.js +14 -4
- package/dist/web/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/web/common.js +67 -3
- package/dist/web/context/agent_controlled_context_compactor.js +81 -0
- package/dist/web/context/anchored_context_compactor.js +117 -0
- package/dist/web/context/compaction_utils.js +27 -0
- package/dist/web/context/token_based_context_compactor.js +52 -33
- package/dist/web/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/web/events/compacted_event.js +7 -2
- package/dist/web/events/event.js +44 -0
- package/dist/web/index.js +6 -1
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/web/models/google_llm.js +54 -9
- package/dist/web/models/interactions_utils.js +728 -0
- package/dist/web/plugins/base_plugin.js +1 -0
- package/dist/web/plugins/global_instruction_plugin.js +67 -0
- package/dist/web/runner/in_memory_runner.js +13 -2
- package/dist/web/runner/runner.js +157 -84
- package/dist/web/sessions/base_session_service.js +6 -1
- package/dist/web/sessions/database_session_service.js +24 -7
- package/dist/web/sessions/vertex_ai_session_service.js +17 -3
- package/dist/web/skills/loader.js +2 -2
- package/dist/web/tools/base_toolset.js +1 -1
- package/dist/web/tools/consolidate_context_tool.js +51 -0
- package/dist/web/tools/enterprise_web_search_tool.js +55 -0
- package/dist/web/tools/example_tool.js +42 -0
- package/dist/web/tools/forwarding_artifact_service.js +16 -28
- package/dist/web/tools/load_web_page.js +221 -0
- package/dist/web/tools/mcp/load_mcp_resource_tool.js +107 -0
- package/dist/web/tools/mcp/mcp_toolset.js +63 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -22
- package/dist/web/tools/skill/run_skill_inline_script_tool.js +51 -4
- package/dist/web/tools/skill/skill_toolset.js +4 -2
- package/dist/web/utils/async_hooks_shim.js +24 -0
- package/dist/web/utils/branch_trie.js +13 -0
- package/dist/web/utils/client_labels.js +38 -2
- package/dist/web/utils/env_aware_utils.js +10 -1
- package/dist/web/utils/streaming_utils.js +11 -5
- package/dist/web/utils/task.js +34 -0
- package/dist/web/version.js +1 -1
- package/package.json +2 -2
|
@@ -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
|
|
84
|
+
userBuilder
|
|
69
85
|
})
|
|
70
86
|
);
|
|
71
87
|
app.use(
|
|
72
88
|
"".concat(basePath, "/jsonrpc"),
|
|
73
89
|
jsonRpcHandler({
|
|
74
90
|
requestHandler,
|
|
75
|
-
userBuilder
|
|
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
|
|
80
|
+
function messageToAdkEvent(msg, invocationId, agentName) {
|
|
81
81
|
const parts = toGenAIParts(msg.parts);
|
|
82
|
-
|
|
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
|
|
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 && !
|
|
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.
|
|
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,
|
|
@@ -5,9 +5,14 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
5
5
|
* Copyright 2025 Google LLC
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
|
+
import { Task } from "../utils/task.js";
|
|
8
9
|
class ActiveStreamingTool {
|
|
9
10
|
constructor(params = {}) {
|
|
10
|
-
|
|
11
|
+
if (params.task instanceof Promise) {
|
|
12
|
+
this.task = new Task(() => params.task);
|
|
13
|
+
} else {
|
|
14
|
+
this.task = params.task;
|
|
15
|
+
}
|
|
11
16
|
this.stream = params.stream;
|
|
12
17
|
}
|
|
13
18
|
}
|
|
@@ -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
|
*
|
|
@@ -56,9 +56,6 @@ class Context extends ReadonlyContext {
|
|
|
56
56
|
throw new Error("Artifact service is not initialized.");
|
|
57
57
|
}
|
|
58
58
|
return this.invocationContext.artifactService.loadArtifact({
|
|
59
|
-
appName: this.invocationContext.appName,
|
|
60
|
-
userId: this.invocationContext.userId,
|
|
61
|
-
sessionId: this.invocationContext.session.id,
|
|
62
59
|
filename,
|
|
63
60
|
version
|
|
64
61
|
});
|
|
@@ -75,9 +72,6 @@ class Context extends ReadonlyContext {
|
|
|
75
72
|
throw new Error("Artifact service is not initialized.");
|
|
76
73
|
}
|
|
77
74
|
const version = await this.invocationContext.artifactService.saveArtifact({
|
|
78
|
-
appName: this.invocationContext.appName,
|
|
79
|
-
userId: this.invocationContext.userId,
|
|
80
|
-
sessionId: this.invocationContext.session.id,
|
|
81
75
|
filename,
|
|
82
76
|
artifact
|
|
83
77
|
});
|
|
@@ -110,11 +104,7 @@ class Context extends ReadonlyContext {
|
|
|
110
104
|
if (!this.invocationContext.artifactService) {
|
|
111
105
|
throw new Error("Artifact service is not initialized.");
|
|
112
106
|
}
|
|
113
|
-
return this.invocationContext.artifactService.listArtifactKeys(
|
|
114
|
-
appName: this.invocationContext.session.appName,
|
|
115
|
-
userId: this.invocationContext.session.userId,
|
|
116
|
-
sessionId: this.invocationContext.session.id
|
|
117
|
-
});
|
|
107
|
+
return this.invocationContext.artifactService.listArtifactKeys();
|
|
118
108
|
}
|
|
119
109
|
/**
|
|
120
110
|
* Searches the memory of the current user.
|
|
@@ -7,9 +7,13 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
7
7
|
*/
|
|
8
8
|
import { createUserContent } from "@google/genai";
|
|
9
9
|
import { isEmpty } from "lodash-es";
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
createEvent,
|
|
12
|
+
generateClientFunctionCallId,
|
|
13
|
+
getFunctionCalls,
|
|
14
|
+
getFunctionResponses
|
|
15
|
+
} from "../events/event.js";
|
|
11
16
|
import { mergeEventActions } from "../events/event_actions.js";
|
|
12
|
-
import { randomUUID } from "../utils/env_aware_utils.js";
|
|
13
17
|
import { logger } from "../utils/logger.js";
|
|
14
18
|
import { Context } from "./context.js";
|
|
15
19
|
import {
|
|
@@ -17,7 +21,11 @@ import {
|
|
|
17
21
|
tracer,
|
|
18
22
|
traceToolCall
|
|
19
23
|
} from "../telemetry/tracing.js";
|
|
20
|
-
|
|
24
|
+
import {
|
|
25
|
+
AF_FUNCTION_CALL_ID_PREFIX,
|
|
26
|
+
generateClientFunctionCallId as generateClientFunctionCallId2,
|
|
27
|
+
populateClientFunctionCallId
|
|
28
|
+
} from "../events/event.js";
|
|
21
29
|
const REQUEST_EUC_FUNCTION_CALL_NAME = "adk_request_credential";
|
|
22
30
|
const REQUEST_CONFIRMATION_FUNCTION_CALL_NAME = "adk_request_confirmation";
|
|
23
31
|
const functionsExportedForTestingOnly = {
|
|
@@ -25,32 +33,6 @@ const functionsExportedForTestingOnly = {
|
|
|
25
33
|
generateAuthEvent,
|
|
26
34
|
generateRequestConfirmationEvent
|
|
27
35
|
};
|
|
28
|
-
function generateClientFunctionCallId() {
|
|
29
|
-
return "".concat(AF_FUNCTION_CALL_ID_PREFIX).concat(randomUUID());
|
|
30
|
-
}
|
|
31
|
-
function populateClientFunctionCallId(modelResponseEvent) {
|
|
32
|
-
const functionCalls = getFunctionCalls(modelResponseEvent);
|
|
33
|
-
if (!functionCalls) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
for (const functionCall of functionCalls) {
|
|
37
|
-
if (!functionCall.id) {
|
|
38
|
-
functionCall.id = generateClientFunctionCallId();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function removeClientFunctionCallId(content) {
|
|
43
|
-
if (content && content.parts) {
|
|
44
|
-
for (const part of content.parts) {
|
|
45
|
-
if (part.functionCall && part.functionCall.id && part.functionCall.id.startsWith(AF_FUNCTION_CALL_ID_PREFIX)) {
|
|
46
|
-
part.functionCall.id = void 0;
|
|
47
|
-
}
|
|
48
|
-
if (part.functionResponse && part.functionResponse.id && part.functionResponse.id.startsWith(AF_FUNCTION_CALL_ID_PREFIX)) {
|
|
49
|
-
part.functionResponse.id = void 0;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
36
|
function getLongRunningFunctionCalls(functionCalls, toolsDict) {
|
|
55
37
|
const longRunningToolIds = /* @__PURE__ */ new Set();
|
|
56
38
|
for (const functionCall of functionCalls) {
|
|
@@ -393,17 +375,46 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
|
|
|
393
375
|
timestamp: baseEvent.timestamp
|
|
394
376
|
});
|
|
395
377
|
}
|
|
378
|
+
function findEventByFunctionCallId(events, functionCallId, endIndex = events.length) {
|
|
379
|
+
for (let i = endIndex - 1; i >= 0; i--) {
|
|
380
|
+
const event = events[i];
|
|
381
|
+
const functionCalls = getFunctionCalls(event);
|
|
382
|
+
for (const functionCall of functionCalls) {
|
|
383
|
+
if (functionCall.id === functionCallId) {
|
|
384
|
+
return event;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return void 0;
|
|
389
|
+
}
|
|
390
|
+
function findMatchingFunctionCall(events) {
|
|
391
|
+
if (!events.length) {
|
|
392
|
+
return void 0;
|
|
393
|
+
}
|
|
394
|
+
const lastEvent = events[events.length - 1];
|
|
395
|
+
const functionResponses = getFunctionResponses(lastEvent);
|
|
396
|
+
if (!functionResponses.length || !functionResponses[0].id) {
|
|
397
|
+
return void 0;
|
|
398
|
+
}
|
|
399
|
+
return findEventByFunctionCallId(
|
|
400
|
+
events,
|
|
401
|
+
functionResponses[0].id,
|
|
402
|
+
events.length - 1
|
|
403
|
+
);
|
|
404
|
+
}
|
|
396
405
|
export {
|
|
406
|
+
AF_FUNCTION_CALL_ID_PREFIX,
|
|
397
407
|
REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
|
|
398
408
|
REQUEST_EUC_FUNCTION_CALL_NAME,
|
|
409
|
+
findEventByFunctionCallId,
|
|
410
|
+
findMatchingFunctionCall,
|
|
399
411
|
functionsExportedForTestingOnly,
|
|
400
412
|
generateAuthEvent,
|
|
401
|
-
generateClientFunctionCallId,
|
|
413
|
+
generateClientFunctionCallId2 as generateClientFunctionCallId,
|
|
402
414
|
generateRequestConfirmationEvent,
|
|
403
415
|
getLongRunningFunctionCalls,
|
|
404
416
|
handleFunctionCallList,
|
|
405
417
|
handleFunctionCallsAsync,
|
|
406
418
|
mergeParallelFunctionResponseEvents,
|
|
407
|
-
populateClientFunctionCallId
|
|
408
|
-
removeClientFunctionCallId
|
|
419
|
+
populateClientFunctionCallId
|
|
409
420
|
};
|
|
@@ -15,9 +15,6 @@ async function resolveKey(key, isOptional, rawMatch, readonlyContext) {
|
|
|
15
15
|
throw new Error("Artifact service is not initialized.");
|
|
16
16
|
}
|
|
17
17
|
const artifact = await invocationContext.artifactService.loadArtifact({
|
|
18
|
-
appName: invocationContext.session.appName,
|
|
19
|
-
userId: invocationContext.session.userId,
|
|
20
|
-
sessionId: invocationContext.session.id,
|
|
21
18
|
filename: fileName
|
|
22
19
|
});
|
|
23
20
|
if (!artifact) {
|
|
@@ -26,19 +23,40 @@ async function resolveKey(key, isOptional, rawMatch, readonlyContext) {
|
|
|
26
23
|
}
|
|
27
24
|
throw new Error("Artifact ".concat(fileName, " not found."));
|
|
28
25
|
}
|
|
29
|
-
return
|
|
26
|
+
return formatValue(artifact, true);
|
|
30
27
|
}
|
|
31
28
|
if (!isValidStateName(key)) {
|
|
32
29
|
return rawMatch;
|
|
33
30
|
}
|
|
34
31
|
if (key in invocationContext.session.state) {
|
|
35
|
-
return
|
|
32
|
+
return formatValue(invocationContext.session.state[key], false);
|
|
36
33
|
}
|
|
37
34
|
if (isOptional) {
|
|
38
35
|
return "";
|
|
39
36
|
}
|
|
40
37
|
throw new Error("Context variable not found: `".concat(key, "`."));
|
|
41
38
|
}
|
|
39
|
+
function formatValue(value, isArtifact = false) {
|
|
40
|
+
if (typeof value === "string") {
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
if (typeof value === "object" && value !== null) {
|
|
44
|
+
if (isArtifact && "text" in value && typeof value.text === "string") {
|
|
45
|
+
return value.text;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const json = JSON.stringify(value);
|
|
49
|
+
if (json !== void 0) {
|
|
50
|
+
return json;
|
|
51
|
+
}
|
|
52
|
+
} catch (e) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
"Failed to serialize value for instruction template: ".concat(e instanceof Error ? e.message : String(e))
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return String(value);
|
|
59
|
+
}
|
|
42
60
|
async function injectSessionState(template, readonlyContext) {
|
|
43
61
|
const pattern = /\{+[^{}]*}+/g;
|
|
44
62
|
const matches = Array.from(template.matchAll(pattern));
|
|
@@ -30,11 +30,7 @@ class InvocationContext {
|
|
|
30
30
|
* @param params The parameters for creating an invocation context.
|
|
31
31
|
*/
|
|
32
32
|
constructor(params) {
|
|
33
|
-
|
|
34
|
-
* A container to keep track of different kinds of costs incurred as a part of
|
|
35
|
-
* this invocation.
|
|
36
|
-
*/
|
|
37
|
-
this.invocationCostManager = new InvocationCostManager();
|
|
33
|
+
var _a;
|
|
38
34
|
this.artifactService = params.artifactService;
|
|
39
35
|
this.sessionService = params.sessionService;
|
|
40
36
|
this.memoryService = params.memoryService;
|
|
@@ -49,6 +45,7 @@ class InvocationContext {
|
|
|
49
45
|
this.activeStreamingTools = params.activeStreamingTools;
|
|
50
46
|
this.pluginManager = params.pluginManager;
|
|
51
47
|
this.abortSignal = params.abortSignal;
|
|
48
|
+
this.invocationCostManager = (_a = params.invocationCostManager) != null ? _a : new InvocationCostManager();
|
|
52
49
|
}
|
|
53
50
|
/**
|
|
54
51
|
* The app name of the current session.
|
|
@@ -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";
|
|
@@ -106,6 +106,7 @@ import { CONTENT_REQUEST_PROCESSOR } from "./processors/content_request_processo
|
|
|
106
106
|
import { ContextCompactorRequestProcessor } from "./processors/context_compactor_request_processor.js";
|
|
107
107
|
import { IDENTITY_LLM_REQUEST_PROCESSOR } from "./processors/identity_llm_request_processor.js";
|
|
108
108
|
import { INSTRUCTIONS_LLM_REQUEST_PROCESSOR } from "./processors/instructions_llm_request_processor.js";
|
|
109
|
+
import { INTERACTIONS_REQUEST_PROCESSOR } from "./processors/interactions_request_processor.js";
|
|
109
110
|
import { REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR } from "./processors/request_confirmation_llm_request_processor.js";
|
|
110
111
|
import { TOOL_FILTER_REQUEST_PROCESSOR } from "./processors/tool_filter_request_processor.js";
|
|
111
112
|
import { ReadonlyContext } from "./readonly_context.js";
|
|
@@ -150,6 +151,7 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
150
151
|
INSTRUCTIONS_LLM_REQUEST_PROCESSOR,
|
|
151
152
|
REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR,
|
|
152
153
|
CONTENT_REQUEST_PROCESSOR,
|
|
154
|
+
INTERACTIONS_REQUEST_PROCESSOR,
|
|
153
155
|
CODE_EXECUTION_REQUEST_PROCESSOR,
|
|
154
156
|
TOOL_FILTER_REQUEST_PROCESSOR
|
|
155
157
|
];
|
|
@@ -245,6 +247,7 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
245
247
|
* This method is only for use by Agent Development Kit.
|
|
246
248
|
* @param context The context to retrieve the session state.
|
|
247
249
|
* @returns The resolved globalInstruction field.
|
|
250
|
+
* @deprecated Use GlobalInstructionPlugin instead.
|
|
248
251
|
*/
|
|
249
252
|
async canonicalGlobalInstruction(context2) {
|
|
250
253
|
if (typeof this.globalInstruction === "string") {
|
|
@@ -605,7 +608,7 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
605
608
|
}
|
|
606
609
|
postprocess(invocationContext, llmRequest, llmResponse, modelResponseEvent) {
|
|
607
610
|
return __asyncGenerator(this, null, function* () {
|
|
608
|
-
var _a2, _b2, _c, _d, _e;
|
|
611
|
+
var _a2, _b2, _c, _d, _e, _f;
|
|
609
612
|
for (const processor of this.responseProcessors) {
|
|
610
613
|
try {
|
|
611
614
|
for (var iter = __forAwait(processor.runAsync(
|
|
@@ -629,7 +632,7 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
629
632
|
}
|
|
630
633
|
}
|
|
631
634
|
}
|
|
632
|
-
if (!llmResponse.content && !llmResponse.errorCode && !llmResponse.interrupted) {
|
|
635
|
+
if ((!llmResponse.content || ((_b2 = llmResponse.content.parts) == null ? void 0 : _b2.length) === 0) && !llmResponse.errorCode && !llmResponse.interrupted) {
|
|
633
636
|
return;
|
|
634
637
|
}
|
|
635
638
|
const mergedEvent = createEvent(__spreadValues(__spreadValues({}, modelResponseEvent), llmResponse));
|
|
@@ -650,10 +653,10 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
650
653
|
}
|
|
651
654
|
}
|
|
652
655
|
yield mergedEvent;
|
|
653
|
-
if (!((
|
|
656
|
+
if (!((_c = getFunctionCalls(mergedEvent)) == null ? void 0 : _c.length)) {
|
|
654
657
|
return;
|
|
655
658
|
}
|
|
656
|
-
if ((
|
|
659
|
+
if ((_d = invocationContext.runConfig) == null ? void 0 : _d.pauseOnToolCalls) {
|
|
657
660
|
invocationContext.endInvocation = true;
|
|
658
661
|
return;
|
|
659
662
|
}
|
|
@@ -664,7 +667,7 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
664
667
|
beforeToolCallbacks: this.canonicalBeforeToolCallbacks,
|
|
665
668
|
afterToolCallbacks: this.canonicalAfterToolCallbacks
|
|
666
669
|
}));
|
|
667
|
-
if (!functionResponseEvent || ((
|
|
670
|
+
if (!functionResponseEvent || ((_e = invocationContext.abortSignal) == null ? void 0 : _e.aborted)) {
|
|
668
671
|
return;
|
|
669
672
|
}
|
|
670
673
|
const authEvent = generateAuthEvent(
|
|
@@ -691,7 +694,7 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
691
694
|
try {
|
|
692
695
|
for (var iter2 = __forAwait(nextAgent.runAsync(invocationContext)), more2, temp2, error2; more2 = !(temp2 = yield new __await(iter2.next())).done; more2 = false) {
|
|
693
696
|
const event = temp2.value;
|
|
694
|
-
if ((
|
|
697
|
+
if ((_f = invocationContext.abortSignal) == null ? void 0 : _f.aborted) {
|
|
695
698
|
return;
|
|
696
699
|
}
|
|
697
700
|
yield event;
|
|
@@ -75,10 +75,34 @@ class LoopAgent extends (_b = BaseAgent, _a = LOOP_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
75
75
|
return;
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
|
-
|
|
79
|
-
runLiveImpl(_context) {
|
|
78
|
+
runLiveImpl(context) {
|
|
80
79
|
return __asyncGenerator(this, null, function* () {
|
|
81
|
-
|
|
80
|
+
var _a2, _b2;
|
|
81
|
+
for (let iteration = 0; iteration < this.maxIterations; iteration++) {
|
|
82
|
+
for (const subAgent of this.subAgents) {
|
|
83
|
+
try {
|
|
84
|
+
for (var iter = __forAwait(subAgent.runLive(context)), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
85
|
+
const event = temp.value;
|
|
86
|
+
if ((_a2 = context.abortSignal) == null ? void 0 : _a2.aborted) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
yield event;
|
|
90
|
+
if ((_b2 = event.actions) == null ? void 0 : _b2.escalate) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
} catch (temp) {
|
|
95
|
+
error = [temp];
|
|
96
|
+
} finally {
|
|
97
|
+
try {
|
|
98
|
+
more && (temp = iter.return) && (yield new __await(temp.call(iter)));
|
|
99
|
+
} finally {
|
|
100
|
+
if (error)
|
|
101
|
+
throw error[0];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
82
106
|
});
|
|
83
107
|
}
|
|
84
108
|
}
|
|
@@ -327,9 +327,6 @@ async function postProcessCodeExecutionResult(invocationContext, codeExecutorCon
|
|
|
327
327
|
}
|
|
328
328
|
for (const outputFile of codeExecutionResult.outputFiles) {
|
|
329
329
|
const version = await invocationContext.artifactService.saveArtifact({
|
|
330
|
-
appName: invocationContext.appName || "",
|
|
331
|
-
userId: invocationContext.userId || "",
|
|
332
|
-
sessionId: invocationContext.session.id,
|
|
333
330
|
filename: outputFile.name,
|
|
334
331
|
artifact: {
|
|
335
332
|
inlineData: { data: outputFile.content, mimeType: outputFile.mimeType }
|
|
@@ -34,11 +34,23 @@ import {
|
|
|
34
34
|
getFunctionCalls,
|
|
35
35
|
getFunctionResponses
|
|
36
36
|
} from "../../events/event.js";
|
|
37
|
+
import { isSegmentPrefix } from "../../utils/branch_trie.js";
|
|
37
38
|
import {
|
|
38
|
-
|
|
39
|
+
AF_FUNCTION_CALL_ID_PREFIX,
|
|
39
40
|
REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
|
|
40
41
|
REQUEST_EUC_FUNCTION_CALL_NAME
|
|
41
42
|
} from "../functions.js";
|
|
43
|
+
function removeClientFunctionCallId(content) {
|
|
44
|
+
var _a, _b, _c, _d, _e;
|
|
45
|
+
for (const part of (_a = content == null ? void 0 : content.parts) != null ? _a : []) {
|
|
46
|
+
if ((_c = (_b = part.functionCall) == null ? void 0 : _b.id) == null ? void 0 : _c.startsWith(AF_FUNCTION_CALL_ID_PREFIX)) {
|
|
47
|
+
part.functionCall.id = void 0;
|
|
48
|
+
}
|
|
49
|
+
if ((_e = (_d = part.functionResponse) == null ? void 0 : _d.id) == null ? void 0 : _e.startsWith(AF_FUNCTION_CALL_ID_PREFIX)) {
|
|
50
|
+
part.functionResponse.id = void 0;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
42
54
|
function getContents(events, agentName, currentBranch) {
|
|
43
55
|
var _a, _b, _c;
|
|
44
56
|
const filteredEvents = [];
|
|
@@ -50,7 +62,7 @@ function getContents(events, agentName, currentBranch) {
|
|
|
50
62
|
if (!((_a = event.content) == null ? void 0 : _a.role) || ((_c = (_b = event.content.parts) == null ? void 0 : _b[0]) == null ? void 0 : _c.text) === "") {
|
|
51
63
|
continue;
|
|
52
64
|
}
|
|
53
|
-
if (currentBranch && event.branch && !currentBranch
|
|
65
|
+
if (currentBranch && event.branch && !isSegmentPrefix(currentBranch, event.branch)) {
|
|
54
66
|
continue;
|
|
55
67
|
}
|
|
56
68
|
if (isAuthEvent(event)) {
|
|
@@ -344,5 +356,6 @@ function convertCompactedEvent(event) {
|
|
|
344
356
|
export {
|
|
345
357
|
getContents,
|
|
346
358
|
getCurrentTurnContents,
|
|
347
|
-
mergeFunctionResponseEvents
|
|
359
|
+
mergeFunctionResponseEvents,
|
|
360
|
+
removeClientFunctionCallId
|
|
348
361
|
};
|
|
@@ -40,20 +40,22 @@ class ContextCompactorRequestProcessor {
|
|
|
40
40
|
*/
|
|
41
41
|
runAsync(invocationContext, _llmRequest) {
|
|
42
42
|
return __asyncGenerator(this, null, function* () {
|
|
43
|
+
var _a;
|
|
43
44
|
for (const compactor of this.compactors) {
|
|
44
45
|
const shouldCompact = yield new __await(Promise.resolve(
|
|
45
46
|
compactor.shouldCompact(invocationContext)
|
|
46
47
|
));
|
|
47
48
|
if (shouldCompact) {
|
|
49
|
+
const trigger = (_a = compactor.trigger) != null ? _a : ContextCompactionTrigger.Auto;
|
|
48
50
|
yield new __await(invocationContext.pluginManager.runBeforeContextCompaction({
|
|
49
51
|
invocationContext,
|
|
50
|
-
trigger
|
|
52
|
+
trigger
|
|
51
53
|
}));
|
|
52
54
|
const oldEvents = new Set(invocationContext.session.events);
|
|
53
55
|
yield new __await(Promise.resolve(compactor.compact(invocationContext)));
|
|
54
56
|
yield new __await(invocationContext.pluginManager.runAfterContextCompaction({
|
|
55
57
|
invocationContext,
|
|
56
|
-
trigger
|
|
58
|
+
trigger
|
|
57
59
|
}));
|
|
58
60
|
const newEvents = invocationContext.session.events.filter(
|
|
59
61
|
(e) => !oldEvents.has(e)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
4
|
+
var __await = function(promise, isYieldStar) {
|
|
5
|
+
this[0] = promise;
|
|
6
|
+
this[1] = isYieldStar;
|
|
7
|
+
};
|
|
8
|
+
var __asyncGenerator = (__this, __arguments, generator) => {
|
|
9
|
+
var resume = (k, v, yes, no) => {
|
|
10
|
+
try {
|
|
11
|
+
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
12
|
+
Promise.resolve(isAwait ? v[0] : v).then((y) => isAwait ? resume(k === "return" ? k : "next", v[1] ? { done: y.done, value: y.value } : y, yes, no) : yes({ value: y, done })).catch((e) => resume("throw", e, yes, no));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
no(e);
|
|
15
|
+
}
|
|
16
|
+
}, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
|
|
17
|
+
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* @license
|
|
21
|
+
* Copyright 2026 Google LLC
|
|
22
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
23
|
+
*/
|
|
24
|
+
import { isGemini } from "../../models/google_llm.js";
|
|
25
|
+
import { isLlmAgent } from "../llm_agent.js";
|
|
26
|
+
class InteractionsRequestProcessor {
|
|
27
|
+
// eslint-disable-next-line require-yield
|
|
28
|
+
runAsync(invocationContext, llmRequest) {
|
|
29
|
+
return __asyncGenerator(this, null, function* () {
|
|
30
|
+
const agent = invocationContext.agent;
|
|
31
|
+
if (!agent || !isLlmAgent(agent)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const model = agent.canonicalModel;
|
|
35
|
+
if (isGemini(model) && model.useInteractionsApi) {
|
|
36
|
+
const events = invocationContext.session.events;
|
|
37
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
38
|
+
const event = events[i];
|
|
39
|
+
if (event.branch === invocationContext.branch && event.author === agent.name && event.interactionId) {
|
|
40
|
+
llmRequest.previousInteractionId = event.interactionId;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const INTERACTIONS_REQUEST_PROCESSOR = new InteractionsRequestProcessor();
|
|
49
|
+
export {
|
|
50
|
+
INTERACTIONS_REQUEST_PROCESSOR,
|
|
51
|
+
InteractionsRequestProcessor
|
|
52
|
+
};
|