@google/adk 0.3.0 → 0.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/a2a_event.js +290 -0
- package/dist/cjs/a2a/event_converter_utils.js +201 -0
- package/dist/cjs/a2a/executor_context.js +53 -0
- package/dist/cjs/a2a/metadata_converter_utils.js +125 -0
- package/dist/cjs/a2a/part_converter_utils.js +212 -0
- package/dist/cjs/agents/active_streaming_tool.js +1 -1
- package/dist/cjs/agents/base_agent.js +6 -6
- package/dist/cjs/agents/content_processor_utils.js +1 -1
- package/dist/cjs/{tools/tool_context.js → agents/context.js} +71 -16
- package/dist/cjs/agents/functions.js +4 -3
- package/dist/cjs/agents/instructions.js +1 -1
- package/dist/cjs/agents/invocation_context.js +1 -1
- package/dist/cjs/agents/live_request_queue.js +1 -1
- package/dist/cjs/agents/llm_agent.js +76 -711
- package/dist/cjs/agents/loop_agent.js +1 -1
- package/dist/cjs/agents/parallel_agent.js +1 -1
- package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +132 -0
- package/dist/cjs/agents/{base_llm_processor.js → processors/base_llm_processor.js} +1 -1
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +68 -0
- package/dist/cjs/agents/processors/code_execution_request_processor.js +389 -0
- package/dist/cjs/agents/processors/content_request_processor.js +66 -0
- package/dist/cjs/agents/processors/identity_llm_request_processor.js +54 -0
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +85 -0
- package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +165 -0
- package/dist/cjs/agents/readonly_context.js +13 -1
- package/dist/cjs/agents/run_config.js +2 -1
- package/dist/cjs/agents/sequential_agent.js +1 -1
- package/dist/cjs/agents/transcription_entry.js +1 -1
- package/dist/cjs/artifacts/base_artifact_service.js +1 -1
- package/dist/cjs/artifacts/file_artifact_service.js +491 -0
- package/dist/cjs/artifacts/gcs_artifact_service.js +127 -48
- package/dist/cjs/artifacts/in_memory_artifact_service.js +54 -6
- package/dist/cjs/artifacts/registry.js +55 -0
- package/dist/cjs/auth/auth_credential.js +1 -1
- package/dist/cjs/auth/auth_handler.js +1 -1
- package/dist/cjs/auth/auth_schemes.js +1 -1
- package/dist/cjs/auth/auth_tool.js +1 -1
- package/dist/cjs/auth/credential_service/base_credential_service.js +1 -1
- package/dist/cjs/auth/credential_service/in_memory_credential_service.js +1 -1
- package/dist/cjs/auth/exchanger/base_credential_exchanger.js +1 -1
- package/dist/cjs/auth/exchanger/credential_exchanger_registry.js +1 -1
- package/dist/cjs/code_executors/base_code_executor.js +1 -1
- package/dist/cjs/code_executors/built_in_code_executor.js +1 -1
- package/dist/cjs/code_executors/code_execution_utils.js +1 -1
- package/dist/cjs/code_executors/code_executor_context.js +1 -1
- package/dist/cjs/common.js +25 -8
- package/dist/cjs/events/event.js +33 -4
- package/dist/cjs/events/event_actions.js +2 -2
- package/dist/cjs/events/structured_events.js +105 -0
- package/dist/cjs/examples/base_example_provider.js +1 -1
- package/dist/cjs/examples/example.js +1 -1
- package/dist/cjs/examples/example_util.js +1 -1
- package/dist/cjs/index.js +24 -17
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/index_web.js +1 -1
- package/dist/cjs/memory/base_memory_service.js +1 -1
- package/dist/cjs/memory/in_memory_memory_service.js +1 -1
- package/dist/cjs/memory/memory_entry.js +1 -1
- package/dist/cjs/models/apigee_llm.js +182 -0
- package/dist/cjs/models/base_llm.js +1 -1
- package/dist/cjs/models/base_llm_connection.js +1 -1
- package/dist/cjs/models/gemini_llm_connection.js +1 -1
- package/dist/cjs/models/google_llm.js +70 -51
- package/dist/cjs/models/llm_request.js +1 -1
- package/dist/cjs/models/llm_response.js +3 -1
- package/dist/cjs/models/registry.js +3 -1
- package/dist/cjs/plugins/base_plugin.js +2 -2
- package/dist/cjs/plugins/logging_plugin.js +1 -1
- package/dist/cjs/plugins/plugin_manager.js +1 -1
- package/dist/cjs/plugins/security_plugin.js +1 -1
- package/dist/cjs/runner/in_memory_runner.js +1 -1
- package/dist/cjs/runner/runner.js +33 -2
- package/dist/cjs/sessions/base_session_service.js +53 -3
- package/dist/cjs/sessions/database_session_service.js +367 -0
- package/dist/cjs/sessions/db/operations.js +126 -0
- package/dist/cjs/sessions/db/schema.js +204 -0
- package/dist/cjs/sessions/in_memory_session_service.js +24 -22
- package/dist/cjs/sessions/registry.js +49 -0
- package/dist/cjs/sessions/session.js +1 -1
- package/dist/cjs/sessions/state.js +1 -1
- package/dist/cjs/telemetry/google_cloud.js +1 -1
- package/dist/cjs/telemetry/setup.js +1 -1
- package/dist/cjs/telemetry/tracing.js +1 -1
- package/dist/cjs/tools/agent_tool.js +1 -1
- package/dist/cjs/tools/base_tool.js +4 -1
- package/dist/cjs/tools/base_toolset.js +14 -4
- package/dist/cjs/tools/exit_loop_tool.js +63 -0
- package/dist/cjs/tools/forwarding_artifact_service.js +17 -1
- package/dist/cjs/tools/function_tool.js +1 -1
- package/dist/cjs/tools/google_search_tool.js +1 -1
- package/dist/cjs/tools/long_running_tool.js +1 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +1 -1
- package/dist/cjs/tools/mcp/mcp_tool.js +1 -1
- package/dist/cjs/tools/mcp/mcp_toolset.js +10 -6
- package/dist/cjs/tools/tool_confirmation.js +1 -1
- package/dist/cjs/utils/client_labels.js +1 -1
- package/dist/cjs/utils/env_aware_utils.js +10 -1
- package/dist/cjs/utils/gemini_schema_util.js +1 -1
- package/dist/cjs/utils/logger.js +62 -55
- package/dist/cjs/utils/model_name.js +1 -1
- package/dist/cjs/utils/object_notation_utils.js +78 -0
- package/dist/cjs/utils/simple_zod_to_json.js +1 -1
- package/dist/cjs/utils/variant_utils.js +3 -9
- package/dist/cjs/version.js +2 -2
- package/dist/esm/a2a/a2a_event.js +243 -0
- package/dist/esm/a2a/event_converter_utils.js +187 -0
- package/dist/esm/a2a/executor_context.js +23 -0
- package/dist/esm/a2a/metadata_converter_utils.js +90 -0
- package/dist/esm/a2a/part_converter_utils.js +175 -0
- package/dist/esm/agents/base_agent.js +5 -5
- package/dist/esm/{tools/tool_context.js → agents/context.js} +66 -11
- package/dist/esm/agents/functions.js +3 -2
- package/dist/esm/agents/llm_agent.js +69 -720
- package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +101 -0
- package/dist/esm/agents/processors/basic_llm_request_processor.js +37 -0
- package/dist/esm/agents/processors/code_execution_request_processor.js +363 -0
- package/dist/esm/agents/processors/content_request_processor.js +38 -0
- package/dist/esm/agents/processors/identity_llm_request_processor.js +23 -0
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +54 -0
- package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +140 -0
- package/dist/esm/agents/readonly_context.js +12 -0
- package/dist/esm/agents/run_config.js +1 -0
- package/dist/esm/artifacts/file_artifact_service.js +451 -0
- package/dist/esm/artifacts/gcs_artifact_service.js +126 -47
- package/dist/esm/artifacts/in_memory_artifact_service.js +51 -4
- package/dist/esm/artifacts/registry.js +28 -0
- package/dist/esm/common.js +20 -10
- package/dist/esm/events/event.js +29 -2
- package/dist/esm/events/event_actions.js +1 -1
- package/dist/esm/events/structured_events.js +74 -0
- package/dist/esm/index.js +24 -17
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/models/apigee_llm.js +152 -0
- package/dist/esm/models/google_llm.js +67 -49
- package/dist/esm/models/llm_response.js +2 -0
- package/dist/esm/models/registry.js +2 -0
- package/dist/esm/plugins/base_plugin.js +1 -1
- package/dist/esm/runner/runner.js +32 -1
- package/dist/esm/sessions/base_session_service.js +49 -1
- package/dist/esm/sessions/database_session_service.js +353 -0
- package/dist/esm/sessions/db/operations.js +111 -0
- package/dist/esm/sessions/db/schema.js +172 -0
- package/dist/esm/sessions/in_memory_session_service.js +23 -21
- package/dist/esm/sessions/registry.js +25 -0
- package/dist/esm/tools/base_tool.js +3 -0
- package/dist/esm/tools/base_toolset.js +11 -2
- package/dist/esm/tools/exit_loop_tool.js +32 -0
- package/dist/esm/tools/forwarding_artifact_service.js +16 -0
- package/dist/esm/tools/mcp/mcp_toolset.js +9 -5
- package/dist/esm/utils/env_aware_utils.js +8 -0
- package/dist/esm/utils/logger.js +51 -54
- package/dist/esm/utils/object_notation_utils.js +47 -0
- package/dist/esm/utils/variant_utils.js +1 -7
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_event.d.ts +122 -0
- package/dist/types/a2a/event_converter_utils.d.ts +20 -0
- package/dist/types/a2a/executor_context.d.ts +33 -0
- package/dist/types/a2a/metadata_converter_utils.d.ts +62 -0
- package/dist/types/a2a/part_converter_utils.d.ts +48 -0
- package/dist/types/agents/base_agent.d.ts +2 -2
- package/dist/types/{tools/tool_context.d.ts → agents/context.d.ts} +43 -8
- package/dist/types/agents/llm_agent.d.ts +19 -42
- package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +18 -0
- package/dist/types/agents/{base_llm_processor.d.ts → processors/base_llm_processor.d.ts} +4 -4
- package/dist/types/agents/processors/basic_llm_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/code_execution_request_processor.d.ts +34 -0
- package/dist/types/agents/processors/content_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/identity_llm_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/instructions_llm_request_processor.d.ts +16 -0
- package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +13 -0
- package/dist/types/agents/readonly_context.d.ts +8 -0
- package/dist/types/agents/run_config.d.ts +6 -0
- package/dist/types/artifacts/base_artifact_service.d.ts +31 -0
- package/dist/types/artifacts/file_artifact_service.d.ts +43 -0
- package/dist/types/artifacts/gcs_artifact_service.d.ts +3 -1
- package/dist/types/artifacts/in_memory_artifact_service.d.ts +5 -2
- package/dist/types/artifacts/registry.d.ts +7 -0
- package/dist/types/auth/credential_service/base_credential_service.d.ts +3 -3
- package/dist/types/auth/credential_service/in_memory_credential_service.d.ts +3 -3
- package/dist/types/common.d.ts +15 -6
- package/dist/types/events/event.d.ts +15 -1
- package/dist/types/events/event_actions.d.ts +1 -1
- package/dist/types/events/structured_events.d.ts +106 -0
- package/dist/types/index.d.ts +5 -1
- package/dist/types/models/apigee_llm.d.ts +59 -0
- package/dist/types/models/google_llm.d.ts +5 -2
- package/dist/types/models/llm_response.d.ts +5 -1
- package/dist/types/plugins/base_plugin.d.ts +12 -13
- package/dist/types/plugins/logging_plugin.d.ts +9 -10
- package/dist/types/plugins/plugin_manager.d.ts +9 -10
- package/dist/types/plugins/security_plugin.d.ts +2 -2
- package/dist/types/runner/runner.d.ts +15 -0
- package/dist/types/sessions/base_session_service.d.ts +20 -0
- package/dist/types/sessions/database_session_service.d.ts +32 -0
- package/dist/types/sessions/db/operations.d.ts +29 -0
- package/dist/types/sessions/db/schema.d.ts +45 -0
- package/dist/types/sessions/in_memory_session_service.d.ts +4 -1
- package/dist/types/sessions/registry.d.ts +7 -0
- package/dist/types/tools/base_tool.d.ts +3 -3
- package/dist/types/tools/base_toolset.d.ts +12 -3
- package/dist/types/tools/exit_loop_tool.d.ts +24 -0
- package/dist/types/tools/forwarding_artifact_service.d.ts +5 -3
- package/dist/types/tools/function_tool.d.ts +2 -2
- package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -1
- package/dist/types/utils/env_aware_utils.d.ts +7 -0
- package/dist/types/utils/logger.d.ts +5 -9
- package/dist/types/utils/object_notation_utils.d.ts +21 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/a2a_event.js +243 -0
- package/dist/web/a2a/event_converter_utils.js +201 -0
- package/dist/web/a2a/executor_context.js +23 -0
- package/dist/web/a2a/metadata_converter_utils.js +107 -0
- package/dist/web/a2a/part_converter_utils.js +175 -0
- package/dist/web/agents/base_agent.js +5 -5
- package/dist/web/{tools/tool_context.js → agents/context.js} +66 -11
- package/dist/web/agents/functions.js +3 -2
- package/dist/web/agents/llm_agent.js +90 -717
- package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +100 -0
- package/dist/web/agents/processors/basic_llm_request_processor.js +71 -0
- package/dist/web/agents/processors/code_execution_request_processor.js +365 -0
- package/dist/web/agents/processors/content_request_processor.js +56 -0
- package/dist/web/agents/processors/identity_llm_request_processor.js +41 -0
- package/dist/web/agents/processors/instructions_llm_request_processor.js +72 -0
- package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +158 -0
- package/dist/web/agents/readonly_context.js +12 -0
- package/dist/web/agents/run_config.js +2 -1
- package/dist/web/artifacts/file_artifact_service.js +506 -0
- package/dist/web/artifacts/gcs_artifact_service.js +123 -46
- package/dist/web/artifacts/in_memory_artifact_service.js +51 -4
- package/dist/web/artifacts/registry.js +28 -0
- package/dist/web/common.js +20 -10
- package/dist/web/events/event.js +29 -2
- package/dist/web/events/event_actions.js +1 -1
- package/dist/web/events/structured_events.js +74 -0
- package/dist/web/index.js +7 -2
- package/dist/web/index.js.map +4 -4
- package/dist/web/models/apigee_llm.js +219 -0
- package/dist/web/models/google_llm.js +67 -46
- package/dist/web/models/llm_response.js +2 -0
- package/dist/web/models/registry.js +2 -0
- package/dist/web/plugins/base_plugin.js +1 -1
- package/dist/web/runner/runner.js +34 -1
- package/dist/web/sessions/base_session_service.js +49 -1
- package/dist/web/sessions/database_session_service.js +371 -0
- package/dist/web/sessions/db/operations.js +111 -0
- package/dist/web/sessions/db/schema.js +172 -0
- package/dist/web/sessions/in_memory_session_service.js +23 -21
- package/dist/web/sessions/registry.js +25 -0
- package/dist/web/tools/base_tool.js +3 -0
- package/dist/web/tools/base_toolset.js +11 -2
- package/dist/web/tools/exit_loop_tool.js +32 -0
- package/dist/web/tools/forwarding_artifact_service.js +16 -0
- package/dist/web/tools/mcp/mcp_toolset.js +27 -5
- package/dist/web/utils/env_aware_utils.js +8 -0
- package/dist/web/utils/logger.js +51 -54
- package/dist/web/utils/object_notation_utils.js +47 -0
- package/dist/web/utils/variant_utils.js +1 -7
- package/dist/web/version.js +1 -1
- package/package.json +13 -3
- package/dist/cjs/agents/callback_context.js +0 -101
- package/dist/esm/agents/callback_context.js +0 -71
- package/dist/types/agents/callback_context.d.ts +0 -42
- package/dist/web/agents/callback_context.js +0 -71
- /package/dist/esm/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
- /package/dist/web/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var agent_transfer_llm_request_processor_exports = {};
|
|
26
|
+
__export(agent_transfer_llm_request_processor_exports, {
|
|
27
|
+
AGENT_TRANSFER_LLM_REQUEST_PROCESSOR: () => AGENT_TRANSFER_LLM_REQUEST_PROCESSOR,
|
|
28
|
+
AgentTransferLlmRequestProcessor: () => AgentTransferLlmRequestProcessor
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(agent_transfer_llm_request_processor_exports);
|
|
31
|
+
var import_zod = require("zod");
|
|
32
|
+
var import_llm_request = require("../../models/llm_request.js");
|
|
33
|
+
var import_function_tool = require("../../tools/function_tool.js");
|
|
34
|
+
var import_context = require("../context.js");
|
|
35
|
+
var import_llm_agent = require("../llm_agent.js");
|
|
36
|
+
var import_base_llm_processor = require("./base_llm_processor.js");
|
|
37
|
+
/**
|
|
38
|
+
* @license
|
|
39
|
+
* Copyright 2025 Google LLC
|
|
40
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
41
|
+
*/
|
|
42
|
+
class AgentTransferLlmRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
|
|
43
|
+
constructor() {
|
|
44
|
+
super(...arguments);
|
|
45
|
+
this.toolName = "transfer_to_agent";
|
|
46
|
+
this.tool = new import_function_tool.FunctionTool({
|
|
47
|
+
name: this.toolName,
|
|
48
|
+
description: "Transfer the question to another agent. This tool hands off control to another agent when it is more suitable to answer the user question according to the agent description.",
|
|
49
|
+
parameters: import_zod.z.object({
|
|
50
|
+
agentName: import_zod.z.string().describe("the agent name to transfer to.")
|
|
51
|
+
}),
|
|
52
|
+
execute: function(args, toolContext) {
|
|
53
|
+
if (!toolContext) {
|
|
54
|
+
throw new Error("toolContext is required.");
|
|
55
|
+
}
|
|
56
|
+
toolContext.actions.transferToAgent = args.agentName;
|
|
57
|
+
return "Transfer queued";
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
// eslint-disable-next-line require-yield
|
|
62
|
+
async *runAsync(invocationContext, llmRequest) {
|
|
63
|
+
if (!(0, import_llm_agent.isLlmAgent)(invocationContext.agent)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const transferTargets = this.getTransferTargets(invocationContext.agent);
|
|
67
|
+
if (!transferTargets.length) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
(0, import_llm_request.appendInstructions)(llmRequest, [
|
|
71
|
+
this.buildTargetAgentsInstructions(
|
|
72
|
+
invocationContext.agent,
|
|
73
|
+
transferTargets
|
|
74
|
+
)
|
|
75
|
+
]);
|
|
76
|
+
const toolContext = new import_context.Context({ invocationContext });
|
|
77
|
+
await this.tool.processLlmRequest({ toolContext, llmRequest });
|
|
78
|
+
}
|
|
79
|
+
buildTargetAgentsInfo(targetAgent) {
|
|
80
|
+
return `
|
|
81
|
+
Agent name: ${targetAgent.name}
|
|
82
|
+
Agent description: ${targetAgent.description}
|
|
83
|
+
`;
|
|
84
|
+
}
|
|
85
|
+
buildTargetAgentsInstructions(agent, targetAgents) {
|
|
86
|
+
let instructions = `
|
|
87
|
+
You have a list of other agents to transfer to:
|
|
88
|
+
|
|
89
|
+
${targetAgents.map((t) => this.buildTargetAgentsInfo(t)).join("\n")}
|
|
90
|
+
|
|
91
|
+
If you are the best to answer the question according to your description, you
|
|
92
|
+
can answer it.
|
|
93
|
+
|
|
94
|
+
If another agent is better for answering the question according to its
|
|
95
|
+
description, call \`${this.toolName}\` function to transfer the
|
|
96
|
+
question to that agent. When transferring, do not generate any text other than
|
|
97
|
+
the function call.
|
|
98
|
+
`;
|
|
99
|
+
if (agent.parentAgent && !agent.disallowTransferToParent) {
|
|
100
|
+
instructions += `
|
|
101
|
+
Your parent agent is ${agent.parentAgent.name}. If neither the other agents nor
|
|
102
|
+
you are best for answering the question according to the descriptions, transfer
|
|
103
|
+
to your parent agent.
|
|
104
|
+
`;
|
|
105
|
+
}
|
|
106
|
+
return instructions;
|
|
107
|
+
}
|
|
108
|
+
getTransferTargets(agent) {
|
|
109
|
+
const targets = [];
|
|
110
|
+
targets.push(...agent.subAgents);
|
|
111
|
+
if (!agent.parentAgent || !(0, import_llm_agent.isLlmAgent)(agent.parentAgent)) {
|
|
112
|
+
return targets;
|
|
113
|
+
}
|
|
114
|
+
if (!agent.disallowTransferToParent) {
|
|
115
|
+
targets.push(agent.parentAgent);
|
|
116
|
+
}
|
|
117
|
+
if (!agent.disallowTransferToPeers) {
|
|
118
|
+
targets.push(
|
|
119
|
+
...agent.parentAgent.subAgents.filter(
|
|
120
|
+
(peerAgent) => peerAgent.name !== agent.name
|
|
121
|
+
)
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
return targets;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const AGENT_TRANSFER_LLM_REQUEST_PROCESSOR = new AgentTransferLlmRequestProcessor();
|
|
128
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
129
|
+
0 && (module.exports = {
|
|
130
|
+
AGENT_TRANSFER_LLM_REQUEST_PROCESSOR,
|
|
131
|
+
AgentTransferLlmRequestProcessor
|
|
132
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var basic_llm_request_processor_exports = {};
|
|
26
|
+
__export(basic_llm_request_processor_exports, {
|
|
27
|
+
BASIC_LLM_REQUEST_PROCESSOR: () => BASIC_LLM_REQUEST_PROCESSOR,
|
|
28
|
+
BasicLlmRequestProcessor: () => BasicLlmRequestProcessor
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(basic_llm_request_processor_exports);
|
|
31
|
+
var import_llm_request = require("../../models/llm_request.js");
|
|
32
|
+
var import_llm_agent = require("../llm_agent.js");
|
|
33
|
+
var import_base_llm_processor = require("./base_llm_processor.js");
|
|
34
|
+
/**
|
|
35
|
+
* @license
|
|
36
|
+
* Copyright 2025 Google LLC
|
|
37
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
38
|
+
*/
|
|
39
|
+
class BasicLlmRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
|
|
40
|
+
// eslint-disable-next-line require-yield
|
|
41
|
+
async *runAsync(invocationContext, llmRequest) {
|
|
42
|
+
var _a;
|
|
43
|
+
const agent = invocationContext.agent;
|
|
44
|
+
if (!(0, import_llm_agent.isLlmAgent)(agent)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
llmRequest.model = agent.canonicalModel.model;
|
|
48
|
+
llmRequest.config = { ...(_a = agent.generateContentConfig) != null ? _a : {} };
|
|
49
|
+
if (agent.outputSchema) {
|
|
50
|
+
(0, import_llm_request.setOutputSchema)(llmRequest, agent.outputSchema);
|
|
51
|
+
}
|
|
52
|
+
if (invocationContext.runConfig) {
|
|
53
|
+
llmRequest.liveConnectConfig.responseModalities = invocationContext.runConfig.responseModalities;
|
|
54
|
+
llmRequest.liveConnectConfig.speechConfig = invocationContext.runConfig.speechConfig;
|
|
55
|
+
llmRequest.liveConnectConfig.outputAudioTranscription = invocationContext.runConfig.outputAudioTranscription;
|
|
56
|
+
llmRequest.liveConnectConfig.inputAudioTranscription = invocationContext.runConfig.inputAudioTranscription;
|
|
57
|
+
llmRequest.liveConnectConfig.realtimeInputConfig = invocationContext.runConfig.realtimeInputConfig;
|
|
58
|
+
llmRequest.liveConnectConfig.enableAffectiveDialog = invocationContext.runConfig.enableAffectiveDialog;
|
|
59
|
+
llmRequest.liveConnectConfig.proactivity = invocationContext.runConfig.proactivity;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const BASIC_LLM_REQUEST_PROCESSOR = new BasicLlmRequestProcessor();
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
BASIC_LLM_REQUEST_PROCESSOR,
|
|
67
|
+
BasicLlmRequestProcessor
|
|
68
|
+
});
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var code_execution_request_processor_exports = {};
|
|
26
|
+
__export(code_execution_request_processor_exports, {
|
|
27
|
+
CODE_EXECUTION_REQUEST_PROCESSOR: () => CODE_EXECUTION_REQUEST_PROCESSOR,
|
|
28
|
+
CodeExecutionRequestProcessor: () => CodeExecutionRequestProcessor,
|
|
29
|
+
CodeExecutionResponseProcessor: () => CodeExecutionResponseProcessor,
|
|
30
|
+
responseProcessor: () => responseProcessor
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(code_execution_request_processor_exports);
|
|
33
|
+
var import_lodash_es = require("lodash-es");
|
|
34
|
+
var import_base_code_executor = require("../../code_executors/base_code_executor.js");
|
|
35
|
+
var import_built_in_code_executor = require("../../code_executors/built_in_code_executor.js");
|
|
36
|
+
var import_code_execution_utils = require("../../code_executors/code_execution_utils.js");
|
|
37
|
+
var import_code_executor_context = require("../../code_executors/code_executor_context.js");
|
|
38
|
+
var import_event = require("../../events/event.js");
|
|
39
|
+
var import_event_actions = require("../../events/event_actions.js");
|
|
40
|
+
var import_state = require("../../sessions/state.js");
|
|
41
|
+
var import_env_aware_utils = require("../../utils/env_aware_utils.js");
|
|
42
|
+
var import_llm_agent = require("../llm_agent.js");
|
|
43
|
+
var import_base_llm_processor = require("./base_llm_processor.js");
|
|
44
|
+
/**
|
|
45
|
+
* @license
|
|
46
|
+
* Copyright 2025 Google LLC
|
|
47
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
48
|
+
*/
|
|
49
|
+
class CodeExecutionRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
|
|
50
|
+
async *runAsync(invocationContext, llmRequest) {
|
|
51
|
+
if (!(0, import_llm_agent.isLlmAgent)(invocationContext.agent)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (!invocationContext.agent.codeExecutor) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
for await (const event of runPreProcessor(invocationContext, llmRequest)) {
|
|
58
|
+
yield event;
|
|
59
|
+
}
|
|
60
|
+
if (!(0, import_base_code_executor.isBaseCodeExecutor)(invocationContext.agent.codeExecutor)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
for (const content of llmRequest.contents) {
|
|
64
|
+
const delimeters = invocationContext.agent.codeExecutor.codeBlockDelimiters.length ? invocationContext.agent.codeExecutor.codeBlockDelimiters[0] : ["", ""];
|
|
65
|
+
(0, import_code_execution_utils.convertCodeExecutionParts)(
|
|
66
|
+
content,
|
|
67
|
+
delimeters,
|
|
68
|
+
invocationContext.agent.codeExecutor.executionResultDelimiters
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const DATA_FILE_UTIL_MAP = {
|
|
74
|
+
"text/csv": {
|
|
75
|
+
extension: ".csv",
|
|
76
|
+
loaderCodeTemplate: "pd.read_csv('{filename}')"
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const DATA_FILE_HELPER_LIB = `
|
|
80
|
+
import pandas as pd
|
|
81
|
+
|
|
82
|
+
def explore_df(df: pd.DataFrame) -> None:
|
|
83
|
+
"""Prints some information about a pandas DataFrame."""
|
|
84
|
+
|
|
85
|
+
with pd.option_context(
|
|
86
|
+
'display.max_columns', None, 'display.expand_frame_repr', False
|
|
87
|
+
):
|
|
88
|
+
# Print the column names to never encounter KeyError when selecting one.
|
|
89
|
+
df_dtypes = df.dtypes
|
|
90
|
+
|
|
91
|
+
# Obtain information about data types and missing values.
|
|
92
|
+
df_nulls = (len(df) - df.isnull().sum()).apply(
|
|
93
|
+
lambda x: f'{x} / {df.shape[0]} non-null'
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
# Explore unique total values in columns using \`.unique()\`.
|
|
97
|
+
df_unique_count = df.apply(lambda x: len(x.unique()))
|
|
98
|
+
|
|
99
|
+
# Explore unique values in columns using \`.unique()\`.
|
|
100
|
+
df_unique = df.apply(lambda x: crop(str(list(x.unique()))))
|
|
101
|
+
|
|
102
|
+
df_info = pd.concat(
|
|
103
|
+
(
|
|
104
|
+
df_dtypes.rename('Dtype'),
|
|
105
|
+
df_nulls.rename('Non-Null Count'),
|
|
106
|
+
df_unique_count.rename('Unique Values Count'),
|
|
107
|
+
df_unique.rename('Unique Values'),
|
|
108
|
+
),
|
|
109
|
+
axis=1,
|
|
110
|
+
)
|
|
111
|
+
df_info.index.name = 'Columns'
|
|
112
|
+
print(f"""Total rows: {df.shape[0]}
|
|
113
|
+
Total columns: {df.shape[1]}
|
|
114
|
+
|
|
115
|
+
{df_info}""")
|
|
116
|
+
`;
|
|
117
|
+
class CodeExecutionResponseProcessor {
|
|
118
|
+
/**
|
|
119
|
+
* Processes the LLM response asynchronously.
|
|
120
|
+
*
|
|
121
|
+
* @param invocationContext The invocation context
|
|
122
|
+
* @param llmResponse The LLM response to process
|
|
123
|
+
* @returns An async generator yielding events
|
|
124
|
+
*/
|
|
125
|
+
async *runAsync(invocationContext, llmResponse) {
|
|
126
|
+
if (llmResponse.partial) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
for await (const event of runPostProcessor(
|
|
130
|
+
invocationContext,
|
|
131
|
+
llmResponse
|
|
132
|
+
)) {
|
|
133
|
+
yield event;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const responseProcessor = new CodeExecutionResponseProcessor();
|
|
138
|
+
async function* runPreProcessor(invocationContext, llmRequest) {
|
|
139
|
+
const agent = invocationContext.agent;
|
|
140
|
+
if (!(0, import_llm_agent.isLlmAgent)(agent)) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const codeExecutor = agent.codeExecutor;
|
|
144
|
+
if (!codeExecutor || !(0, import_base_code_executor.isBaseCodeExecutor)(codeExecutor)) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if ((0, import_built_in_code_executor.isBuiltInCodeExecutor)(codeExecutor)) {
|
|
148
|
+
codeExecutor.processLlmRequest(llmRequest);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (!codeExecutor.optimizeDataFile) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const codeExecutorContext = new import_code_executor_context.CodeExecutorContext(
|
|
155
|
+
new import_state.State(invocationContext.session.state)
|
|
156
|
+
);
|
|
157
|
+
if (codeExecutorContext.getErrorCount(invocationContext.invocationId) >= codeExecutor.errorRetryAttempts) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const allInputFiles = extractAndReplaceInlineFiles(
|
|
161
|
+
codeExecutorContext,
|
|
162
|
+
llmRequest
|
|
163
|
+
);
|
|
164
|
+
const processedFileNames = new Set(
|
|
165
|
+
codeExecutorContext.getProcessedFileNames()
|
|
166
|
+
);
|
|
167
|
+
const filesToProcess = allInputFiles.filter(
|
|
168
|
+
(f) => !processedFileNames.has(f.name)
|
|
169
|
+
);
|
|
170
|
+
for (const file of filesToProcess) {
|
|
171
|
+
const codeStr = getDataFilePreprocessingCode(file);
|
|
172
|
+
if (!codeStr) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const codeContent = {
|
|
176
|
+
role: "model",
|
|
177
|
+
parts: [
|
|
178
|
+
{ text: `Processing input file: \`${file.name}\`` },
|
|
179
|
+
(0, import_code_execution_utils.buildExecutableCodePart)(codeStr)
|
|
180
|
+
]
|
|
181
|
+
};
|
|
182
|
+
llmRequest.contents.push((0, import_lodash_es.cloneDeep)(codeContent));
|
|
183
|
+
yield (0, import_event.createEvent)({
|
|
184
|
+
invocationId: invocationContext.invocationId,
|
|
185
|
+
author: agent.name,
|
|
186
|
+
branch: invocationContext.branch,
|
|
187
|
+
content: codeContent
|
|
188
|
+
});
|
|
189
|
+
const executionId = getOrSetExecutionId(
|
|
190
|
+
invocationContext,
|
|
191
|
+
codeExecutorContext
|
|
192
|
+
);
|
|
193
|
+
const codeExecutionResult = await codeExecutor.executeCode({
|
|
194
|
+
invocationContext,
|
|
195
|
+
codeExecutionInput: {
|
|
196
|
+
code: codeStr,
|
|
197
|
+
inputFiles: [file],
|
|
198
|
+
executionId
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
codeExecutorContext.updateCodeExecutionResult({
|
|
202
|
+
invocationId: invocationContext.invocationId,
|
|
203
|
+
code: codeStr,
|
|
204
|
+
resultStdout: codeExecutionResult.stdout,
|
|
205
|
+
resultStderr: codeExecutionResult.stderr
|
|
206
|
+
});
|
|
207
|
+
codeExecutorContext.addProcessedFileNames([file.name]);
|
|
208
|
+
const executionResultEvent = await postProcessCodeExecutionResult(
|
|
209
|
+
invocationContext,
|
|
210
|
+
codeExecutorContext,
|
|
211
|
+
codeExecutionResult
|
|
212
|
+
);
|
|
213
|
+
yield executionResultEvent;
|
|
214
|
+
llmRequest.contents.push((0, import_lodash_es.cloneDeep)(executionResultEvent.content));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
async function* runPostProcessor(invocationContext, llmResponse) {
|
|
218
|
+
const agent = invocationContext.agent;
|
|
219
|
+
if (!(0, import_llm_agent.isLlmAgent)(agent)) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const codeExecutor = agent.codeExecutor;
|
|
223
|
+
if (!codeExecutor || !(0, import_base_code_executor.isBaseCodeExecutor)(codeExecutor)) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (!llmResponse || !llmResponse.content) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if ((0, import_built_in_code_executor.isBuiltInCodeExecutor)(codeExecutor)) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const codeExecutorContext = new import_code_executor_context.CodeExecutorContext(
|
|
233
|
+
new import_state.State(invocationContext.session.state)
|
|
234
|
+
);
|
|
235
|
+
if (codeExecutorContext.getErrorCount(invocationContext.invocationId) >= codeExecutor.errorRetryAttempts) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const responseContent = llmResponse.content;
|
|
239
|
+
const codeStr = (0, import_code_execution_utils.extractCodeAndTruncateContent)(
|
|
240
|
+
responseContent,
|
|
241
|
+
codeExecutor.codeBlockDelimiters
|
|
242
|
+
);
|
|
243
|
+
if (!codeStr) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
yield (0, import_event.createEvent)({
|
|
247
|
+
invocationId: invocationContext.invocationId,
|
|
248
|
+
author: agent.name,
|
|
249
|
+
branch: invocationContext.branch,
|
|
250
|
+
content: responseContent
|
|
251
|
+
});
|
|
252
|
+
const executionId = getOrSetExecutionId(
|
|
253
|
+
invocationContext,
|
|
254
|
+
codeExecutorContext
|
|
255
|
+
);
|
|
256
|
+
const codeExecutionResult = await codeExecutor.executeCode({
|
|
257
|
+
invocationContext,
|
|
258
|
+
codeExecutionInput: {
|
|
259
|
+
code: codeStr,
|
|
260
|
+
inputFiles: codeExecutorContext.getInputFiles(),
|
|
261
|
+
executionId
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
codeExecutorContext.updateCodeExecutionResult({
|
|
265
|
+
invocationId: invocationContext.invocationId,
|
|
266
|
+
code: codeStr,
|
|
267
|
+
resultStdout: codeExecutionResult.stdout,
|
|
268
|
+
resultStderr: codeExecutionResult.stderr
|
|
269
|
+
});
|
|
270
|
+
yield await postProcessCodeExecutionResult(
|
|
271
|
+
invocationContext,
|
|
272
|
+
codeExecutorContext,
|
|
273
|
+
codeExecutionResult
|
|
274
|
+
);
|
|
275
|
+
llmResponse.content = void 0;
|
|
276
|
+
}
|
|
277
|
+
function extractAndReplaceInlineFiles(codeExecutorContext, llmRequest) {
|
|
278
|
+
var _a;
|
|
279
|
+
const allInputFiles = codeExecutorContext.getInputFiles();
|
|
280
|
+
const savedFileNames = new Set(allInputFiles.map((f) => f.name));
|
|
281
|
+
for (let i = 0; i < llmRequest.contents.length; i++) {
|
|
282
|
+
const content = llmRequest.contents[i];
|
|
283
|
+
if (content.role !== "user" || !content.parts) {
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
for (let j = 0; j < content.parts.length; j++) {
|
|
287
|
+
const part = content.parts[j];
|
|
288
|
+
const mimeType = (_a = part.inlineData) == null ? void 0 : _a.mimeType;
|
|
289
|
+
if (!mimeType || !part.inlineData || !DATA_FILE_UTIL_MAP[mimeType]) {
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
const fileName = `data_${i + 1}_${j + 1}${DATA_FILE_UTIL_MAP[mimeType].extension}`;
|
|
293
|
+
part.text = `
|
|
294
|
+
Available file: \`${fileName}\`
|
|
295
|
+
`;
|
|
296
|
+
const file = {
|
|
297
|
+
name: fileName,
|
|
298
|
+
content: (0, import_env_aware_utils.base64Decode)(part.inlineData.data),
|
|
299
|
+
mimeType
|
|
300
|
+
};
|
|
301
|
+
if (!savedFileNames.has(fileName)) {
|
|
302
|
+
codeExecutorContext.addInputFiles([file]);
|
|
303
|
+
allInputFiles.push(file);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return allInputFiles;
|
|
308
|
+
}
|
|
309
|
+
function getOrSetExecutionId(invocationContext, codeExecutorContext) {
|
|
310
|
+
var _a;
|
|
311
|
+
const agent = invocationContext.agent;
|
|
312
|
+
if (!(0, import_llm_agent.isLlmAgent)(agent) || !((_a = agent.codeExecutor) == null ? void 0 : _a.stateful)) {
|
|
313
|
+
return void 0;
|
|
314
|
+
}
|
|
315
|
+
let executionId = codeExecutorContext.getExecutionId();
|
|
316
|
+
if (!executionId) {
|
|
317
|
+
executionId = invocationContext.session.id;
|
|
318
|
+
codeExecutorContext.setExecutionId(executionId);
|
|
319
|
+
}
|
|
320
|
+
return executionId;
|
|
321
|
+
}
|
|
322
|
+
async function postProcessCodeExecutionResult(invocationContext, codeExecutorContext, codeExecutionResult) {
|
|
323
|
+
if (!invocationContext.artifactService) {
|
|
324
|
+
throw new Error("Artifact service is not initialized.");
|
|
325
|
+
}
|
|
326
|
+
const resultContent = {
|
|
327
|
+
role: "model",
|
|
328
|
+
parts: [(0, import_code_execution_utils.buildCodeExecutionResultPart)(codeExecutionResult)]
|
|
329
|
+
};
|
|
330
|
+
const eventActions = (0, import_event_actions.createEventActions)({
|
|
331
|
+
stateDelta: codeExecutorContext.getStateDelta()
|
|
332
|
+
});
|
|
333
|
+
if (codeExecutionResult.stderr) {
|
|
334
|
+
codeExecutorContext.incrementErrorCount(invocationContext.invocationId);
|
|
335
|
+
} else {
|
|
336
|
+
codeExecutorContext.resetErrorCount(invocationContext.invocationId);
|
|
337
|
+
}
|
|
338
|
+
for (const outputFile of codeExecutionResult.outputFiles) {
|
|
339
|
+
const version = await invocationContext.artifactService.saveArtifact({
|
|
340
|
+
appName: invocationContext.appName || "",
|
|
341
|
+
userId: invocationContext.userId || "",
|
|
342
|
+
sessionId: invocationContext.session.id,
|
|
343
|
+
filename: outputFile.name,
|
|
344
|
+
artifact: {
|
|
345
|
+
inlineData: { data: outputFile.content, mimeType: outputFile.mimeType }
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
eventActions.artifactDelta[outputFile.name] = version;
|
|
349
|
+
}
|
|
350
|
+
return (0, import_event.createEvent)({
|
|
351
|
+
invocationId: invocationContext.invocationId,
|
|
352
|
+
author: invocationContext.agent.name,
|
|
353
|
+
branch: invocationContext.branch,
|
|
354
|
+
content: resultContent,
|
|
355
|
+
actions: eventActions
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
function getDataFilePreprocessingCode(file) {
|
|
359
|
+
function getNormalizedFileName(fileName) {
|
|
360
|
+
const [varName2] = fileName.split(".");
|
|
361
|
+
let normalizedName = varName2.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
362
|
+
if (/^\d/.test(normalizedName)) {
|
|
363
|
+
normalizedName = "_" + normalizedName;
|
|
364
|
+
}
|
|
365
|
+
return normalizedName;
|
|
366
|
+
}
|
|
367
|
+
if (!DATA_FILE_UTIL_MAP[file.mimeType]) {
|
|
368
|
+
return void 0;
|
|
369
|
+
}
|
|
370
|
+
const varName = getNormalizedFileName(file.name);
|
|
371
|
+
const loaderCode = DATA_FILE_UTIL_MAP[file.mimeType].loaderCodeTemplate.replace("{filename}", file.name);
|
|
372
|
+
return `
|
|
373
|
+
${DATA_FILE_HELPER_LIB}
|
|
374
|
+
|
|
375
|
+
# Load the dataframe.
|
|
376
|
+
${varName} = ${loaderCode}
|
|
377
|
+
|
|
378
|
+
# Use \`explore_df\` to guide my analysis.
|
|
379
|
+
explore_df(${varName})
|
|
380
|
+
`;
|
|
381
|
+
}
|
|
382
|
+
const CODE_EXECUTION_REQUEST_PROCESSOR = new CodeExecutionRequestProcessor();
|
|
383
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
384
|
+
0 && (module.exports = {
|
|
385
|
+
CODE_EXECUTION_REQUEST_PROCESSOR,
|
|
386
|
+
CodeExecutionRequestProcessor,
|
|
387
|
+
CodeExecutionResponseProcessor,
|
|
388
|
+
responseProcessor
|
|
389
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var content_request_processor_exports = {};
|
|
26
|
+
__export(content_request_processor_exports, {
|
|
27
|
+
CONTENT_REQUEST_PROCESSOR: () => CONTENT_REQUEST_PROCESSOR,
|
|
28
|
+
ContentRequestProcessor: () => ContentRequestProcessor
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(content_request_processor_exports);
|
|
31
|
+
var import_content_processor_utils = require("../content_processor_utils.js");
|
|
32
|
+
var import_llm_agent = require("../llm_agent.js");
|
|
33
|
+
/**
|
|
34
|
+
* @license
|
|
35
|
+
* Copyright 2025 Google LLC
|
|
36
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
37
|
+
*/
|
|
38
|
+
class ContentRequestProcessor {
|
|
39
|
+
// eslint-disable-next-line require-yield
|
|
40
|
+
async *runAsync(invocationContext, llmRequest) {
|
|
41
|
+
const agent = invocationContext.agent;
|
|
42
|
+
if (!agent || !(0, import_llm_agent.isLlmAgent)(agent)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (agent.includeContents === "default") {
|
|
46
|
+
llmRequest.contents = (0, import_content_processor_utils.getContents)(
|
|
47
|
+
invocationContext.session.events,
|
|
48
|
+
agent.name,
|
|
49
|
+
invocationContext.branch
|
|
50
|
+
);
|
|
51
|
+
} else {
|
|
52
|
+
llmRequest.contents = (0, import_content_processor_utils.getCurrentTurnContents)(
|
|
53
|
+
invocationContext.session.events,
|
|
54
|
+
agent.name,
|
|
55
|
+
invocationContext.branch
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const CONTENT_REQUEST_PROCESSOR = new ContentRequestProcessor();
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
CONTENT_REQUEST_PROCESSOR,
|
|
65
|
+
ContentRequestProcessor
|
|
66
|
+
});
|