@google/adk 1.2.0 → 1.4.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/agents/active_streaming_tool.js +6 -1
- package/dist/cjs/agents/base_agent.js +19 -1
- package/dist/cjs/agents/context.js +1 -11
- package/dist/cjs/agents/functions.js +35 -16
- package/dist/cjs/agents/instructions.js +99 -33
- package/dist/cjs/agents/invocation_context.js +2 -6
- package/dist/cjs/agents/llm_agent.js +60 -11
- package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/cjs/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/cjs/agents/processors/content_processor_utils.js +51 -25
- package/dist/cjs/agents/processors/content_request_processor.js +7 -0
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +16 -2
- package/dist/cjs/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/cjs/agents/processors/interactions_request_processor.js +63 -0
- package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/cjs/agents/processors/tool_filter_request_processor.js +7 -1
- 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 +5 -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/auth_preprocessor.js +12 -10
- package/dist/cjs/auth/oauth2/oauth2_discovery.js +17 -5
- package/dist/cjs/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/cjs/code_executors/code_executor_context.js +7 -7
- package/dist/cjs/common.js +86 -0
- package/dist/cjs/context/agent_controlled_context_compactor.js +109 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +11 -0
- package/dist/cjs/context/token_based_context_compactor.js +43 -11
- package/dist/cjs/context/trajectory_thought_pruning_compactor.js +71 -0
- package/dist/cjs/events/event.js +25 -1
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
- package/dist/cjs/models/gemini_llm_connection.js +62 -19
- package/dist/cjs/models/google_llm.js +51 -18
- package/dist/cjs/models/interactions_utils.js +732 -0
- package/dist/cjs/plugins/base_plugin.js +1 -0
- package/dist/cjs/plugins/security_plugin.js +16 -0
- package/dist/cjs/runner/in_memory_runner.js +13 -2
- package/dist/cjs/runner/runner.js +93 -72
- package/dist/cjs/sessions/base_session_service.js +19 -3
- package/dist/cjs/sessions/database_session_service.js +26 -9
- package/dist/cjs/sessions/db/schema.js +45 -10
- package/dist/cjs/sessions/in_memory_session_service.js +2 -1
- package/dist/cjs/sessions/vertex_ai_session_service.js +21 -5
- package/dist/cjs/skills/gcp_skill_registry.js +104 -0
- package/dist/cjs/skills/loader.js +67 -2
- package/dist/cjs/skills/skill_registry.js +27 -0
- package/dist/cjs/tools/base_toolset.js +1 -1
- package/dist/cjs/tools/consolidate_context_tool.js +79 -0
- package/dist/cjs/tools/forwarding_artifact_service.js +16 -28
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +232 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +224 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +117 -0
- package/dist/cjs/tools/openapi_tool/openapi_toolset.js +133 -0
- package/dist/cjs/tools/openapi_tool/rest_api_tool.js +256 -0
- package/dist/cjs/tools/skill/load_skill_resource_tool.js +25 -3
- package/dist/cjs/tools/skill/load_skill_tool.js +12 -1
- package/dist/cjs/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/cjs/tools/skill/search_skills_tool.js +108 -0
- package/dist/cjs/tools/skill/skill_toolset.js +40 -5
- package/dist/cjs/utils/async_hooks_shim.js +52 -0
- package/dist/cjs/utils/async_queue.js +88 -0
- package/dist/cjs/utils/case_utils.js +53 -0
- package/dist/cjs/utils/client_labels.js +41 -3
- package/dist/cjs/utils/env_aware_utils.js +14 -1
- package/dist/cjs/utils/live_connection_utils.js +284 -0
- package/dist/cjs/utils/model_name.js +9 -0
- package/dist/cjs/utils/streaming_utils.js +18 -11
- package/dist/cjs/utils/task.js +62 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/active_streaming_tool.js +6 -1
- package/dist/esm/agents/base_agent.js +19 -1
- package/dist/esm/agents/context.js +1 -11
- package/dist/esm/agents/functions.js +36 -15
- package/dist/esm/agents/instructions.js +99 -33
- package/dist/esm/agents/invocation_context.js +2 -6
- package/dist/esm/agents/llm_agent.js +61 -11
- package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/esm/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/esm/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/esm/agents/processors/content_processor_utils.js +48 -24
- package/dist/esm/agents/processors/content_request_processor.js +7 -0
- package/dist/esm/agents/processors/context_compactor_request_processor.js +16 -2
- package/dist/esm/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/esm/agents/processors/interactions_request_processor.js +34 -0
- package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/esm/agents/processors/tool_filter_request_processor.js +7 -1
- 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 +5 -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/auth_preprocessor.js +12 -10
- package/dist/esm/auth/oauth2/oauth2_discovery.js +14 -4
- package/dist/esm/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/esm/code_executors/code_executor_context.js +7 -7
- package/dist/esm/common.js +75 -3
- package/dist/esm/context/agent_controlled_context_compactor.js +81 -0
- package/dist/esm/context/summarizers/llm_summarizer.js +11 -0
- package/dist/esm/context/token_based_context_compactor.js +43 -11
- package/dist/esm/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/esm/events/event.js +23 -1
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
- package/dist/esm/models/gemini_llm_connection.js +62 -19
- package/dist/esm/models/google_llm.js +49 -17
- package/dist/esm/models/interactions_utils.js +697 -0
- package/dist/esm/plugins/base_plugin.js +1 -0
- package/dist/esm/plugins/security_plugin.js +16 -0
- package/dist/esm/runner/in_memory_runner.js +13 -2
- package/dist/esm/runner/runner.js +91 -73
- package/dist/esm/sessions/base_session_service.js +17 -2
- package/dist/esm/sessions/database_session_service.js +26 -9
- package/dist/esm/sessions/db/schema.js +44 -10
- package/dist/esm/sessions/in_memory_session_service.js +4 -2
- package/dist/esm/sessions/vertex_ai_session_service.js +21 -5
- package/dist/esm/skills/gcp_skill_registry.js +78 -0
- package/dist/esm/skills/loader.js +66 -2
- package/dist/esm/skills/skill_registry.js +7 -0
- package/dist/esm/tools/base_toolset.js +1 -1
- package/dist/esm/tools/consolidate_context_tool.js +51 -0
- package/dist/esm/tools/forwarding_artifact_service.js +16 -28
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +206 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +91 -0
- package/dist/esm/tools/openapi_tool/openapi_toolset.js +97 -0
- package/dist/esm/tools/openapi_tool/rest_api_tool.js +229 -0
- package/dist/esm/tools/skill/load_skill_resource_tool.js +25 -3
- package/dist/esm/tools/skill/load_skill_tool.js +12 -1
- package/dist/esm/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/esm/tools/skill/search_skills_tool.js +82 -0
- package/dist/esm/tools/skill/skill_toolset.js +40 -5
- package/dist/esm/utils/async_hooks_shim.js +24 -0
- package/dist/esm/utils/async_queue.js +60 -0
- package/dist/esm/utils/case_utils.js +25 -0
- package/dist/esm/utils/client_labels.js +38 -2
- package/dist/esm/utils/env_aware_utils.js +14 -1
- package/dist/esm/utils/live_connection_utils.js +256 -0
- package/dist/esm/utils/model_name.js +8 -0
- package/dist/esm/utils/streaming_utils.js +18 -11
- package/dist/esm/utils/task.js +34 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent_utils.d.ts +29 -4
- package/dist/types/a2a/event_converter_utils.d.ts +14 -1
- package/dist/types/a2a/metadata_converter_utils.d.ts +18 -0
- package/dist/types/a2a/part_converter_utils.d.ts +51 -6
- package/dist/types/agents/active_streaming_tool.d.ts +3 -4
- package/dist/types/agents/functions.d.ts +12 -9
- package/dist/types/agents/invocation_context.d.ts +7 -12
- package/dist/types/agents/llm_agent.d.ts +14 -0
- package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +14 -0
- package/dist/types/agents/processors/basic_llm_request_processor.d.ts +7 -0
- package/dist/types/agents/processors/content_processor_utils.d.ts +34 -0
- package/dist/types/agents/processors/content_request_processor.d.ts +16 -0
- package/dist/types/agents/processors/context_compactor_request_processor.d.ts +12 -0
- package/dist/types/agents/processors/identity_llm_request_processor.d.ts +7 -0
- package/dist/types/agents/processors/interactions_request_processor.d.ts +17 -0
- package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +9 -1
- package/dist/types/agents/processors/tool_filter_request_processor.d.ts +12 -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 +35 -4
- package/dist/types/context/agent_controlled_context_compactor.d.ts +24 -0
- package/dist/types/context/base_context_compactor.d.ts +3 -0
- package/dist/types/context/summarizers/llm_summarizer.d.ts +17 -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/event.d.ts +8 -0
- package/dist/types/events/event_actions.d.ts +1 -2
- package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +21 -2
- package/dist/types/models/base_llm_connection.d.ts +10 -0
- package/dist/types/models/gemini_llm_connection.d.ts +15 -4
- 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 +14 -1
- package/dist/types/plugins/base_plugin.d.ts +2 -1
- package/dist/types/plugins/security_plugin.d.ts +30 -0
- package/dist/types/runner/in_memory_runner.d.ts +7 -1
- package/dist/types/runner/runner.d.ts +43 -9
- package/dist/types/sessions/base_session_service.d.ts +7 -16
- package/dist/types/sessions/db/schema.d.ts +1 -0
- package/dist/types/sessions/session.d.ts +11 -0
- package/dist/types/sessions/vertex_ai_session_service.d.ts +9 -1
- package/dist/types/skills/gcp_skill_registry.d.ts +24 -0
- package/dist/types/skills/loader.d.ts +7 -0
- package/dist/types/skills/skill.d.ts +1 -1
- package/dist/types/skills/skill_registry.d.ts +29 -0
- package/dist/types/tools/consolidate_context_tool.d.ts +19 -0
- package/dist/types/tools/forwarding_artifact_service.d.ts +3 -2
- package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +34 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +59 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +23 -0
- package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +27 -0
- package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +50 -0
- package/dist/types/tools/skill/load_skill_resource_tool.d.ts +1 -1
- package/dist/types/tools/skill/search_skills_tool.d.ts +14 -0
- package/dist/types/tools/skill/skill_toolset.d.ts +5 -0
- package/dist/types/utils/async_hooks_shim.d.ts +10 -0
- package/dist/types/utils/async_queue.d.ts +18 -0
- package/dist/types/utils/case_utils.d.ts +12 -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/live_connection_utils.d.ts +30 -0
- package/dist/types/utils/model_name.d.ts +7 -0
- package/dist/types/utils/streaming_utils.d.ts +0 -1
- package/dist/types/utils/task.d.ts +24 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/active_streaming_tool.js +6 -1
- package/dist/web/agents/base_agent.js +31 -1
- package/dist/web/agents/context.js +1 -11
- package/dist/web/agents/functions.js +36 -15
- package/dist/web/agents/instructions.js +99 -33
- package/dist/web/agents/invocation_context.js +2 -6
- package/dist/web/agents/llm_agent.js +61 -11
- package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/web/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/web/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/web/agents/processors/content_processor_utils.js +66 -24
- package/dist/web/agents/processors/content_request_processor.js +7 -0
- package/dist/web/agents/processors/context_compactor_request_processor.js +16 -2
- package/dist/web/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/web/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/web/agents/processors/interactions_request_processor.js +52 -0
- package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/web/agents/processors/tool_filter_request_processor.js +7 -1
- 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 +5 -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/auth_preprocessor.js +12 -10
- package/dist/web/auth/oauth2/oauth2_discovery.js +14 -4
- package/dist/web/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/web/code_executors/code_executor_context.js +7 -7
- package/dist/web/common.js +75 -3
- package/dist/web/context/agent_controlled_context_compactor.js +81 -0
- package/dist/web/context/summarizers/llm_summarizer.js +11 -0
- package/dist/web/context/token_based_context_compactor.js +43 -11
- package/dist/web/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/web/events/event.js +21 -1
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
- package/dist/web/models/gemini_llm_connection.js +75 -19
- package/dist/web/models/google_llm.js +80 -17
- package/dist/web/models/interactions_utils.js +728 -0
- package/dist/web/plugins/base_plugin.js +1 -0
- package/dist/web/plugins/security_plugin.js +16 -0
- package/dist/web/runner/in_memory_runner.js +13 -2
- package/dist/web/runner/runner.js +111 -75
- package/dist/web/sessions/base_session_service.js +17 -2
- package/dist/web/sessions/database_session_service.js +26 -9
- package/dist/web/sessions/db/schema.js +44 -10
- package/dist/web/sessions/in_memory_session_service.js +4 -2
- package/dist/web/sessions/vertex_ai_session_service.js +21 -5
- package/dist/web/skills/gcp_skill_registry.js +78 -0
- package/dist/web/skills/loader.js +66 -2
- package/dist/web/skills/skill_registry.js +7 -0
- package/dist/web/tools/base_toolset.js +1 -1
- package/dist/web/tools/consolidate_context_tool.js +51 -0
- package/dist/web/tools/forwarding_artifact_service.js +16 -28
- package/dist/web/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +221 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +91 -0
- package/dist/web/tools/openapi_tool/openapi_toolset.js +97 -0
- package/dist/web/tools/openapi_tool/rest_api_tool.js +229 -0
- package/dist/web/tools/skill/load_skill_resource_tool.js +25 -3
- package/dist/web/tools/skill/load_skill_tool.js +12 -1
- package/dist/web/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/web/tools/skill/search_skills_tool.js +82 -0
- package/dist/web/tools/skill/skill_toolset.js +40 -5
- package/dist/web/utils/async_hooks_shim.js +24 -0
- package/dist/web/utils/async_queue.js +60 -0
- package/dist/web/utils/case_utils.js +25 -0
- package/dist/web/utils/client_labels.js +38 -2
- package/dist/web/utils/env_aware_utils.js +14 -1
- package/dist/web/utils/live_connection_utils.js +254 -0
- package/dist/web/utils/model_name.js +8 -0
- package/dist/web/utils/streaming_utils.js +18 -11
- package/dist/web/utils/task.js +34 -0
- package/dist/web/version.js +1 -1
- package/package.json +4 -2
|
@@ -27,6 +27,7 @@ __export(active_streaming_tool_exports, {
|
|
|
27
27
|
ActiveStreamingTool: () => ActiveStreamingTool
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(active_streaming_tool_exports);
|
|
30
|
+
var import_task = require("../utils/task.js");
|
|
30
31
|
/**
|
|
31
32
|
* @license
|
|
32
33
|
* Copyright 2025 Google LLC
|
|
@@ -34,7 +35,11 @@ module.exports = __toCommonJS(active_streaming_tool_exports);
|
|
|
34
35
|
*/
|
|
35
36
|
class ActiveStreamingTool {
|
|
36
37
|
constructor(params = {}) {
|
|
37
|
-
|
|
38
|
+
if (params.task instanceof Promise) {
|
|
39
|
+
this.task = new import_task.Task(() => params.task);
|
|
40
|
+
} else {
|
|
41
|
+
this.task = params.task;
|
|
42
|
+
}
|
|
38
43
|
this.stream = params.stream;
|
|
39
44
|
}
|
|
40
45
|
}
|
|
@@ -124,9 +124,27 @@ class BaseAgent {
|
|
|
124
124
|
ctx,
|
|
125
125
|
this,
|
|
126
126
|
async function* () {
|
|
127
|
+
var _a2, _b;
|
|
128
|
+
const context2 = this.createInvocationContext(parentContext);
|
|
129
|
+
const beforeAgentCallbackEvent = await this.handleBeforeAgentCallback(context2);
|
|
130
|
+
if (beforeAgentCallbackEvent) {
|
|
131
|
+
yield beforeAgentCallbackEvent;
|
|
132
|
+
}
|
|
133
|
+
if (context2.endInvocation || ((_a2 = parentContext.abortSignal) == null ? void 0 : _a2.aborted)) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
for await (const event of this.runLiveImpl(context2)) {
|
|
137
|
+
yield event;
|
|
138
|
+
}
|
|
139
|
+
if (context2.endInvocation || ((_b = parentContext.abortSignal) == null ? void 0 : _b.aborted)) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const afterAgentCallbackEvent = await this.handleAfterAgentCallback(context2);
|
|
143
|
+
if (afterAgentCallbackEvent) {
|
|
144
|
+
yield afterAgentCallbackEvent;
|
|
145
|
+
}
|
|
127
146
|
}
|
|
128
147
|
);
|
|
129
|
-
throw new Error("Live mode is not implemented yet.");
|
|
130
148
|
} finally {
|
|
131
149
|
span.end();
|
|
132
150
|
}
|
|
@@ -83,9 +83,6 @@ class Context extends import_readonly_context.ReadonlyContext {
|
|
|
83
83
|
throw new Error("Artifact service is not initialized.");
|
|
84
84
|
}
|
|
85
85
|
return this.invocationContext.artifactService.loadArtifact({
|
|
86
|
-
appName: this.invocationContext.appName,
|
|
87
|
-
userId: this.invocationContext.userId,
|
|
88
|
-
sessionId: this.invocationContext.session.id,
|
|
89
86
|
filename,
|
|
90
87
|
version
|
|
91
88
|
});
|
|
@@ -102,9 +99,6 @@ class Context extends import_readonly_context.ReadonlyContext {
|
|
|
102
99
|
throw new Error("Artifact service is not initialized.");
|
|
103
100
|
}
|
|
104
101
|
const version = await this.invocationContext.artifactService.saveArtifact({
|
|
105
|
-
appName: this.invocationContext.appName,
|
|
106
|
-
userId: this.invocationContext.userId,
|
|
107
|
-
sessionId: this.invocationContext.session.id,
|
|
108
102
|
filename,
|
|
109
103
|
artifact
|
|
110
104
|
});
|
|
@@ -137,11 +131,7 @@ class Context extends import_readonly_context.ReadonlyContext {
|
|
|
137
131
|
if (!this.invocationContext.artifactService) {
|
|
138
132
|
throw new Error("Artifact service is not initialized.");
|
|
139
133
|
}
|
|
140
|
-
return this.invocationContext.artifactService.listArtifactKeys(
|
|
141
|
-
appName: this.invocationContext.session.appName,
|
|
142
|
-
userId: this.invocationContext.session.userId,
|
|
143
|
-
sessionId: this.invocationContext.session.id
|
|
144
|
-
});
|
|
134
|
+
return this.invocationContext.artifactService.listArtifactKeys();
|
|
145
135
|
}
|
|
146
136
|
/**
|
|
147
137
|
* Searches the memory of the current user.
|
|
@@ -24,8 +24,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var functions_exports = {};
|
|
26
26
|
__export(functions_exports, {
|
|
27
|
+
AF_FUNCTION_CALL_ID_PREFIX: () => AF_FUNCTION_CALL_ID_PREFIX,
|
|
27
28
|
REQUEST_CONFIRMATION_FUNCTION_CALL_NAME: () => REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
|
|
28
29
|
REQUEST_EUC_FUNCTION_CALL_NAME: () => REQUEST_EUC_FUNCTION_CALL_NAME,
|
|
30
|
+
findEventByFunctionCallId: () => findEventByFunctionCallId,
|
|
31
|
+
findMatchingFunctionCall: () => findMatchingFunctionCall,
|
|
29
32
|
functionsExportedForTestingOnly: () => functionsExportedForTestingOnly,
|
|
30
33
|
generateAuthEvent: () => generateAuthEvent,
|
|
31
34
|
generateClientFunctionCallId: () => generateClientFunctionCallId,
|
|
@@ -34,8 +37,7 @@ __export(functions_exports, {
|
|
|
34
37
|
handleFunctionCallList: () => handleFunctionCallList,
|
|
35
38
|
handleFunctionCallsAsync: () => handleFunctionCallsAsync,
|
|
36
39
|
mergeParallelFunctionResponseEvents: () => mergeParallelFunctionResponseEvents,
|
|
37
|
-
populateClientFunctionCallId: () => populateClientFunctionCallId
|
|
38
|
-
removeClientFunctionCallId: () => removeClientFunctionCallId
|
|
40
|
+
populateClientFunctionCallId: () => populateClientFunctionCallId
|
|
39
41
|
});
|
|
40
42
|
module.exports = __toCommonJS(functions_exports);
|
|
41
43
|
var import_genai = require("@google/genai");
|
|
@@ -73,18 +75,6 @@ function populateClientFunctionCallId(modelResponseEvent) {
|
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
|
-
function removeClientFunctionCallId(content) {
|
|
77
|
-
if (content && content.parts) {
|
|
78
|
-
for (const part of content.parts) {
|
|
79
|
-
if (part.functionCall && part.functionCall.id && part.functionCall.id.startsWith(AF_FUNCTION_CALL_ID_PREFIX)) {
|
|
80
|
-
part.functionCall.id = void 0;
|
|
81
|
-
}
|
|
82
|
-
if (part.functionResponse && part.functionResponse.id && part.functionResponse.id.startsWith(AF_FUNCTION_CALL_ID_PREFIX)) {
|
|
83
|
-
part.functionResponse.id = void 0;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
78
|
function getLongRunningFunctionCalls(functionCalls, toolsDict) {
|
|
89
79
|
const longRunningToolIds = /* @__PURE__ */ new Set();
|
|
90
80
|
for (const functionCall of functionCalls) {
|
|
@@ -427,10 +417,40 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
|
|
|
427
417
|
timestamp: baseEvent.timestamp
|
|
428
418
|
});
|
|
429
419
|
}
|
|
420
|
+
function findEventByFunctionCallId(events, functionCallId, endIndex = events.length) {
|
|
421
|
+
for (let i = endIndex - 1; i >= 0; i--) {
|
|
422
|
+
const event = events[i];
|
|
423
|
+
const functionCalls = (0, import_event.getFunctionCalls)(event);
|
|
424
|
+
for (const functionCall of functionCalls) {
|
|
425
|
+
if (functionCall.id === functionCallId) {
|
|
426
|
+
return event;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return void 0;
|
|
431
|
+
}
|
|
432
|
+
function findMatchingFunctionCall(events) {
|
|
433
|
+
if (!events.length) {
|
|
434
|
+
return void 0;
|
|
435
|
+
}
|
|
436
|
+
const lastEvent = events[events.length - 1];
|
|
437
|
+
const functionResponses = (0, import_event.getFunctionResponses)(lastEvent);
|
|
438
|
+
if (!functionResponses.length || !functionResponses[0].id) {
|
|
439
|
+
return void 0;
|
|
440
|
+
}
|
|
441
|
+
return findEventByFunctionCallId(
|
|
442
|
+
events,
|
|
443
|
+
functionResponses[0].id,
|
|
444
|
+
events.length - 1
|
|
445
|
+
);
|
|
446
|
+
}
|
|
430
447
|
// Annotate the CommonJS export names for ESM import in node:
|
|
431
448
|
0 && (module.exports = {
|
|
449
|
+
AF_FUNCTION_CALL_ID_PREFIX,
|
|
432
450
|
REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
|
|
433
451
|
REQUEST_EUC_FUNCTION_CALL_NAME,
|
|
452
|
+
findEventByFunctionCallId,
|
|
453
|
+
findMatchingFunctionCall,
|
|
434
454
|
functionsExportedForTestingOnly,
|
|
435
455
|
generateAuthEvent,
|
|
436
456
|
generateClientFunctionCallId,
|
|
@@ -439,6 +459,5 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
|
|
|
439
459
|
handleFunctionCallList,
|
|
440
460
|
handleFunctionCallsAsync,
|
|
441
461
|
mergeParallelFunctionResponseEvents,
|
|
442
|
-
populateClientFunctionCallId
|
|
443
|
-
removeClientFunctionCallId
|
|
462
|
+
populateClientFunctionCallId
|
|
444
463
|
});
|
|
@@ -33,50 +33,116 @@ var import_state = require("../sessions/state.js");
|
|
|
33
33
|
* Copyright 2025 Google LLC
|
|
34
34
|
* SPDX-License-Identifier: Apache-2.0
|
|
35
35
|
*/
|
|
36
|
-
|
|
36
|
+
const ARTIFACT_PREFIX = "artifact.";
|
|
37
|
+
async function resolveKey(key, isOptional, rawMatch, readonlyContext) {
|
|
37
38
|
const invocationContext = readonlyContext.invocationContext;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
key = key.slice(0, -1);
|
|
39
|
+
if (key.startsWith(ARTIFACT_PREFIX)) {
|
|
40
|
+
const fileName = key.substring(ARTIFACT_PREFIX.length);
|
|
41
|
+
if (invocationContext.artifactService === void 0) {
|
|
42
|
+
throw new Error("Artifact service is not initialized.");
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
const artifact = await invocationContext.artifactService.loadArtifact({
|
|
45
|
+
filename: fileName
|
|
46
|
+
});
|
|
47
|
+
if (!artifact) {
|
|
48
|
+
if (isOptional) {
|
|
49
|
+
return "";
|
|
48
50
|
}
|
|
49
|
-
|
|
50
|
-
appName: invocationContext.session.appName,
|
|
51
|
-
userId: invocationContext.session.userId,
|
|
52
|
-
sessionId: invocationContext.session.id,
|
|
53
|
-
filename: fileName
|
|
54
|
-
});
|
|
55
|
-
if (!artifact) {
|
|
56
|
-
throw new Error(`Artifact ${fileName} not found.`);
|
|
57
|
-
}
|
|
58
|
-
return String(artifact);
|
|
51
|
+
throw new Error(`Artifact ${fileName} not found.`);
|
|
59
52
|
}
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
return formatValue(artifact, true);
|
|
54
|
+
}
|
|
55
|
+
if (!isValidStateName(key)) {
|
|
56
|
+
return rawMatch;
|
|
57
|
+
}
|
|
58
|
+
if (key in invocationContext.session.state) {
|
|
59
|
+
return formatValue(invocationContext.session.state[key], false);
|
|
60
|
+
}
|
|
61
|
+
if (isOptional) {
|
|
62
|
+
return "";
|
|
63
|
+
}
|
|
64
|
+
throw new Error(`Context variable not found: \`${key}\`.`);
|
|
65
|
+
}
|
|
66
|
+
function formatValue(value, isArtifact = false) {
|
|
67
|
+
if (typeof value === "string") {
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
if (typeof value === "object" && value !== null) {
|
|
71
|
+
if (isArtifact && "text" in value && typeof value.text === "string") {
|
|
72
|
+
return value.text;
|
|
62
73
|
}
|
|
63
|
-
|
|
64
|
-
|
|
74
|
+
try {
|
|
75
|
+
const json = JSON.stringify(value);
|
|
76
|
+
if (json !== void 0) {
|
|
77
|
+
return json;
|
|
78
|
+
}
|
|
79
|
+
} catch (e) {
|
|
80
|
+
throw new Error(
|
|
81
|
+
`Failed to serialize value for instruction template: ${e instanceof Error ? e.message : String(e)}`
|
|
82
|
+
);
|
|
65
83
|
}
|
|
84
|
+
}
|
|
85
|
+
return String(value);
|
|
86
|
+
}
|
|
87
|
+
async function injectSessionState(template, readonlyContext) {
|
|
88
|
+
const pattern = /\{+[^{}]*}+/g;
|
|
89
|
+
const matches = Array.from(template.matchAll(pattern));
|
|
90
|
+
if (matches.length === 0) {
|
|
91
|
+
return template;
|
|
92
|
+
}
|
|
93
|
+
const parsedMatches = matches.map((match) => {
|
|
94
|
+
const raw = match[0];
|
|
95
|
+
let key = raw.replace(/^\{+/, "").replace(/\}+$/, "").trim();
|
|
96
|
+
const isOptional = key.endsWith("?");
|
|
66
97
|
if (isOptional) {
|
|
67
|
-
|
|
98
|
+
key = key.slice(0, -1);
|
|
99
|
+
}
|
|
100
|
+
const isValid = key.startsWith(ARTIFACT_PREFIX) || isValidStateName(key);
|
|
101
|
+
return {
|
|
102
|
+
raw,
|
|
103
|
+
key,
|
|
104
|
+
isOptional,
|
|
105
|
+
isValid,
|
|
106
|
+
index: match.index
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
const uniqueKeys = /* @__PURE__ */ new Map();
|
|
110
|
+
for (const pm of parsedMatches) {
|
|
111
|
+
if (!pm.isValid) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const existing = uniqueKeys.get(pm.key);
|
|
115
|
+
if (existing) {
|
|
116
|
+
if (existing.isOptional && !pm.isOptional) {
|
|
117
|
+
existing.isOptional = false;
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
uniqueKeys.set(pm.key, {
|
|
121
|
+
key: pm.key,
|
|
122
|
+
isOptional: pm.isOptional,
|
|
123
|
+
raw: pm.raw
|
|
124
|
+
});
|
|
68
125
|
}
|
|
69
|
-
throw new Error(`Context variable not found: \`${key}\`.`);
|
|
70
126
|
}
|
|
71
|
-
const
|
|
127
|
+
const resolutions = /* @__PURE__ */ new Map();
|
|
128
|
+
for (const info of uniqueKeys.values()) {
|
|
129
|
+
resolutions.set(
|
|
130
|
+
info.key,
|
|
131
|
+
resolveKey(info.key, info.isOptional, info.raw, readonlyContext)
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
await Promise.all(resolutions.values());
|
|
72
135
|
const result = [];
|
|
73
136
|
let lastEnd = 0;
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
137
|
+
for (const pm of parsedMatches) {
|
|
138
|
+
result.push(template.slice(lastEnd, pm.index));
|
|
139
|
+
if (pm.isValid) {
|
|
140
|
+
const replacement = await resolutions.get(pm.key);
|
|
141
|
+
result.push(replacement);
|
|
142
|
+
} else {
|
|
143
|
+
result.push(pm.raw);
|
|
144
|
+
}
|
|
145
|
+
lastEnd = pm.index + pm.raw.length;
|
|
80
146
|
}
|
|
81
147
|
result.push(template.slice(lastEnd));
|
|
82
148
|
return result.join("");
|
|
@@ -58,11 +58,7 @@ class InvocationContext {
|
|
|
58
58
|
* @param params The parameters for creating an invocation context.
|
|
59
59
|
*/
|
|
60
60
|
constructor(params) {
|
|
61
|
-
|
|
62
|
-
* A container to keep track of different kinds of costs incurred as a part of
|
|
63
|
-
* this invocation.
|
|
64
|
-
*/
|
|
65
|
-
this.invocationCostManager = new InvocationCostManager();
|
|
61
|
+
var _a;
|
|
66
62
|
this.artifactService = params.artifactService;
|
|
67
63
|
this.sessionService = params.sessionService;
|
|
68
64
|
this.memoryService = params.memoryService;
|
|
@@ -74,10 +70,10 @@ class InvocationContext {
|
|
|
74
70
|
this.endInvocation = params.endInvocation || false;
|
|
75
71
|
this.transcriptionCache = params.transcriptionCache;
|
|
76
72
|
this.runConfig = params.runConfig;
|
|
77
|
-
this.liveRequestQueue = params.liveRequestQueue;
|
|
78
73
|
this.activeStreamingTools = params.activeStreamingTools;
|
|
79
74
|
this.pluginManager = params.pluginManager;
|
|
80
75
|
this.abortSignal = params.abortSignal;
|
|
76
|
+
this.invocationCostManager = (_a = params.invocationCostManager) != null ? _a : new InvocationCostManager();
|
|
81
77
|
}
|
|
82
78
|
/**
|
|
83
79
|
* The app name of the current session.
|
|
@@ -29,6 +29,7 @@ __export(llm_agent_exports, {
|
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(llm_agent_exports);
|
|
31
31
|
var import_api = require("@opentelemetry/api");
|
|
32
|
+
var import_function_tool = require("../tools/function_tool.js");
|
|
32
33
|
var import_event = require("../events/event.js");
|
|
33
34
|
var import_base_llm = require("../models/base_llm.js");
|
|
34
35
|
var import_registry = require("../models/registry.js");
|
|
@@ -39,6 +40,7 @@ var import_tracing = require("../telemetry/tracing.js");
|
|
|
39
40
|
var import_simple_zod_to_json = require("../utils/simple_zod_to_json.js");
|
|
40
41
|
var import_base_agent = require("./base_agent.js");
|
|
41
42
|
var import_functions = require("./functions.js");
|
|
43
|
+
var import_auth_preprocessor = require("../auth/auth_preprocessor.js");
|
|
42
44
|
var import_agent_transfer_llm_request_processor = require("./processors/agent_transfer_llm_request_processor.js");
|
|
43
45
|
var import_basic_llm_request_processor = require("./processors/basic_llm_request_processor.js");
|
|
44
46
|
var import_code_execution_request_processor = require("./processors/code_execution_request_processor.js");
|
|
@@ -46,6 +48,7 @@ var import_content_request_processor = require("./processors/content_request_pro
|
|
|
46
48
|
var import_context_compactor_request_processor = require("./processors/context_compactor_request_processor.js");
|
|
47
49
|
var import_identity_llm_request_processor = require("./processors/identity_llm_request_processor.js");
|
|
48
50
|
var import_instructions_llm_request_processor = require("./processors/instructions_llm_request_processor.js");
|
|
51
|
+
var import_interactions_request_processor = require("./processors/interactions_request_processor.js");
|
|
49
52
|
var import_request_confirmation_llm_request_processor = require("./processors/request_confirmation_llm_request_processor.js");
|
|
50
53
|
var import_tool_filter_request_processor = require("./processors/tool_filter_request_processor.js");
|
|
51
54
|
var import_readonly_context = require("./readonly_context.js");
|
|
@@ -91,10 +94,12 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
|
|
|
91
94
|
this.codeExecutor = config.codeExecutor;
|
|
92
95
|
this.requestProcessors = (_g = config.requestProcessors) != null ? _g : [
|
|
93
96
|
import_basic_llm_request_processor.BASIC_LLM_REQUEST_PROCESSOR,
|
|
97
|
+
import_auth_preprocessor.AUTH_PREPROCESSOR,
|
|
94
98
|
import_identity_llm_request_processor.IDENTITY_LLM_REQUEST_PROCESSOR,
|
|
95
99
|
import_instructions_llm_request_processor.INSTRUCTIONS_LLM_REQUEST_PROCESSOR,
|
|
96
100
|
import_request_confirmation_llm_request_processor.REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR,
|
|
97
101
|
import_content_request_processor.CONTENT_REQUEST_PROCESSOR,
|
|
102
|
+
import_interactions_request_processor.INTERACTIONS_REQUEST_PROCESSOR,
|
|
98
103
|
import_code_execution_request_processor.CODE_EXECUTION_REQUEST_PROCESSOR,
|
|
99
104
|
import_tool_filter_request_processor.TOOL_FILTER_REQUEST_PROCESSOR
|
|
100
105
|
];
|
|
@@ -316,18 +321,26 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
|
|
|
316
321
|
event.actions.stateDelta[this.outputKey] = result;
|
|
317
322
|
}
|
|
318
323
|
async *runAsyncImpl(context2) {
|
|
319
|
-
var _a2;
|
|
324
|
+
var _a2, _b2;
|
|
320
325
|
while (true) {
|
|
321
326
|
let lastEvent = void 0;
|
|
327
|
+
let stepHadToolCalls = false;
|
|
322
328
|
for await (const event of this.runOneStepAsync(context2)) {
|
|
323
329
|
if ((_a2 = context2.abortSignal) == null ? void 0 : _a2.aborted) {
|
|
324
330
|
return;
|
|
325
331
|
}
|
|
326
332
|
lastEvent = event;
|
|
333
|
+
if ((0, import_event.getFunctionCalls)(event).length > 0 || (0, import_event.getFunctionResponses)(event).length > 0) {
|
|
334
|
+
stepHadToolCalls = true;
|
|
335
|
+
}
|
|
327
336
|
this.maybeSaveOutputToState(event);
|
|
328
337
|
yield event;
|
|
329
338
|
}
|
|
330
|
-
if (!lastEvent
|
|
339
|
+
if (!lastEvent) {
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
const isEmptyMetadataEvent = lastEvent.author === this.name && !lastEvent.partial && (!((_b2 = lastEvent.content) == null ? void 0 : _b2.parts) || lastEvent.content.parts.length === 0);
|
|
343
|
+
if ((0, import_event.isFinalResponse)(lastEvent) && !(isEmptyMetadataEvent && stepHadToolCalls)) {
|
|
331
344
|
break;
|
|
332
345
|
}
|
|
333
346
|
if (lastEvent.partial) {
|
|
@@ -352,6 +365,20 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
|
|
|
352
365
|
// --------------------------------------------------------------------------
|
|
353
366
|
// #START LlmFlow Logic
|
|
354
367
|
// --------------------------------------------------------------------------
|
|
368
|
+
/**
|
|
369
|
+
* Runs the bidirectional (live) flow for this agent.
|
|
370
|
+
*
|
|
371
|
+
* Establishes a live connection to the model, drains the invocation's
|
|
372
|
+
* `liveRequestQueue` into the connection on a parallel task, and yields
|
|
373
|
+
* events derived from server messages until the queue closes, the model
|
|
374
|
+
* finishes, or an agent transfer occurs.
|
|
375
|
+
*
|
|
376
|
+
* If the live connection drops (network failure, server `goAway`) and a
|
|
377
|
+
* session resumption handle has been observed, the flow transparently
|
|
378
|
+
* reconnects using that handle up to {@link MAX_LIVE_RECONNECT_ATTEMPTS}
|
|
379
|
+
* times. Subsequent reconnects skip `sendHistory` because the server
|
|
380
|
+
* already holds the conversation state associated with the handle.
|
|
381
|
+
*/
|
|
355
382
|
// eslint-disable-next-line require-yield
|
|
356
383
|
async *runLiveFlow(_invocationContext) {
|
|
357
384
|
await Promise.resolve();
|
|
@@ -375,13 +402,28 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
|
|
|
375
402
|
yield event;
|
|
376
403
|
}
|
|
377
404
|
}
|
|
378
|
-
|
|
405
|
+
const allTools = [...this.tools];
|
|
406
|
+
if (this.outputSchema && allTools.length > 0) {
|
|
407
|
+
const setModelResponseTool = new import_function_tool.FunctionTool({
|
|
408
|
+
name: "set_model_response",
|
|
409
|
+
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.",
|
|
410
|
+
parameters: this.outputSchema,
|
|
411
|
+
execute: async (args, toolContext) => {
|
|
412
|
+
if (toolContext) {
|
|
413
|
+
toolContext.actions.skipSummarization = true;
|
|
414
|
+
}
|
|
415
|
+
return JSON.stringify(args);
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
allTools.push(setModelResponseTool);
|
|
419
|
+
}
|
|
420
|
+
for (const toolUnion of allTools) {
|
|
379
421
|
const toolContext = new import_context.Context({ invocationContext });
|
|
380
422
|
const tools = (await convertToolUnionToTools(
|
|
381
423
|
toolUnion,
|
|
382
424
|
new import_readonly_context.ReadonlyContext(invocationContext)
|
|
383
425
|
)).filter((tool) => {
|
|
384
|
-
return !llmRequest.allowedTools || llmRequest.allowedTools.includes(tool.name);
|
|
426
|
+
return !llmRequest.allowedTools || llmRequest.allowedTools.includes(tool.name) || tool.name === "set_model_response";
|
|
385
427
|
});
|
|
386
428
|
for (const tool of tools) {
|
|
387
429
|
await tool.processLlmRequest({ toolContext, llmRequest });
|
|
@@ -440,7 +482,7 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
|
|
|
440
482
|
span.end();
|
|
441
483
|
}
|
|
442
484
|
async *postprocess(invocationContext, llmRequest, llmResponse, modelResponseEvent) {
|
|
443
|
-
var _a2, _b2, _c, _d, _e;
|
|
485
|
+
var _a2, _b2, _c, _d, _e, _f;
|
|
444
486
|
for (const processor of this.responseProcessors) {
|
|
445
487
|
for await (const event of processor.runAsync(
|
|
446
488
|
invocationContext,
|
|
@@ -452,7 +494,7 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
|
|
|
452
494
|
yield event;
|
|
453
495
|
}
|
|
454
496
|
}
|
|
455
|
-
if (!llmResponse.content && !llmResponse.errorCode && !llmResponse.interrupted) {
|
|
497
|
+
if ((!llmResponse.content || ((_b2 = llmResponse.content.parts) == null ? void 0 : _b2.length) === 0) && !llmResponse.errorCode && !llmResponse.interrupted) {
|
|
456
498
|
return;
|
|
457
499
|
}
|
|
458
500
|
const mergedEvent = (0, import_event.createEvent)({
|
|
@@ -461,7 +503,14 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
|
|
|
461
503
|
});
|
|
462
504
|
if (mergedEvent.content) {
|
|
463
505
|
const functionCalls = (0, import_event.getFunctionCalls)(mergedEvent);
|
|
464
|
-
|
|
506
|
+
const setModelResponseCall = functionCalls.find(
|
|
507
|
+
(call) => call.name === "set_model_response"
|
|
508
|
+
);
|
|
509
|
+
if (setModelResponseCall) {
|
|
510
|
+
const args = setModelResponseCall.args;
|
|
511
|
+
mergedEvent.content.parts = [{ text: JSON.stringify(args) }];
|
|
512
|
+
mergedEvent.actions.skipSummarization = true;
|
|
513
|
+
} else if (functionCalls && functionCalls.length) {
|
|
465
514
|
(0, import_functions.populateClientFunctionCallId)(mergedEvent);
|
|
466
515
|
mergedEvent.longRunningToolIds = Array.from(
|
|
467
516
|
(0, import_functions.getLongRunningFunctionCalls)(functionCalls, llmRequest.toolsDict)
|
|
@@ -469,10 +518,10 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
|
|
|
469
518
|
}
|
|
470
519
|
}
|
|
471
520
|
yield mergedEvent;
|
|
472
|
-
if (!((
|
|
521
|
+
if (!((_c = (0, import_event.getFunctionCalls)(mergedEvent)) == null ? void 0 : _c.length)) {
|
|
473
522
|
return;
|
|
474
523
|
}
|
|
475
|
-
if ((
|
|
524
|
+
if ((_d = invocationContext.runConfig) == null ? void 0 : _d.pauseOnToolCalls) {
|
|
476
525
|
invocationContext.endInvocation = true;
|
|
477
526
|
return;
|
|
478
527
|
}
|
|
@@ -483,7 +532,7 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
|
|
|
483
532
|
beforeToolCallbacks: this.canonicalBeforeToolCallbacks,
|
|
484
533
|
afterToolCallbacks: this.canonicalAfterToolCallbacks
|
|
485
534
|
});
|
|
486
|
-
if (!functionResponseEvent || ((
|
|
535
|
+
if (!functionResponseEvent || ((_e = invocationContext.abortSignal) == null ? void 0 : _e.aborted)) {
|
|
487
536
|
return;
|
|
488
537
|
}
|
|
489
538
|
const authEvent = (0, import_functions.generateAuthEvent)(
|
|
@@ -508,7 +557,7 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
|
|
|
508
557
|
if (nextAgentName) {
|
|
509
558
|
const nextAgent = this.getAgentByName(invocationContext, nextAgentName);
|
|
510
559
|
for await (const event of nextAgent.runAsync(invocationContext)) {
|
|
511
|
-
if ((
|
|
560
|
+
if ((_f = invocationContext.abortSignal) == null ? void 0 : _f.aborted) {
|
|
512
561
|
return;
|
|
513
562
|
}
|
|
514
563
|
yield event;
|
|
@@ -58,6 +58,13 @@ class AgentTransferLlmRequestProcessor extends import_base_llm_processor.BaseLlm
|
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Appends transfer instructions and registers the `transfer_to_agent` tool
|
|
63
|
+
* when the agent has reachable transfer targets.
|
|
64
|
+
*
|
|
65
|
+
* @param invocationContext - The current invocation context.
|
|
66
|
+
* @param llmRequest - The request to augment with transfer instructions and the transfer tool.
|
|
67
|
+
*/
|
|
61
68
|
// eslint-disable-next-line require-yield
|
|
62
69
|
async *runAsync(invocationContext, llmRequest) {
|
|
63
70
|
if (!(0, import_llm_agent.isLlmAgent)(invocationContext.agent)) {
|
|
@@ -37,6 +37,13 @@ var import_base_llm_processor = require("./base_llm_processor.js");
|
|
|
37
37
|
* SPDX-License-Identifier: Apache-2.0
|
|
38
38
|
*/
|
|
39
39
|
class BasicLlmRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
|
|
40
|
+
/**
|
|
41
|
+
* Populates model name, generation config, output schema, and live connect
|
|
42
|
+
* settings on the request from the agent and run config.
|
|
43
|
+
*
|
|
44
|
+
* @param invocationContext - The current invocation context.
|
|
45
|
+
* @param llmRequest - The request object to populate in place.
|
|
46
|
+
*/
|
|
40
47
|
// eslint-disable-next-line require-yield
|
|
41
48
|
async *runAsync(invocationContext, llmRequest) {
|
|
42
49
|
var _a;
|
|
@@ -46,7 +53,7 @@ class BasicLlmRequestProcessor extends import_base_llm_processor.BaseLlmRequestP
|
|
|
46
53
|
}
|
|
47
54
|
llmRequest.model = agent.canonicalModel.model;
|
|
48
55
|
llmRequest.config = { ...(_a = agent.generateContentConfig) != null ? _a : {} };
|
|
49
|
-
if (agent.outputSchema) {
|
|
56
|
+
if (agent.outputSchema && (!agent.tools || agent.tools.length === 0)) {
|
|
50
57
|
(0, import_llm_request.setOutputSchema)(llmRequest, agent.outputSchema);
|
|
51
58
|
}
|
|
52
59
|
if (invocationContext.runConfig) {
|
|
@@ -339,9 +339,6 @@ async function postProcessCodeExecutionResult(invocationContext, codeExecutorCon
|
|
|
339
339
|
}
|
|
340
340
|
for (const outputFile of codeExecutionResult.outputFiles) {
|
|
341
341
|
const version = await invocationContext.artifactService.saveArtifact({
|
|
342
|
-
appName: invocationContext.appName || "",
|
|
343
|
-
userId: invocationContext.userId || "",
|
|
344
|
-
sessionId: invocationContext.session.id,
|
|
345
342
|
filename: outputFile.name,
|
|
346
343
|
artifact: {
|
|
347
344
|
inlineData: { data: outputFile.content, mimeType: outputFile.mimeType }
|