@google/adk 1.4.0 → 1.6.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/a2a_remote_agent.js +12 -2
- package/dist/cjs/a2a/agent_to_a2a.js +18 -3
- package/dist/cjs/a2a/auth.js +65 -0
- package/dist/cjs/a2a/event_converter_utils.js +47 -18
- package/dist/cjs/a2a/metadata_converter_utils.js +1 -1
- package/dist/cjs/agents/base_agent.js +39 -0
- package/dist/cjs/agents/functions.js +26 -28
- package/dist/cjs/agents/llm_agent.js +4 -2
- package/dist/cjs/agents/loop_agent.js +15 -3
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +3 -2
- package/dist/cjs/agents/processors/content_processor_utils.js +2 -1
- package/dist/cjs/agents/processors/content_request_processor.js +2 -21
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +3 -1
- package/dist/cjs/agents/routed_agent.js +31 -0
- package/dist/cjs/agents/run_config.js +3 -2
- package/dist/cjs/artifacts/in_memory_artifact_service.js +17 -9
- package/dist/cjs/auth/credential_service/in_memory_credential_service.js +14 -3
- package/dist/cjs/code_executors/unsafe_local_code_executor.js +23 -12
- package/dist/cjs/common.js +35 -0
- package/dist/cjs/context/agent_controlled_context_compactor.js +2 -11
- package/dist/cjs/context/anchored_context_compactor.js +127 -0
- package/dist/cjs/context/compaction_utils.js +64 -0
- package/dist/cjs/context/token_based_context_compactor.js +13 -44
- package/dist/cjs/events/compacted_event.js +9 -3
- package/dist/cjs/events/event.js +28 -0
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/cjs/memory/in_memory_memory_service.js +13 -2
- package/dist/cjs/memory/vertex_ai_memory_bank_service.js +3 -0
- package/dist/cjs/plugins/base_plugin.js +4 -2
- package/dist/cjs/plugins/global_instruction_plugin.js +97 -0
- package/dist/cjs/runner/runner.js +69 -23
- package/dist/cjs/sessions/base_session_service.js +8 -3
- package/dist/cjs/sessions/in_memory_session_service.js +8 -8
- package/dist/cjs/sessions/vertex_ai_session_service.js +22 -10
- package/dist/cjs/skills/loader.js +40 -6
- package/dist/cjs/tools/enterprise_web_search_tool.js +81 -0
- package/dist/cjs/tools/example_tool.js +68 -0
- package/dist/cjs/tools/get_user_choice_tool.js +53 -0
- 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_session_manager.js +35 -21
- package/dist/cjs/tools/mcp/mcp_toolset.js +63 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
- package/dist/cjs/tools/request_input_tool.js +54 -0
- 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/branch_trie.js +41 -0
- package/dist/cjs/utils/crypto_shim.js +43 -0
- package/dist/cjs/utils/env_aware_utils.js +15 -13
- package/dist/cjs/utils/error_utils.js +120 -0
- package/dist/cjs/utils/file_utils.js +5 -2
- package/dist/cjs/utils/output_schema_utils.js +43 -0
- package/dist/cjs/utils/streaming_utils.js +5 -5
- package/dist/cjs/utils/vertex_ai_utils.js +3 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_remote_agent.js +12 -2
- package/dist/esm/a2a/agent_to_a2a.js +18 -3
- package/dist/esm/a2a/auth.js +37 -0
- package/dist/esm/a2a/event_converter_utils.js +47 -18
- package/dist/esm/a2a/metadata_converter_utils.js +1 -1
- package/dist/esm/agents/base_agent.js +39 -0
- package/dist/esm/agents/functions.js +27 -24
- package/dist/esm/agents/llm_agent.js +6 -4
- package/dist/esm/agents/loop_agent.js +15 -3
- package/dist/esm/agents/processors/basic_llm_request_processor.js +3 -2
- package/dist/esm/agents/processors/content_processor_utils.js +2 -1
- package/dist/esm/agents/processors/content_request_processor.js +2 -21
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +3 -1
- package/dist/esm/agents/routed_agent.js +31 -0
- package/dist/esm/agents/run_config.js +3 -2
- package/dist/esm/artifacts/in_memory_artifact_service.js +17 -9
- package/dist/esm/auth/credential_service/in_memory_credential_service.js +14 -3
- package/dist/esm/code_executors/unsafe_local_code_executor.js +22 -11
- package/dist/esm/common.js +29 -1
- package/dist/esm/context/agent_controlled_context_compactor.js +2 -11
- package/dist/esm/context/anchored_context_compactor.js +99 -0
- package/dist/esm/context/compaction_utils.js +38 -0
- package/dist/esm/context/token_based_context_compactor.js +16 -44
- package/dist/esm/events/compacted_event.js +7 -2
- package/dist/esm/events/event.js +24 -0
- package/dist/esm/index.js +8 -1
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/esm/memory/in_memory_memory_service.js +13 -2
- package/dist/esm/memory/vertex_ai_memory_bank_service.js +7 -1
- package/dist/esm/plugins/base_plugin.js +4 -2
- package/dist/esm/plugins/global_instruction_plugin.js +69 -0
- package/dist/esm/runner/runner.js +69 -23
- package/dist/esm/sessions/base_session_service.js +8 -3
- package/dist/esm/sessions/in_memory_session_service.js +8 -8
- package/dist/esm/sessions/vertex_ai_session_service.js +26 -11
- package/dist/esm/skills/loader.js +40 -6
- package/dist/esm/tools/enterprise_web_search_tool.js +55 -0
- package/dist/esm/tools/example_tool.js +42 -0
- package/dist/esm/tools/get_user_choice_tool.js +25 -0
- 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_session_manager.js +35 -21
- package/dist/esm/tools/mcp/mcp_toolset.js +63 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
- package/dist/esm/tools/request_input_tool.js +26 -0
- 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/branch_trie.js +13 -0
- package/dist/esm/utils/crypto_shim.js +15 -0
- package/dist/esm/utils/env_aware_utils.js +15 -13
- package/dist/esm/utils/error_utils.js +92 -0
- package/dist/esm/utils/file_utils.js +5 -2
- package/dist/esm/utils/output_schema_utils.js +15 -0
- package/dist/esm/utils/streaming_utils.js +1 -1
- package/dist/esm/utils/vertex_ai_utils.js +2 -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/a2a/auth.d.ts +30 -0
- package/dist/types/a2a/event_converter_utils.d.ts +4 -1
- package/dist/types/agents/base_agent.d.ts +29 -1
- package/dist/types/agents/functions.d.ts +1 -9
- package/dist/types/agents/llm_agent.d.ts +5 -1
- package/dist/types/agents/loop_agent.d.ts +2 -2
- package/dist/types/agents/routed_agent.d.ts +24 -1
- package/dist/types/agents/run_config.d.ts +1 -1
- package/dist/types/auth/credential_service/in_memory_credential_service.d.ts +11 -0
- package/dist/types/code_executors/unsafe_local_code_executor.d.ts +5 -1
- package/dist/types/common.d.ts +11 -2
- package/dist/types/context/agent_controlled_context_compactor.d.ts +0 -1
- package/dist/types/context/anchored_context_compactor.d.ts +35 -0
- package/dist/types/context/compaction_utils.d.ts +23 -0
- package/dist/types/context/token_based_context_compactor.d.ts +0 -1
- package/dist/types/events/compacted_event.d.ts +10 -0
- package/dist/types/events/event.d.ts +13 -0
- package/dist/types/index.d.ts +5 -3
- package/dist/types/memory/in_memory_memory_service.d.ts +11 -0
- package/dist/types/plugins/base_plugin.d.ts +4 -2
- package/dist/types/plugins/global_instruction_plugin.d.ts +38 -0
- package/dist/types/runner/runner.d.ts +1 -1
- package/dist/types/sessions/base_session_service.d.ts +8 -0
- package/dist/types/sessions/in_memory_session_service.d.ts +9 -0
- package/dist/types/sessions/vertex_ai_session_service.d.ts +19 -1
- package/dist/types/skills/loader.d.ts +5 -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/get_user_choice_tool.d.ts +14 -0
- 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/request_input_tool.d.ts +15 -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/branch_trie.d.ts +14 -0
- package/dist/types/utils/crypto_shim.d.ts +16 -0
- package/dist/types/utils/env_aware_utils.d.ts +23 -0
- package/dist/types/utils/error_utils.d.ts +18 -0
- package/dist/types/utils/output_schema_utils.d.ts +18 -0
- package/dist/types/utils/vertex_ai_utils.d.ts +1 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/a2a_remote_agent.js +12 -2
- package/dist/web/a2a/agent_to_a2a.js +18 -3
- package/dist/web/a2a/auth.js +37 -0
- package/dist/web/a2a/event_converter_utils.js +47 -18
- package/dist/web/a2a/metadata_converter_utils.js +1 -1
- package/dist/web/agents/base_agent.js +39 -0
- package/dist/web/agents/functions.js +27 -24
- package/dist/web/agents/llm_agent.js +6 -4
- package/dist/web/agents/loop_agent.js +27 -3
- package/dist/web/agents/processors/basic_llm_request_processor.js +3 -2
- package/dist/web/agents/processors/content_processor_utils.js +2 -1
- package/dist/web/agents/processors/content_request_processor.js +2 -21
- package/dist/web/agents/processors/instructions_llm_request_processor.js +3 -1
- package/dist/web/agents/routed_agent.js +31 -0
- package/dist/web/agents/run_config.js +8 -3
- package/dist/web/artifacts/in_memory_artifact_service.js +17 -9
- package/dist/web/auth/credential_service/in_memory_credential_service.js +14 -3
- package/dist/web/code_executors/unsafe_local_code_executor.js +22 -11
- package/dist/web/common.js +29 -1
- package/dist/web/context/agent_controlled_context_compactor.js +2 -11
- package/dist/web/context/anchored_context_compactor.js +117 -0
- package/dist/web/context/compaction_utils.js +38 -0
- package/dist/web/context/token_based_context_compactor.js +16 -44
- package/dist/web/events/compacted_event.js +7 -2
- package/dist/web/events/event.js +24 -0
- package/dist/web/index.js +8 -1
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/web/memory/in_memory_memory_service.js +13 -2
- package/dist/web/memory/vertex_ai_memory_bank_service.js +7 -1
- package/dist/web/plugins/base_plugin.js +4 -2
- package/dist/web/plugins/global_instruction_plugin.js +67 -0
- package/dist/web/runner/runner.js +65 -22
- package/dist/web/sessions/base_session_service.js +8 -3
- package/dist/web/sessions/in_memory_session_service.js +8 -8
- package/dist/web/sessions/vertex_ai_session_service.js +24 -11
- package/dist/web/skills/loader.js +40 -6
- package/dist/web/tools/enterprise_web_search_tool.js +55 -0
- package/dist/web/tools/example_tool.js +42 -0
- package/dist/web/tools/get_user_choice_tool.js +25 -0
- 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_session_manager.js +35 -21
- package/dist/web/tools/mcp/mcp_toolset.js +63 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
- package/dist/web/tools/request_input_tool.js +26 -0
- 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/branch_trie.js +13 -0
- package/dist/web/utils/crypto_shim.js +15 -0
- package/dist/web/utils/env_aware_utils.js +15 -13
- package/dist/web/utils/error_utils.js +92 -0
- package/dist/web/utils/file_utils.js +5 -2
- package/dist/web/utils/output_schema_utils.js +15 -0
- package/dist/web/utils/streaming_utils.js +1 -1
- package/dist/web/utils/vertex_ai_utils.js +2 -0
- package/dist/web/version.js +1 -1
- package/package.json +1 -1
|
@@ -62,32 +62,34 @@ function toA2AMessage(event, {
|
|
|
62
62
|
metadata: getA2AEventMetadata(event, { appName, userId, sessionId })
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
-
function toAdkEvent(event, invocationId, agentName) {
|
|
65
|
+
function toAdkEvent(event, invocationId, agentName, branch) {
|
|
66
66
|
if (isMessage(event)) {
|
|
67
|
-
return messageToAdkEvent(event, invocationId, agentName);
|
|
67
|
+
return messageToAdkEvent(event, invocationId, agentName, branch);
|
|
68
68
|
}
|
|
69
69
|
if (isTask(event)) {
|
|
70
|
-
return taskToAdkEvent(event, invocationId, agentName);
|
|
70
|
+
return taskToAdkEvent(event, invocationId, agentName, branch);
|
|
71
71
|
}
|
|
72
72
|
if (isTaskArtifactUpdateEvent(event)) {
|
|
73
|
-
return artifactUpdateToAdkEvent(event, invocationId, agentName);
|
|
73
|
+
return artifactUpdateToAdkEvent(event, invocationId, agentName, branch);
|
|
74
74
|
}
|
|
75
75
|
if (isTaskStatusUpdateEvent(event)) {
|
|
76
|
-
return event.final ? finalTaskStatusUpdateToAdkEvent(event, invocationId, agentName) : taskStatusUpdateToAdkEvent(event, invocationId, agentName);
|
|
76
|
+
return event.final ? finalTaskStatusUpdateToAdkEvent(event, invocationId, agentName, branch) : taskStatusUpdateToAdkEvent(event, invocationId, agentName, branch);
|
|
77
77
|
}
|
|
78
78
|
return void 0;
|
|
79
79
|
}
|
|
80
|
-
function messageToAdkEvent(msg, invocationId, agentName,
|
|
80
|
+
function messageToAdkEvent(msg, invocationId, agentName, branch) {
|
|
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
|
-
|
|
86
|
+
branch,
|
|
87
|
+
content,
|
|
86
88
|
turnComplete: true,
|
|
87
89
|
partial: false
|
|
88
90
|
});
|
|
89
91
|
}
|
|
90
|
-
function artifactUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
|
|
92
|
+
function artifactUpdateToAdkEvent(a2aEvent, invocationId, agentName, branch) {
|
|
91
93
|
var _a;
|
|
92
94
|
const partsToConvert = ((_a = a2aEvent.artifact) == null ? void 0 : _a.parts) || [];
|
|
93
95
|
if (partsToConvert.length === 0) {
|
|
@@ -97,12 +99,13 @@ function artifactUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
|
|
|
97
99
|
return __spreadProps(__spreadValues({}, createAdkEventFromMetadata(a2aEvent)), {
|
|
98
100
|
invocationId,
|
|
99
101
|
author: agentName,
|
|
102
|
+
branch,
|
|
100
103
|
content: createModelContent(toGenAIParts(partsToConvert)),
|
|
101
104
|
longRunningToolIds: getLongRunningToolIDs(partsToConvert),
|
|
102
105
|
partial
|
|
103
106
|
});
|
|
104
107
|
}
|
|
105
|
-
function finalTaskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
|
|
108
|
+
function finalTaskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName, branch) {
|
|
106
109
|
var _a;
|
|
107
110
|
const partsToConvert = ((_a = a2aEvent.status.message) == null ? void 0 : _a.parts) || [];
|
|
108
111
|
if (partsToConvert.length === 0) {
|
|
@@ -114,27 +117,32 @@ function finalTaskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
|
|
|
114
117
|
return __spreadProps(__spreadValues({}, createAdkEventFromMetadata(a2aEvent)), {
|
|
115
118
|
invocationId,
|
|
116
119
|
author: agentName,
|
|
120
|
+
branch,
|
|
117
121
|
errorMessage: isFailedTask ? getFailedTaskStatusUpdateEventError(a2aEvent) : void 0,
|
|
118
122
|
content: hasContent ? createModelContent(parts) : void 0,
|
|
119
123
|
longRunningToolIds: getLongRunningToolIDs(partsToConvert),
|
|
120
124
|
turnComplete: true
|
|
121
125
|
});
|
|
122
126
|
}
|
|
123
|
-
function taskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
|
|
127
|
+
function taskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName, branch) {
|
|
124
128
|
const msg = a2aEvent.status.message;
|
|
125
129
|
if (!msg) {
|
|
126
130
|
return void 0;
|
|
127
131
|
}
|
|
128
132
|
const parts = toGenAIParts(msg.parts);
|
|
133
|
+
if (parts.length === 0) {
|
|
134
|
+
return void 0;
|
|
135
|
+
}
|
|
129
136
|
return __spreadProps(__spreadValues({}, createAdkEventFromMetadata(a2aEvent)), {
|
|
130
137
|
invocationId,
|
|
131
138
|
author: agentName,
|
|
139
|
+
branch,
|
|
132
140
|
content: createModelContent(parts),
|
|
133
141
|
turnComplete: false,
|
|
134
142
|
partial: true
|
|
135
143
|
});
|
|
136
144
|
}
|
|
137
|
-
function taskToAdkEvent(a2aTask, invocationId, agentName) {
|
|
145
|
+
function taskToAdkEvent(a2aTask, invocationId, agentName, branch) {
|
|
138
146
|
var _a, _b;
|
|
139
147
|
const parts = [];
|
|
140
148
|
const longRunningToolIds = [];
|
|
@@ -155,22 +163,32 @@ function taskToAdkEvent(a2aTask, invocationId, agentName) {
|
|
|
155
163
|
}
|
|
156
164
|
const isTerminal = isTerminalTaskStatusUpdateEvent(a2aTask) || isInputRequiredTaskStatusUpdateEvent(a2aTask);
|
|
157
165
|
const isFailed = isFailedTaskStatusUpdateEvent(a2aTask);
|
|
158
|
-
if (parts.length === 0 && !
|
|
166
|
+
if (parts.length === 0 && !isFailed) {
|
|
159
167
|
return void 0;
|
|
160
168
|
}
|
|
161
169
|
return __spreadProps(__spreadValues({}, createAdkEventFromMetadata(a2aTask)), {
|
|
162
170
|
invocationId,
|
|
163
171
|
author: agentName,
|
|
172
|
+
branch,
|
|
164
173
|
content: isFailed ? void 0 : createModelContent(parts),
|
|
165
174
|
errorMessage: isFailed ? getFailedTaskStatusUpdateEventError(a2aTask) : void 0,
|
|
166
175
|
longRunningToolIds,
|
|
167
176
|
turnComplete: isTerminal
|
|
168
177
|
});
|
|
169
178
|
}
|
|
179
|
+
const PEER_SETTABLE_ACTION_FIELDS = /* @__PURE__ */ new Set(["escalate"]);
|
|
170
180
|
function createAdkEventFromMetadata(a2aEvent) {
|
|
171
181
|
const metadata = a2aEvent.metadata || {};
|
|
172
182
|
return createEvent({
|
|
173
|
-
branch
|
|
183
|
+
// `branch` is intentionally NOT restored from peer metadata here (unlike
|
|
184
|
+
// the other fields below): it is the mechanism getContents() (see
|
|
185
|
+
// content_processor_utils.ts) uses to keep sibling sub-agent branches'
|
|
186
|
+
// conversation contexts isolated from each other. A remote A2A peer that
|
|
187
|
+
// controls its own outgoing metadata could otherwise forge `adk_branch`
|
|
188
|
+
// (set it to a shared ancestor branch, or omit it) to leak its content
|
|
189
|
+
// into an unrelated sibling agent's LLM context. Every caller of the
|
|
190
|
+
// `*ToAdkEvent` functions in this file force-sets `branch` from its own
|
|
191
|
+
// local `InvocationContext` instead, the same way `author` is handled.
|
|
174
192
|
author: metadata[A2AMetadataKeys.AUTHOR],
|
|
175
193
|
partial: metadata[A2AMetadataKeys.PARTIAL],
|
|
176
194
|
errorCode: metadata[A2AMetadataKeys.ERROR_CODE],
|
|
@@ -179,10 +197,21 @@ function createAdkEventFromMetadata(a2aEvent) {
|
|
|
179
197
|
groundingMetadata: metadata[A2AMetadataKeys.GROUNDING_METADATA],
|
|
180
198
|
usageMetadata: metadata[A2AMetadataKeys.USAGE_METADATA],
|
|
181
199
|
customMetadata: metadata[A2AMetadataKeys.CUSTOM_METADATA],
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
200
|
+
// Only fields in PEER_SETTABLE_ACTION_FIELDS may be restored from
|
|
201
|
+
// metadata a remote A2A peer controls. Every other action field either
|
|
202
|
+
// mutates the caller's own session or drives the caller's own control
|
|
203
|
+
// flow (e.g. `transferToAgent`, see llm_agent.ts), so it must never be
|
|
204
|
+
// rebuilt from peer-supplied data. Filtering through an allowlist here
|
|
205
|
+
// (rather than just omitting the unsafe field) means a future action
|
|
206
|
+
// field is unsafe-by-default: adding it to `candidateActions` alone
|
|
207
|
+
// does nothing until it's also added to the allowlist.
|
|
208
|
+
actions: createEventActions(
|
|
209
|
+
Object.fromEntries(
|
|
210
|
+
Object.entries({
|
|
211
|
+
escalate: !!metadata[A2AMetadataKeys.ESCALATE]
|
|
212
|
+
}).filter(([key]) => PEER_SETTABLE_ACTION_FIELDS.has(key))
|
|
213
|
+
)
|
|
214
|
+
)
|
|
186
215
|
});
|
|
187
216
|
}
|
|
188
217
|
function getLongRunningToolIDs(parts) {
|
|
@@ -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,
|
|
@@ -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
|
-
|
|
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) {
|
|
@@ -195,6 +185,18 @@ async function handleFunctionCallsAsync({
|
|
|
195
185
|
toolConfirmationDict
|
|
196
186
|
});
|
|
197
187
|
}
|
|
188
|
+
function normalizeCallbackResponse(response) {
|
|
189
|
+
if (response == null) {
|
|
190
|
+
return void 0;
|
|
191
|
+
}
|
|
192
|
+
if (typeof response !== "object") {
|
|
193
|
+
return { result: response };
|
|
194
|
+
}
|
|
195
|
+
if (Array.isArray(response)) {
|
|
196
|
+
return { results: response };
|
|
197
|
+
}
|
|
198
|
+
return response;
|
|
199
|
+
}
|
|
198
200
|
async function handleFunctionCallList({
|
|
199
201
|
invocationContext,
|
|
200
202
|
functionCalls,
|
|
@@ -241,6 +243,7 @@ async function handleFunctionCallList({
|
|
|
241
243
|
}
|
|
242
244
|
}
|
|
243
245
|
}
|
|
246
|
+
functionResponse = normalizeCallbackResponse(functionResponse);
|
|
244
247
|
if (functionResponse == null) {
|
|
245
248
|
try {
|
|
246
249
|
functionResponse = await callToolAsync(tool, functionArgs, toolContext);
|
|
@@ -252,8 +255,8 @@ async function handleFunctionCallList({
|
|
|
252
255
|
toolContext,
|
|
253
256
|
error: e
|
|
254
257
|
});
|
|
255
|
-
if (onToolErrorResponse) {
|
|
256
|
-
functionResponse = onToolErrorResponse;
|
|
258
|
+
if (onToolErrorResponse != null) {
|
|
259
|
+
functionResponse = normalizeCallbackResponse(onToolErrorResponse);
|
|
257
260
|
} else {
|
|
258
261
|
functionResponseError = e.message;
|
|
259
262
|
}
|
|
@@ -282,17 +285,17 @@ async function handleFunctionCallList({
|
|
|
282
285
|
}
|
|
283
286
|
}
|
|
284
287
|
if (alteredFunctionResponse != null) {
|
|
285
|
-
functionResponse = alteredFunctionResponse;
|
|
288
|
+
functionResponse = normalizeCallbackResponse(alteredFunctionResponse);
|
|
286
289
|
}
|
|
287
|
-
if (tool.isLongRunning &&
|
|
290
|
+
if (tool.isLongRunning && functionResponse == null) {
|
|
288
291
|
continue;
|
|
289
292
|
}
|
|
290
293
|
if (functionResponseError) {
|
|
291
294
|
functionResponse = { error: functionResponseError };
|
|
292
|
-
} else if (
|
|
295
|
+
} else if (functionResponse == null) {
|
|
293
296
|
functionResponse = { result: functionResponse };
|
|
294
|
-
} else
|
|
295
|
-
functionResponse =
|
|
297
|
+
} else {
|
|
298
|
+
functionResponse = normalizeCallbackResponse(functionResponse);
|
|
296
299
|
}
|
|
297
300
|
const functionResponseEvent = createEvent({
|
|
298
301
|
invocationId: invocationContext.invocationId,
|
|
@@ -420,7 +423,7 @@ export {
|
|
|
420
423
|
findMatchingFunctionCall,
|
|
421
424
|
functionsExportedForTestingOnly,
|
|
422
425
|
generateAuthEvent,
|
|
423
|
-
generateClientFunctionCallId,
|
|
426
|
+
generateClientFunctionCallId2 as generateClientFunctionCallId,
|
|
424
427
|
generateRequestConfirmationEvent,
|
|
425
428
|
getLongRunningFunctionCalls,
|
|
426
429
|
handleFunctionCallList,
|
|
@@ -77,12 +77,14 @@ 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";
|
|
84
85
|
import { isBaseTool } from "../tools/base_tool.js";
|
|
85
86
|
import { logger } from "../utils/logger.js";
|
|
87
|
+
import { canUseOutputSchemaWithTools } from "../utils/output_schema_utils.js";
|
|
86
88
|
import { Context } from "./context.js";
|
|
87
89
|
import {
|
|
88
90
|
runAsyncGeneratorWithOtelContext,
|
|
@@ -95,8 +97,7 @@ import {
|
|
|
95
97
|
generateAuthEvent,
|
|
96
98
|
generateRequestConfirmationEvent,
|
|
97
99
|
getLongRunningFunctionCalls,
|
|
98
|
-
handleFunctionCallsAsync
|
|
99
|
-
populateClientFunctionCallId
|
|
100
|
+
handleFunctionCallsAsync
|
|
100
101
|
} from "./functions.js";
|
|
101
102
|
import { AUTH_PREPROCESSOR } from "../auth/auth_preprocessor.js";
|
|
102
103
|
import { AGENT_TRANSFER_LLM_REQUEST_PROCESSOR } from "./processors/agent_transfer_llm_request_processor.js";
|
|
@@ -247,6 +248,7 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
247
248
|
* This method is only for use by Agent Development Kit.
|
|
248
249
|
* @param context The context to retrieve the session state.
|
|
249
250
|
* @returns The resolved globalInstruction field.
|
|
251
|
+
* @deprecated Use GlobalInstructionPlugin instead.
|
|
250
252
|
*/
|
|
251
253
|
async canonicalGlobalInstruction(context2) {
|
|
252
254
|
if (typeof this.globalInstruction === "string") {
|
|
@@ -498,7 +500,7 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
498
500
|
}
|
|
499
501
|
}
|
|
500
502
|
const allTools = [...this.tools];
|
|
501
|
-
if (this.outputSchema && allTools.length > 0) {
|
|
503
|
+
if (this.outputSchema && allTools.length > 0 && !canUseOutputSchemaWithTools(this.canonicalModel.model)) {
|
|
502
504
|
const setModelResponseTool = new FunctionTool({
|
|
503
505
|
name: "set_model_response",
|
|
504
506
|
description: "Call this tool to submit your final response conforming to the output schema. Use this tool only when you have collected all the information and are ready to return the final answer.",
|
|
@@ -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
|
}
|
|
@@ -38,6 +38,7 @@ var __asyncGenerator = (__this, __arguments, generator) => {
|
|
|
38
38
|
* SPDX-License-Identifier: Apache-2.0
|
|
39
39
|
*/
|
|
40
40
|
import { setOutputSchema } from "../../models/llm_request.js";
|
|
41
|
+
import { canUseOutputSchemaWithTools } from "../../utils/output_schema_utils.js";
|
|
41
42
|
import { isLlmAgent } from "../llm_agent.js";
|
|
42
43
|
import { BaseLlmRequestProcessor } from "./base_llm_processor.js";
|
|
43
44
|
class BasicLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
@@ -51,14 +52,14 @@ class BasicLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
|
51
52
|
// eslint-disable-next-line require-yield
|
|
52
53
|
runAsync(invocationContext, llmRequest) {
|
|
53
54
|
return __asyncGenerator(this, null, function* () {
|
|
54
|
-
var _a;
|
|
55
|
+
var _a, _b;
|
|
55
56
|
const agent = invocationContext.agent;
|
|
56
57
|
if (!isLlmAgent(agent)) {
|
|
57
58
|
return;
|
|
58
59
|
}
|
|
59
60
|
llmRequest.model = agent.canonicalModel.model;
|
|
60
61
|
llmRequest.config = __spreadValues({}, (_a = agent.generateContentConfig) != null ? _a : {});
|
|
61
|
-
if (agent.outputSchema && (!agent.tools || agent.
|
|
62
|
+
if (agent.outputSchema && (!((_b = agent.tools) == null ? void 0 : _b.length) || canUseOutputSchemaWithTools(agent.canonicalModel.model))) {
|
|
62
63
|
setOutputSchema(llmRequest, agent.outputSchema);
|
|
63
64
|
}
|
|
64
65
|
if (invocationContext.runConfig) {
|
|
@@ -34,6 +34,7 @@ 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,
|
|
@@ -61,7 +62,7 @@ function getContents(events, agentName, currentBranch) {
|
|
|
61
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) === "") {
|
|
62
63
|
continue;
|
|
63
64
|
}
|
|
64
|
-
if (currentBranch && event.branch && !currentBranch
|
|
65
|
+
if (currentBranch && event.branch && !isSegmentPrefix(currentBranch, event.branch)) {
|
|
65
66
|
continue;
|
|
66
67
|
}
|
|
67
68
|
if (isAuthEvent(event)) {
|
|
@@ -21,7 +21,7 @@ var __asyncGenerator = (__this, __arguments, generator) => {
|
|
|
21
21
|
* Copyright 2025 Google LLC
|
|
22
22
|
* SPDX-License-Identifier: Apache-2.0
|
|
23
23
|
*/
|
|
24
|
-
import {
|
|
24
|
+
import { getActiveEvents } from "../../context/compaction_utils.js";
|
|
25
25
|
import { isLlmAgent } from "../llm_agent.js";
|
|
26
26
|
import {
|
|
27
27
|
getContents,
|
|
@@ -42,26 +42,7 @@ class ContentRequestProcessor {
|
|
|
42
42
|
if (!agent || !isLlmAgent(agent)) {
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
const compactedEvents = events.filter(isCompactedEvent);
|
|
47
|
-
const latestCompactedEvent = compactedEvents.length > 0 ? compactedEvents.reduce(
|
|
48
|
-
(latest, current) => current.endTime > latest.endTime ? current : latest
|
|
49
|
-
) : void 0;
|
|
50
|
-
if (latestCompactedEvent) {
|
|
51
|
-
const remainingEvents = events.filter((event) => {
|
|
52
|
-
if (event === latestCompactedEvent) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
if (isCompactedEvent(event)) {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
if (event.timestamp <= latestCompactedEvent.endTime) {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
return true;
|
|
62
|
-
});
|
|
63
|
-
events = [latestCompactedEvent, ...remainingEvents];
|
|
64
|
-
}
|
|
45
|
+
const events = getActiveEvents(invocationContext.session.events);
|
|
65
46
|
if (agent.includeContents === "default") {
|
|
66
47
|
llmRequest.contents = getContents(
|
|
67
48
|
events,
|
|
@@ -22,6 +22,7 @@ var __asyncGenerator = (__this, __arguments, generator) => {
|
|
|
22
22
|
* SPDX-License-Identifier: Apache-2.0
|
|
23
23
|
*/
|
|
24
24
|
import { appendInstructions } from "../../models/llm_request.js";
|
|
25
|
+
import { canUseOutputSchemaWithTools } from "../../utils/output_schema_utils.js";
|
|
25
26
|
import { injectSessionState } from "../instructions.js";
|
|
26
27
|
import { isLlmAgent } from "../llm_agent.js";
|
|
27
28
|
import { ReadonlyContext } from "../readonly_context.js";
|
|
@@ -33,6 +34,7 @@ class InstructionsLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
|
33
34
|
// eslint-disable-next-line require-yield
|
|
34
35
|
runAsync(invocationContext, llmRequest) {
|
|
35
36
|
return __asyncGenerator(this, null, function* () {
|
|
37
|
+
var _a;
|
|
36
38
|
const agent = invocationContext.agent;
|
|
37
39
|
if (!isLlmAgent(agent)) {
|
|
38
40
|
return;
|
|
@@ -64,7 +66,7 @@ class InstructionsLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
|
64
66
|
}
|
|
65
67
|
appendInstructions(llmRequest, [instructionWithState]);
|
|
66
68
|
}
|
|
67
|
-
if (agent.outputSchema && agent.tools && agent.
|
|
69
|
+
if (agent.outputSchema && ((_a = agent.tools) == null ? void 0 : _a.length) && !canUseOutputSchemaWithTools(agent.canonicalModel.model)) {
|
|
68
70
|
appendInstructions(llmRequest, [
|
|
69
71
|
'To output the final result, you must call the "set_model_response" function with the appropriate values. Do not output anything else.'
|
|
70
72
|
]);
|
|
@@ -102,6 +102,29 @@ let RoutedAgent = class extends (_b = BaseAgent, _a = ROUTED_AGENT_SIGNATURE_SYM
|
|
|
102
102
|
}
|
|
103
103
|
this.router = config.router;
|
|
104
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Creates a detached copy of this routed agent.
|
|
107
|
+
*
|
|
108
|
+
* The inherited {@link BaseAgent.clone} only deep-clones `subAgents`, but a
|
|
109
|
+
* `RoutedAgent` derives its routing targets from `config.agents`. Rebuilding
|
|
110
|
+
* through the base clone alone would re-read the already-parented original
|
|
111
|
+
* agents and throw "already has a parent agent". This override deep-clones the
|
|
112
|
+
* routing targets (unless the caller overrides `agents`) so the rebuilt
|
|
113
|
+
* constructor re-parents fresh, detached copies. The array-vs-record shape
|
|
114
|
+
* and, for records, the keys are preserved so the router keeps selecting the
|
|
115
|
+
* same targets.
|
|
116
|
+
*
|
|
117
|
+
* @param overrides Config fields to override on the clone. Overriding
|
|
118
|
+
* `parentAgent` is rejected by the base implementation.
|
|
119
|
+
* @returns A new detached `RoutedAgent` of the same concrete class.
|
|
120
|
+
*/
|
|
121
|
+
clone(overrides) {
|
|
122
|
+
const nextOverrides = __spreadValues({}, overrides);
|
|
123
|
+
if (!("agents" in nextOverrides)) {
|
|
124
|
+
nextOverrides.agents = cloneRoutingTargets(this.config.agents);
|
|
125
|
+
}
|
|
126
|
+
return super.clone(nextOverrides);
|
|
127
|
+
}
|
|
105
128
|
/**
|
|
106
129
|
* Runs the selected agent via text-based conversation.
|
|
107
130
|
*/
|
|
@@ -132,6 +155,14 @@ let RoutedAgent = class extends (_b = BaseAgent, _a = ROUTED_AGENT_SIGNATURE_SYM
|
|
|
132
155
|
RoutedAgent = __decorateClass([
|
|
133
156
|
experimental
|
|
134
157
|
], RoutedAgent);
|
|
158
|
+
function cloneRoutingTargets(agents) {
|
|
159
|
+
if (Array.isArray(agents)) {
|
|
160
|
+
return agents.map((agent) => agent.clone());
|
|
161
|
+
}
|
|
162
|
+
return Object.fromEntries(
|
|
163
|
+
Object.entries(agents).map(([key, agent]) => [key, agent.clone()])
|
|
164
|
+
);
|
|
165
|
+
}
|
|
135
166
|
export {
|
|
136
167
|
RoutedAgent,
|
|
137
168
|
isRoutedAgent
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
2
|
const require = topLevelCreateRequire(import.meta.url);
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
6
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -16,6 +18,7 @@ var __spreadValues = (a, b) => {
|
|
|
16
18
|
}
|
|
17
19
|
return a;
|
|
18
20
|
};
|
|
21
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
19
22
|
/**
|
|
20
23
|
* @license
|
|
21
24
|
* Copyright 2025 Google LLC
|
|
@@ -29,14 +32,16 @@ var StreamingMode = /* @__PURE__ */ ((StreamingMode2) => {
|
|
|
29
32
|
return StreamingMode2;
|
|
30
33
|
})(StreamingMode || {});
|
|
31
34
|
function createRunConfig(params = {}) {
|
|
32
|
-
|
|
35
|
+
var _a;
|
|
36
|
+
return __spreadProps(__spreadValues({
|
|
33
37
|
saveInputBlobsAsArtifacts: false,
|
|
34
38
|
supportCfc: false,
|
|
35
39
|
enableAffectiveDialog: false,
|
|
36
40
|
streamingMode: "none" /* NONE */,
|
|
37
|
-
maxLlmCalls: validateMaxLlmCalls(params.maxLlmCalls || 500),
|
|
38
41
|
pauseOnToolCalls: false
|
|
39
|
-
}, params)
|
|
42
|
+
}, params), {
|
|
43
|
+
maxLlmCalls: validateMaxLlmCalls((_a = params.maxLlmCalls) != null ? _a : 500)
|
|
44
|
+
});
|
|
40
45
|
}
|
|
41
46
|
function validateMaxLlmCalls(value) {
|
|
42
47
|
if (value > Number.MAX_SAFE_INTEGER) {
|
|
@@ -5,6 +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
|
+
import { logger } from "../utils/logger.js";
|
|
8
9
|
function isInMemoryConnectionString(uri) {
|
|
9
10
|
return uri === "memory://";
|
|
10
11
|
}
|
|
@@ -56,6 +57,12 @@ class InMemoryArtifactService {
|
|
|
56
57
|
if (version === void 0) {
|
|
57
58
|
version = versions.length - 1;
|
|
58
59
|
}
|
|
60
|
+
if (!versions[version]) {
|
|
61
|
+
logger.warn(
|
|
62
|
+
"[InMemoryArtifactService] loadArtifact: Artifact ".concat(filename, " version ").concat(version, " not found")
|
|
63
|
+
);
|
|
64
|
+
return Promise.resolve(void 0);
|
|
65
|
+
}
|
|
59
66
|
return Promise.resolve(versions[version].part);
|
|
60
67
|
}
|
|
61
68
|
listArtifactKeys({
|
|
@@ -63,16 +70,14 @@ class InMemoryArtifactService {
|
|
|
63
70
|
userId,
|
|
64
71
|
sessionId
|
|
65
72
|
}) {
|
|
66
|
-
const sessionPrefix = ""
|
|
67
|
-
const
|
|
73
|
+
const sessionPrefix = artifactPrefix("session", appName, userId, sessionId);
|
|
74
|
+
const userPrefix = artifactPrefix("user", appName, userId);
|
|
68
75
|
const filenames = [];
|
|
69
76
|
for (const path in this.artifacts) {
|
|
70
77
|
if (path.startsWith(sessionPrefix)) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const filename = path.replace(usernamespacePrefix, "");
|
|
75
|
-
filenames.push(filename);
|
|
78
|
+
filenames.push(decodeURIComponent(path.slice(sessionPrefix.length)));
|
|
79
|
+
} else if (path.startsWith(userPrefix)) {
|
|
80
|
+
filenames.push(decodeURIComponent(path.slice(userPrefix.length)));
|
|
76
81
|
}
|
|
77
82
|
}
|
|
78
83
|
return Promise.resolve(filenames.sort());
|
|
@@ -143,9 +148,12 @@ class InMemoryArtifactService {
|
|
|
143
148
|
}
|
|
144
149
|
function artifactPath(appName, userId, sessionId, filename) {
|
|
145
150
|
if (fileHasUserNamespace(filename)) {
|
|
146
|
-
return "".concat(appName,
|
|
151
|
+
return "".concat(artifactPrefix("user", appName, userId)).concat(encodeURIComponent(filename));
|
|
147
152
|
}
|
|
148
|
-
return "".concat(appName,
|
|
153
|
+
return "".concat(artifactPrefix("session", appName, userId, sessionId)).concat(encodeURIComponent(filename));
|
|
154
|
+
}
|
|
155
|
+
function artifactPrefix(scope, ...parts) {
|
|
156
|
+
return "".concat([scope, ...parts].map(encodeURIComponent).join("/"), "/");
|
|
149
157
|
}
|
|
150
158
|
function fileHasUserNamespace(filename) {
|
|
151
159
|
return filename.startsWith("user:");
|