@google/adk 2.2.1 → 2.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/a2a/a2a_remote_agent.js +4 -1
- package/dist/cjs/a2a/agent_card.js +102 -26
- package/dist/cjs/a2a/agent_to_a2a.js +1 -1
- package/dist/cjs/agents/agent_engine_client.js +172 -0
- package/dist/cjs/agents/base_agent.js +20 -4
- package/dist/cjs/agents/functions.js +227 -25
- package/dist/cjs/agents/instructions.js +6 -2
- package/dist/cjs/agents/invocation_context.js +26 -4
- package/dist/cjs/agents/langgraph_agent.js +152 -0
- package/dist/cjs/agents/llm_agent.js +194 -107
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +1 -1
- package/dist/cjs/agents/processors/code_execution_request_processor.js +18 -6
- package/dist/cjs/agents/processors/content_processor_utils.js +38 -10
- package/dist/cjs/agents/processors/content_request_processor.js +34 -2
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/cjs/agents/processors/nl_planning_processor.js +12 -3
- package/dist/cjs/artifacts/in_memory_artifact_service.js +14 -0
- package/dist/cjs/auth/auth_handler.js +37 -5
- package/dist/cjs/auth/auth_schemes.js +9 -0
- package/dist/cjs/cli/cli_eval.js +532 -0
- package/dist/cjs/cli/utils/envs.js +116 -0
- package/dist/cjs/cli/utils/evals.js +137 -0
- package/dist/cjs/cli/utils/logs.js +150 -0
- package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +7 -2
- package/dist/cjs/code_executors/code_execution_utils.js +48 -16
- package/dist/cjs/code_executors/code_executor_context.js +6 -2
- package/dist/cjs/code_executors/container_code_executor.js +27 -16
- package/dist/cjs/code_executors/unsafe_local_code_executor.js +6 -1
- package/dist/cjs/common.js +61 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +12 -10
- package/dist/cjs/context/token_based_context_compactor.js +2 -1
- package/dist/cjs/errors/input_validation_error.js +3 -2
- package/dist/cjs/events/event.js +4 -2
- package/dist/cjs/examples/example_util.js +23 -2
- package/dist/cjs/flows/llm_flows/audio_transcriber.js +170 -0
- package/dist/cjs/index.js +104 -1
- package/dist/cjs/integrations/agent_registry/helpers.js +1 -1
- package/dist/cjs/models/gemini_llm_connection.js +16 -8
- package/dist/cjs/models/google_llm.js +13 -16
- package/dist/cjs/models/llm_response.js +9 -1
- package/dist/cjs/models/registry.js +1 -1
- package/dist/cjs/models/routed_llm.js +9 -8
- package/dist/cjs/planners/plan_re_act_planner.js +1 -1
- package/dist/cjs/plugins/base_plugin.js +13 -23
- package/dist/cjs/runner/in_memory_runner.js +6 -11
- package/dist/cjs/runner/runner.js +105 -33
- package/dist/cjs/sessions/base_session_service.js +14 -8
- package/dist/cjs/sessions/database_session_service.js +50 -28
- package/dist/cjs/sessions/db/operations.js +1 -1
- package/dist/cjs/sessions/in_memory_session_service.js +3 -1
- package/dist/cjs/sessions/stale_session_error.js +59 -0
- package/dist/cjs/sessions/state.js +8 -4
- package/dist/cjs/sessions/vertex_ai_session_service.js +34 -15
- package/dist/cjs/skills/loader.js +52 -18
- package/dist/cjs/telemetry/setup.js +0 -1
- package/dist/cjs/telemetry/tracing.js +147 -73
- package/dist/cjs/tools/agent_tool.js +44 -0
- package/dist/cjs/tools/apihub_tool/apihub_toolset.js +137 -0
- package/dist/cjs/tools/apihub_tool/clients/apihub_client.js +272 -0
- package/dist/cjs/tools/apihub_tool/clients/secret_client.js +148 -0
- package/dist/cjs/tools/apihub_tool/clients/service_account.js +48 -0
- package/dist/cjs/tools/application_integration_tool/application_integration_toolset.js +263 -0
- package/dist/cjs/tools/application_integration_tool/clients/cloud_request.js +133 -0
- package/dist/cjs/tools/application_integration_tool/clients/connections_client.js +671 -0
- package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +223 -0
- package/dist/cjs/tools/application_integration_tool/integration_connector_tool.js +184 -0
- package/dist/cjs/tools/example_tool.js +10 -0
- package/dist/cjs/tools/function_tool.js +319 -0
- package/dist/cjs/tools/google_api_tool/google_api_tool.js +100 -0
- package/dist/cjs/tools/google_api_tool/google_api_toolset.js +173 -0
- package/dist/cjs/tools/google_api_tool/google_api_toolsets.js +124 -0
- package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +440 -0
- package/dist/cjs/tools/google_api_tool/index.js +61 -0
- package/dist/cjs/tools/load_artifacts_tool.js +12 -6
- package/dist/cjs/tools/load_memory_tool.js +12 -10
- package/dist/cjs/tools/mcp/index.js +12 -0
- package/dist/cjs/tools/mcp/mcp_session_manager.js +25 -0
- package/dist/cjs/tools/mcp/mcp_toolset.js +1 -14
- package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +1 -2
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +46 -2
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +4 -3
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +20 -6
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +17 -6
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +14 -2
- package/dist/cjs/tools/openapi_tool/openapi_toolset.js +7 -13
- package/dist/cjs/tools/openapi_tool/rest_api_tool.js +17 -1
- package/dist/cjs/tools/retrieval/base_retrieval_tool.js +18 -3
- package/dist/cjs/tools/toolbox_toolset.js +174 -0
- package/dist/cjs/tools/webmcp/webmcp_toolset.js +1 -14
- package/dist/cjs/utils/client_labels.js +19 -2
- package/dist/cjs/utils/env_aware_utils.js +6 -8
- package/dist/cjs/utils/error_utils.js +11 -11
- package/dist/cjs/utils/failover_utils.js +1 -1
- package/dist/cjs/utils/file_extension_utils.js +11 -0
- package/dist/cjs/utils/file_utils.js +2 -24
- package/dist/cjs/utils/gemini_schema_util.js +28 -7
- package/dist/cjs/utils/json_utils.js +49 -0
- package/dist/cjs/utils/live_connection_utils.js +4 -5
- package/dist/cjs/utils/logger_node.js +11 -1
- package/dist/cjs/utils/object_notation_utils.js +6 -3
- package/dist/cjs/utils/output_schema_utils.js +5 -2
- package/dist/cjs/utils/streaming_utils.js +12 -12
- package/dist/cjs/utils/task.js +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_remote_agent.js +4 -1
- package/dist/esm/a2a/agent_card.js +103 -27
- package/dist/esm/a2a/agent_to_a2a.js +5 -2
- package/dist/esm/agents/agent_engine_client.js +144 -0
- package/dist/esm/agents/base_agent.js +20 -4
- package/dist/esm/agents/functions.js +226 -25
- package/dist/esm/agents/instructions.js +6 -2
- package/dist/esm/agents/invocation_context.js +24 -4
- package/dist/esm/agents/langgraph_agent.js +123 -0
- package/dist/esm/agents/llm_agent.js +204 -110
- package/dist/esm/agents/processors/basic_llm_request_processor.js +1 -1
- package/dist/esm/agents/processors/code_execution_request_processor.js +21 -8
- package/dist/esm/agents/processors/content_processor_utils.js +38 -10
- package/dist/esm/agents/processors/content_request_processor.js +34 -2
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/esm/agents/processors/nl_planning_processor.js +12 -3
- package/dist/esm/artifacts/in_memory_artifact_service.js +14 -0
- package/dist/esm/auth/auth_handler.js +37 -5
- package/dist/esm/auth/auth_schemes.js +8 -0
- package/dist/esm/cli/cli_eval.js +510 -0
- package/dist/esm/cli/utils/envs.js +78 -0
- package/dist/esm/cli/utils/evals.js +109 -0
- package/dist/esm/cli/utils/logs.js +111 -0
- package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +7 -2
- package/dist/esm/code_executors/code_execution_utils.js +46 -16
- package/dist/esm/code_executors/code_executor_context.js +5 -2
- package/dist/esm/code_executors/container_code_executor.js +27 -16
- package/dist/esm/code_executors/unsafe_local_code_executor.js +6 -1
- package/dist/esm/common.js +65 -4
- package/dist/esm/context/summarizers/llm_summarizer.js +12 -10
- package/dist/esm/context/token_based_context_compactor.js +2 -1
- package/dist/esm/errors/input_validation_error.js +3 -2
- package/dist/esm/events/event.js +4 -2
- package/dist/esm/examples/example_util.js +21 -1
- package/dist/esm/flows/llm_flows/audio_transcriber.js +142 -0
- package/dist/esm/index.js +114 -2
- package/dist/esm/integrations/agent_registry/helpers.js +1 -1
- package/dist/esm/models/gemini_llm_connection.js +16 -8
- package/dist/esm/models/google_llm.js +14 -17
- package/dist/esm/models/llm_response.js +9 -1
- package/dist/esm/models/registry.js +1 -1
- package/dist/esm/models/routed_llm.js +9 -8
- package/dist/esm/planners/plan_re_act_planner.js +1 -1
- package/dist/esm/plugins/base_plugin.js +13 -23
- package/dist/esm/runner/in_memory_runner.js +6 -11
- package/dist/esm/runner/runner.js +105 -33
- package/dist/esm/sessions/base_session_service.js +12 -7
- package/dist/esm/sessions/database_session_service.js +49 -28
- package/dist/esm/sessions/db/operations.js +1 -1
- package/dist/esm/sessions/in_memory_session_service.js +3 -1
- package/dist/esm/sessions/stale_session_error.js +31 -0
- package/dist/esm/sessions/state.js +8 -4
- package/dist/esm/sessions/vertex_ai_session_service.js +34 -15
- package/dist/esm/skills/loader.js +51 -17
- package/dist/esm/telemetry/setup.js +1 -2
- package/dist/esm/telemetry/tracing.js +151 -74
- package/dist/esm/tools/agent_tool.js +44 -0
- package/dist/esm/tools/apihub_tool/apihub_toolset.js +101 -0
- package/dist/esm/tools/apihub_tool/clients/apihub_client.js +244 -0
- package/dist/esm/tools/apihub_tool/clients/secret_client.js +132 -0
- package/dist/esm/tools/apihub_tool/clients/service_account.js +21 -0
- package/dist/esm/tools/application_integration_tool/application_integration_toolset.js +245 -0
- package/dist/esm/tools/application_integration_tool/clients/cloud_request.js +103 -0
- package/dist/esm/tools/application_integration_tool/clients/connections_client.js +629 -0
- package/dist/esm/tools/application_integration_tool/clients/integration_client.js +219 -0
- package/dist/esm/tools/application_integration_tool/integration_connector_tool.js +158 -0
- package/dist/esm/tools/example_tool.js +13 -1
- package/dist/esm/tools/function_tool.js +316 -0
- package/dist/esm/tools/google_api_tool/google_api_tool.js +73 -0
- package/dist/esm/tools/google_api_tool/google_api_toolset.js +146 -0
- package/dist/esm/tools/google_api_tool/google_api_toolsets.js +94 -0
- package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +393 -0
- package/dist/esm/tools/google_api_tool/index.js +31 -0
- package/dist/esm/tools/load_artifacts_tool.js +10 -5
- package/dist/esm/tools/load_memory_tool.js +12 -10
- package/dist/esm/tools/mcp/index.js +6 -0
- package/dist/esm/tools/mcp/mcp_session_manager.js +25 -0
- package/dist/esm/tools/mcp/mcp_toolset.js +1 -14
- package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +1 -2
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +50 -3
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +4 -3
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +20 -6
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +17 -6
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -2
- package/dist/esm/tools/openapi_tool/openapi_toolset.js +6 -12
- package/dist/esm/tools/openapi_tool/rest_api_tool.js +17 -1
- package/dist/esm/tools/retrieval/base_retrieval_tool.js +16 -2
- package/dist/esm/tools/toolbox_toolset.js +148 -0
- package/dist/esm/tools/webmcp/webmcp_toolset.js +1 -14
- package/dist/esm/utils/client_labels.js +19 -2
- package/dist/esm/utils/env_aware_utils.js +6 -8
- package/dist/esm/utils/error_utils.js +9 -10
- package/dist/esm/utils/failover_utils.js +1 -1
- package/dist/esm/utils/file_extension_utils.js +11 -0
- package/dist/esm/utils/file_utils.js +2 -23
- package/dist/esm/utils/gemini_schema_util.js +27 -7
- package/dist/esm/utils/json_utils.js +21 -0
- package/dist/esm/utils/live_connection_utils.js +4 -5
- package/dist/esm/utils/logger_node.js +11 -1
- package/dist/esm/utils/object_notation_utils.js +4 -2
- package/dist/esm/utils/output_schema_utils.js +5 -2
- package/dist/esm/utils/streaming_utils.js +11 -11
- package/dist/esm/utils/task.js +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +9 -0
- package/dist/types/a2a/agent_card.d.ts +44 -1
- package/dist/types/a2a/agent_to_a2a.d.ts +9 -0
- package/dist/types/a2a/index.d.ts +1 -0
- package/dist/types/agents/agent_engine_client.d.ts +37 -0
- package/dist/types/agents/base_agent.d.ts +12 -0
- package/dist/types/agents/functions.d.ts +33 -1
- package/dist/types/agents/invocation_context.d.ts +20 -1
- package/dist/types/agents/langgraph_agent.d.ts +153 -0
- package/dist/types/agents/llm_agent.d.ts +5 -1
- package/dist/types/agents/processors/content_processor_utils.d.ts +4 -2
- package/dist/types/agents/processors/nl_planning_processor.d.ts +2 -1
- package/dist/types/auth/auth_handler.d.ts +28 -1
- package/dist/types/auth/auth_schemes.d.ts +13 -0
- package/dist/types/cli/cli_eval.d.ts +173 -0
- package/dist/types/cli/utils/envs.d.ts +23 -0
- package/dist/types/cli/utils/evals.d.ts +47 -0
- package/dist/types/cli/utils/logs.d.ts +38 -0
- package/dist/types/code_executors/code_execution_utils.d.ts +39 -0
- package/dist/types/code_executors/code_executor_context.d.ts +1 -0
- package/dist/types/code_executors/container_code_executor.d.ts +17 -5
- package/dist/types/common.d.ts +24 -5
- package/dist/types/errors/input_validation_error.d.ts +2 -1
- package/dist/types/events/event.d.ts +4 -0
- package/dist/types/examples/example_util.d.ts +17 -0
- package/dist/types/flows/llm_flows/audio_transcriber.d.ts +85 -0
- package/dist/types/index.d.ts +19 -2
- package/dist/types/models/gemini_llm_connection.d.ts +6 -7
- package/dist/types/models/routed_llm.d.ts +1 -1
- package/dist/types/plugins/base_plugin.d.ts +0 -10
- package/dist/types/runner/in_memory_runner.d.ts +2 -1
- package/dist/types/runner/runner.d.ts +34 -0
- package/dist/types/sessions/base_session_service.d.ts +5 -0
- package/dist/types/sessions/database_session_service.d.ts +17 -1
- package/dist/types/sessions/stale_session_error.d.ts +21 -0
- package/dist/types/sessions/state.d.ts +5 -1
- package/dist/types/sessions/vertex_ai_session_service.d.ts +8 -0
- package/dist/types/skills/loader.d.ts +3 -2
- package/dist/types/skills/skill.d.ts +1 -1
- package/dist/types/telemetry/tracing.d.ts +20 -4
- package/dist/types/tools/apihub_tool/apihub_toolset.d.ts +115 -0
- package/dist/types/tools/apihub_tool/clients/apihub_client.d.ts +142 -0
- package/dist/types/tools/apihub_tool/clients/secret_client.d.ts +55 -0
- package/dist/types/tools/apihub_tool/clients/service_account.d.ts +11 -0
- package/dist/types/tools/application_integration_tool/application_integration_toolset.d.ts +109 -0
- package/dist/types/tools/application_integration_tool/clients/cloud_request.d.ts +53 -0
- package/dist/types/tools/application_integration_tool/clients/connections_client.d.ts +229 -0
- package/dist/types/tools/application_integration_tool/clients/integration_client.d.ts +72 -0
- package/dist/types/tools/application_integration_tool/integration_connector_tool.d.ts +70 -0
- package/dist/types/tools/base_toolset.d.ts +6 -5
- package/dist/types/tools/example_tool.d.ts +10 -0
- package/dist/types/tools/function_tool.d.ts +32 -0
- package/dist/types/tools/google_api_tool/google_api_tool.d.ts +37 -0
- package/dist/types/tools/google_api_tool/google_api_toolset.d.ts +55 -0
- package/dist/types/tools/google_api_tool/google_api_toolsets.d.ts +48 -0
- package/dist/types/tools/google_api_tool/googleapi_to_openapi_converter.d.ts +165 -0
- package/dist/types/tools/google_api_tool/index.d.ts +10 -0
- package/dist/types/tools/load_artifacts_tool.d.ts +14 -1
- package/dist/types/tools/load_memory_tool.d.ts +23 -1
- package/dist/types/tools/mcp/index.d.ts +3 -0
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +34 -1
- package/dist/types/tools/mcp/mcp_toolset.d.ts +15 -0
- package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +19 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +18 -1
- package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +12 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +8 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +2 -1
- package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +5 -0
- package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +10 -0
- package/dist/types/tools/retrieval/base_retrieval_tool.d.ts +15 -0
- package/dist/types/tools/toolbox_toolset.d.ts +159 -0
- package/dist/types/utils/client_labels.d.ts +2 -1
- package/dist/types/utils/env_aware_utils.d.ts +18 -2
- package/dist/types/utils/error_utils.d.ts +7 -0
- package/dist/types/utils/file_utils.d.ts +6 -1
- package/dist/types/utils/gemini_schema_util.d.ts +9 -2
- package/dist/types/utils/json_utils.d.ts +11 -0
- package/dist/types/utils/object_notation_utils.d.ts +7 -0
- package/dist/types/utils/output_schema_utils.d.ts +3 -2
- package/dist/types/utils/simple_zod_to_json.d.ts +1 -2
- package/dist/types/utils/streaming_utils.d.ts +11 -4
- package/dist/types/version.d.ts +1 -1
- package/dist/web/index_web.js +117 -110
- package/dist/web/index_web.js.map +4 -4
- package/package.json +38 -26
- package/dist/cjs/models/gemini_continuation.js +0 -232
- package/dist/esm/models/gemini_continuation.js +0 -205
- package/dist/types/models/gemini_continuation.d.ts +0 -59
|
@@ -29,6 +29,7 @@ __export(llm_agent_exports, {
|
|
|
29
29
|
isLlmAgent: () => isLlmAgent
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(llm_agent_exports);
|
|
32
|
+
var import_genai = require("@google/genai");
|
|
32
33
|
var import_api = require("@opentelemetry/api");
|
|
33
34
|
var import_finish_task_tool = require("../tools/finish_task_tool.js");
|
|
34
35
|
var import_function_tool = require("../tools/function_tool.js");
|
|
@@ -42,6 +43,7 @@ var import_base_llm = require("../models/base_llm.js");
|
|
|
42
43
|
var import_registry = require("../models/registry.js");
|
|
43
44
|
var import_built_in_planner = require("../planners/built_in_planner.js");
|
|
44
45
|
var import_base_tool = require("../tools/base_tool.js");
|
|
46
|
+
var import_base_toolset = require("../tools/base_toolset.js");
|
|
45
47
|
var import_logger = require("../utils/logger.js");
|
|
46
48
|
var import_output_schema_utils = require("../utils/output_schema_utils.js");
|
|
47
49
|
var import_context = require("./context.js");
|
|
@@ -52,6 +54,7 @@ var import_base_agent = require("./base_agent.js");
|
|
|
52
54
|
var import_functions = require("./functions.js");
|
|
53
55
|
var import_auth_preprocessor = require("../auth/auth_preprocessor.js");
|
|
54
56
|
var import_invocation_context = require("./invocation_context.js");
|
|
57
|
+
var import_live_request_queue = require("./live_request_queue.js");
|
|
55
58
|
var import_agent_transfer_llm_request_processor = require("./processors/agent_transfer_llm_request_processor.js");
|
|
56
59
|
var import_basic_llm_request_processor = require("./processors/basic_llm_request_processor.js");
|
|
57
60
|
var import_code_execution_request_processor = require("./processors/code_execution_request_processor.js");
|
|
@@ -120,6 +123,9 @@ function applyLiveRunConfig(runConfig, llmRequest) {
|
|
|
120
123
|
liveConfig[k] = runConfig[k];
|
|
121
124
|
}
|
|
122
125
|
}
|
|
126
|
+
if (runConfig.supportCfc) {
|
|
127
|
+
liveConfig.responseModalities = [import_genai.Modality.TEXT];
|
|
128
|
+
}
|
|
123
129
|
}
|
|
124
130
|
__name(applyLiveRunConfig, "applyLiveRunConfig");
|
|
125
131
|
const ADK_AGENT_NAME_LABEL_KEY = "adk_agent_name";
|
|
@@ -202,7 +208,9 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
202
208
|
}
|
|
203
209
|
}
|
|
204
210
|
this.responseProcessors = (_j = config.responseProcessors) != null ? _j : [
|
|
205
|
-
import_nl_planning_processor.NL_PLANNING_RESPONSE_PROCESSOR
|
|
211
|
+
import_nl_planning_processor.NL_PLANNING_RESPONSE_PROCESSOR,
|
|
212
|
+
// Runs the code blocks that a client-side code executor receives.
|
|
213
|
+
import_code_execution_request_processor.responseProcessor
|
|
206
214
|
];
|
|
207
215
|
const agentTransferDisabled = this.disallowTransferToParent && this.disallowTransferToPeers && !((_k = this.subAgents) == null ? void 0 : _k.length);
|
|
208
216
|
if (!agentTransferDisabled) {
|
|
@@ -465,14 +473,18 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
465
473
|
while (true) {
|
|
466
474
|
let lastEvent = void 0;
|
|
467
475
|
let stepHadToolCalls = false;
|
|
476
|
+
let stepTransferred = false;
|
|
468
477
|
for await (const event of this.runOneStepAsync(context2)) {
|
|
469
478
|
if ((_a2 = context2.abortSignal) == null ? void 0 : _a2.aborted) {
|
|
470
479
|
return;
|
|
471
480
|
}
|
|
472
481
|
lastEvent = event;
|
|
473
|
-
if ((0, import_event.getFunctionCalls)(event).length > 0 || (0, import_event.getFunctionResponses)(event).length > 0) {
|
|
482
|
+
if ((0, import_event.getFunctionCalls)(event).length > 0 || (0, import_event.getFunctionResponses)(event).length > 0 || !event.partial && (0, import_event.hasTrailingCodeExecutionResult)(event)) {
|
|
474
483
|
stepHadToolCalls = true;
|
|
475
484
|
}
|
|
485
|
+
if (event.author === this.name && event.actions.transferToAgent) {
|
|
486
|
+
stepTransferred = true;
|
|
487
|
+
}
|
|
476
488
|
this.maybeSaveOutputToState(event);
|
|
477
489
|
yield event;
|
|
478
490
|
}
|
|
@@ -480,7 +492,7 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
480
492
|
break;
|
|
481
493
|
}
|
|
482
494
|
const isEmptyMetadataEvent = lastEvent.author === this.name && !lastEvent.partial && (!((_b2 = lastEvent.content) == null ? void 0 : _b2.parts) || lastEvent.content.parts.length === 0) && (0, import_event_actions.isDefaultEventActions)(lastEvent.actions);
|
|
483
|
-
if ((0, import_event.isFinalResponse)(lastEvent) && !(isEmptyMetadataEvent && stepHadToolCalls)) {
|
|
495
|
+
if ((0, import_event.isFinalResponse)(lastEvent) && !(isEmptyMetadataEvent && stepHadToolCalls && !stepTransferred)) {
|
|
484
496
|
break;
|
|
485
497
|
}
|
|
486
498
|
if (lastEvent.partial) {
|
|
@@ -520,7 +532,7 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
520
532
|
* already holds the conversation state associated with the handle.
|
|
521
533
|
*/
|
|
522
534
|
async *runLiveFlow(invocationContext) {
|
|
523
|
-
var _a2, _b2, _c, _d;
|
|
535
|
+
var _a2, _b2, _c, _d, _e;
|
|
524
536
|
if (!invocationContext.liveRequestQueue) {
|
|
525
537
|
throw new Error("liveRequestQueue is required for LlmAgent.runLiveFlow.");
|
|
526
538
|
}
|
|
@@ -575,16 +587,29 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
575
587
|
throw err;
|
|
576
588
|
}
|
|
577
589
|
if (llmRequest.contents.length > 0 && !invocationContext.liveSessionResumptionHandle) {
|
|
578
|
-
await
|
|
590
|
+
await import_tracing.tracer.startActiveSpan("send_data", async (span) => {
|
|
591
|
+
try {
|
|
592
|
+
await connection.sendHistory(llmRequest.contents);
|
|
593
|
+
(0, import_tracing.traceSendData)({
|
|
594
|
+
invocationContext,
|
|
595
|
+
eventId: (0, import_event.createNewEventId)(),
|
|
596
|
+
data: llmRequest.contents
|
|
597
|
+
});
|
|
598
|
+
} finally {
|
|
599
|
+
span.end();
|
|
600
|
+
}
|
|
601
|
+
});
|
|
579
602
|
}
|
|
580
603
|
let sendError;
|
|
581
604
|
const sendAbort = new AbortController();
|
|
582
605
|
const combinedAbort = invocationContext.abortSignal ? AbortSignal.any([invocationContext.abortSignal, sendAbort.signal]) : sendAbort.signal;
|
|
606
|
+
(_d = invocationContext.activeStreamingTools) != null ? _d : invocationContext.activeStreamingTools = {};
|
|
583
607
|
const sendTask = this.runSendLoop(
|
|
584
608
|
connection,
|
|
585
609
|
invocationContext.liveRequestQueue,
|
|
586
610
|
combinedAbort,
|
|
587
|
-
invocationContext.abortSignal
|
|
611
|
+
invocationContext.abortSignal,
|
|
612
|
+
invocationContext.activeStreamingTools
|
|
588
613
|
);
|
|
589
614
|
sendTask.catch((error) => {
|
|
590
615
|
import_logger.logger.error("Error in live send loop:", error);
|
|
@@ -616,7 +641,7 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
616
641
|
}
|
|
617
642
|
}
|
|
618
643
|
await this.teardownLiveConnection(sendAbort, connection, sendTask);
|
|
619
|
-
if ((
|
|
644
|
+
if ((_e = invocationContext.abortSignal) == null ? void 0 : _e.aborted) {
|
|
620
645
|
return;
|
|
621
646
|
}
|
|
622
647
|
if (sendError) {
|
|
@@ -634,7 +659,7 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
634
659
|
}
|
|
635
660
|
}
|
|
636
661
|
async *runLivePreprocess(invocationContext, llmRequest) {
|
|
637
|
-
var _a2, _b2;
|
|
662
|
+
var _a2, _b2, _c;
|
|
638
663
|
for (const processor of this.requestProcessors) {
|
|
639
664
|
for await (const event of processor.runAsync(
|
|
640
665
|
invocationContext,
|
|
@@ -648,6 +673,12 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
648
673
|
}
|
|
649
674
|
for (const toolUnion of this.tools) {
|
|
650
675
|
const toolContext = new import_context.Context({ invocationContext });
|
|
676
|
+
if ((0, import_base_toolset.isBaseToolset)(toolUnion)) {
|
|
677
|
+
await toolUnion.processLlmRequest(toolContext, llmRequest);
|
|
678
|
+
if ((_b2 = invocationContext.abortSignal) == null ? void 0 : _b2.aborted) {
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
651
682
|
const tools = (await convertToolUnionToTools(
|
|
652
683
|
toolUnion,
|
|
653
684
|
new import_readonly_context.ReadonlyContext(invocationContext)
|
|
@@ -656,13 +687,13 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
656
687
|
);
|
|
657
688
|
for (const tool of tools) {
|
|
658
689
|
await tool.processLlmRequest({ toolContext, llmRequest });
|
|
659
|
-
if ((
|
|
690
|
+
if ((_c = invocationContext.abortSignal) == null ? void 0 : _c.aborted) {
|
|
660
691
|
return;
|
|
661
692
|
}
|
|
662
693
|
}
|
|
663
694
|
}
|
|
664
695
|
}
|
|
665
|
-
async runSendLoop(connection, liveRequestQueue, sendAbortSignal, invocationAbortSignal) {
|
|
696
|
+
async runSendLoop(connection, liveRequestQueue, sendAbortSignal, invocationAbortSignal, activeStreamingTools) {
|
|
666
697
|
while (true) {
|
|
667
698
|
if ((sendAbortSignal == null ? void 0 : sendAbortSignal.aborted) || (invocationAbortSignal == null ? void 0 : invocationAbortSignal.aborted)) {
|
|
668
699
|
return;
|
|
@@ -676,6 +707,13 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
676
707
|
}
|
|
677
708
|
throw error;
|
|
678
709
|
}
|
|
710
|
+
if (activeStreamingTools) {
|
|
711
|
+
for (const activeStreamingTool of Object.values(activeStreamingTools)) {
|
|
712
|
+
if (activeStreamingTool.stream) {
|
|
713
|
+
activeStreamingTool.stream.send(liveRequest);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
679
717
|
try {
|
|
680
718
|
await this.dispatchLiveRequest(connection, liveRequest);
|
|
681
719
|
} catch (error) {
|
|
@@ -730,67 +768,74 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
730
768
|
}
|
|
731
769
|
async *runReceiveLoop(invocationContext, connection, llmRequest, sendAbort) {
|
|
732
770
|
var _a2, _b2, _c, _d;
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
if ((_b2 = llmResponse.liveSessionResumptionUpdate) == null ? void 0 : _b2.newHandle) {
|
|
741
|
-
invocationContext.liveSessionResumptionHandle = llmResponse.liveSessionResumptionUpdate.newHandle;
|
|
742
|
-
}
|
|
743
|
-
if (llmResponse.goAway) {
|
|
744
|
-
import_logger.logger.info("Received goAway from live server; triggering reconnect.");
|
|
745
|
-
throw new LiveReconnectSignal("goAway");
|
|
746
|
-
}
|
|
747
|
-
const author = llmResponse.inputTranscription || ((_c = llmResponse.content) == null ? void 0 : _c.role) === "user" ? "user" : this.name;
|
|
748
|
-
const modelResponseEvent = (0, import_event.createEvent)({
|
|
749
|
-
invocationId: invocationContext.invocationId,
|
|
750
|
-
author,
|
|
751
|
-
branch: invocationContext.branch
|
|
752
|
-
});
|
|
753
|
-
for await (const event of this.postprocessLive(
|
|
754
|
-
invocationContext,
|
|
755
|
-
llmRequest,
|
|
756
|
-
llmResponse,
|
|
757
|
-
modelResponseEvent
|
|
758
|
-
)) {
|
|
759
|
-
yield event;
|
|
760
|
-
if (event.content && (0, import_event.getFunctionResponses)(event).length > 0) {
|
|
761
|
-
await connection.sendContent(event.content);
|
|
771
|
+
let receivedAny = true;
|
|
772
|
+
while (receivedAny) {
|
|
773
|
+
receivedAny = false;
|
|
774
|
+
for await (const llmResponse of connection.receive()) {
|
|
775
|
+
receivedAny = true;
|
|
776
|
+
if ((_a2 = invocationContext.abortSignal) == null ? void 0 : _a2.aborted) {
|
|
777
|
+
return;
|
|
762
778
|
}
|
|
763
|
-
|
|
764
|
-
(r) => r.name === "task_completed"
|
|
765
|
-
);
|
|
766
|
-
if (taskCompleted) {
|
|
767
|
-
await sleep(TRANSFER_AGENT_DELAY_MS);
|
|
779
|
+
if (sendAbort.signal.aborted) {
|
|
768
780
|
return;
|
|
769
781
|
}
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
782
|
+
if ((_b2 = llmResponse.liveSessionResumptionUpdate) == null ? void 0 : _b2.newHandle) {
|
|
783
|
+
invocationContext.liveSessionResumptionHandle = llmResponse.liveSessionResumptionUpdate.newHandle;
|
|
784
|
+
}
|
|
785
|
+
if (llmResponse.goAway) {
|
|
786
|
+
import_logger.logger.info(
|
|
787
|
+
"Received goAway from live server; triggering reconnect."
|
|
788
|
+
);
|
|
789
|
+
throw new LiveReconnectSignal("goAway");
|
|
790
|
+
}
|
|
791
|
+
const author = llmResponse.inputTranscription || ((_c = llmResponse.content) == null ? void 0 : _c.role) === "user" ? "user" : this.name;
|
|
792
|
+
const modelResponseEvent = (0, import_event.createEvent)({
|
|
793
|
+
invocationId: invocationContext.invocationId,
|
|
794
|
+
author,
|
|
795
|
+
branch: invocationContext.branch
|
|
796
|
+
});
|
|
797
|
+
for await (const event of this.postprocessLive(
|
|
798
|
+
invocationContext,
|
|
799
|
+
llmRequest,
|
|
800
|
+
llmResponse,
|
|
801
|
+
modelResponseEvent
|
|
802
|
+
)) {
|
|
803
|
+
yield event;
|
|
804
|
+
if (event.content && (0, import_event.getFunctionResponses)(event).length > 0) {
|
|
805
|
+
await connection.sendContent(event.content);
|
|
806
|
+
}
|
|
807
|
+
const taskCompleted = (0, import_event.getFunctionResponses)(event).some(
|
|
808
|
+
(r) => r.name === "task_completed"
|
|
809
|
+
);
|
|
810
|
+
if (taskCompleted) {
|
|
811
|
+
await sleep(TRANSFER_AGENT_DELAY_MS);
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
const transferTo = (_d = event.actions) == null ? void 0 : _d.transferToAgent;
|
|
815
|
+
if (transferTo) {
|
|
816
|
+
await sleep(TRANSFER_AGENT_DELAY_MS);
|
|
817
|
+
sendAbort.abort();
|
|
818
|
+
await connection.close();
|
|
819
|
+
const agent = (0, import_invocation_context.requireAgent)(invocationContext);
|
|
820
|
+
const subAgent = agent.rootAgent.findAgent(transferTo);
|
|
821
|
+
if (subAgent) {
|
|
822
|
+
const previousAgent = invocationContext.agent;
|
|
823
|
+
invocationContext.agent = subAgent;
|
|
824
|
+
const previousHandle = invocationContext.liveSessionResumptionHandle;
|
|
825
|
+
invocationContext.liveSessionResumptionHandle = void 0;
|
|
826
|
+
try {
|
|
827
|
+
for await (const subEvent of subAgent.runLive(
|
|
828
|
+
invocationContext
|
|
829
|
+
)) {
|
|
830
|
+
yield subEvent;
|
|
831
|
+
}
|
|
832
|
+
} finally {
|
|
833
|
+
invocationContext.agent = previousAgent;
|
|
834
|
+
invocationContext.liveSessionResumptionHandle = previousHandle;
|
|
787
835
|
}
|
|
788
|
-
} finally {
|
|
789
|
-
invocationContext.agent = previousAgent;
|
|
790
|
-
invocationContext.liveSessionResumptionHandle = previousHandle;
|
|
791
836
|
}
|
|
837
|
+
return;
|
|
792
838
|
}
|
|
793
|
-
return;
|
|
794
839
|
}
|
|
795
840
|
}
|
|
796
841
|
}
|
|
@@ -845,7 +890,7 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
845
890
|
if (!functionCalls.length) {
|
|
846
891
|
return;
|
|
847
892
|
}
|
|
848
|
-
const functionResponseEvent = await (0, import_functions.
|
|
893
|
+
const functionResponseEvent = await (0, import_functions.handleFunctionCallsLive)({
|
|
849
894
|
invocationContext,
|
|
850
895
|
functionCallEvent: mergedEvent,
|
|
851
896
|
toolsDict: llmRequest.toolsDict,
|
|
@@ -865,7 +910,7 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
865
910
|
yield functionResponseEvent;
|
|
866
911
|
}
|
|
867
912
|
async *runOneStepAsync(invocationContext) {
|
|
868
|
-
var _a2, _b2, _c;
|
|
913
|
+
var _a2, _b2, _c, _d;
|
|
869
914
|
const llmRequest = {
|
|
870
915
|
contents: [],
|
|
871
916
|
toolsDict: {},
|
|
@@ -885,7 +930,7 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
885
930
|
const allTools = [...this.tools];
|
|
886
931
|
if (this.mode === "task") {
|
|
887
932
|
allTools.push(this.finishTaskTool);
|
|
888
|
-
} else if (this.outputSchema && allTools.length > 0 && !(0, import_output_schema_utils.canUseOutputSchemaWithTools)(this.canonicalModel
|
|
933
|
+
} else if (this.outputSchema && allTools.length > 0 && !(0, import_output_schema_utils.canUseOutputSchemaWithTools)(this.canonicalModel)) {
|
|
889
934
|
const setModelResponseTool = new import_function_tool.FunctionTool({
|
|
890
935
|
name: "set_model_response",
|
|
891
936
|
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.",
|
|
@@ -909,6 +954,12 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
909
954
|
invocationContext,
|
|
910
955
|
eventActions: modelResponseEvent.actions
|
|
911
956
|
});
|
|
957
|
+
if ((0, import_base_toolset.isBaseToolset)(toolUnion)) {
|
|
958
|
+
await toolUnion.processLlmRequest(toolContext, llmRequest);
|
|
959
|
+
if ((_b2 = invocationContext.abortSignal) == null ? void 0 : _b2.aborted) {
|
|
960
|
+
return;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
912
963
|
const tools = (await convertToolUnionToTools(
|
|
913
964
|
toolUnion,
|
|
914
965
|
new import_readonly_context.ReadonlyContext(invocationContext)
|
|
@@ -917,54 +968,65 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
917
968
|
});
|
|
918
969
|
for (const tool of tools) {
|
|
919
970
|
await tool.processLlmRequest({ toolContext, llmRequest });
|
|
920
|
-
if ((
|
|
971
|
+
if ((_c = invocationContext.abortSignal) == null ? void 0 : _c.aborted) {
|
|
921
972
|
return;
|
|
922
973
|
}
|
|
923
974
|
}
|
|
924
975
|
}
|
|
925
|
-
if (invocationContext.endInvocation || ((
|
|
976
|
+
if (invocationContext.endInvocation || ((_d = invocationContext.abortSignal) == null ? void 0 : _d.aborted)) {
|
|
926
977
|
return;
|
|
927
978
|
}
|
|
928
979
|
const span = import_tracing.tracer.startSpan("call_llm");
|
|
929
980
|
const ctx = import_api.trace.setSpan(import_api.context.active(), span);
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
llmRequest,
|
|
939
|
-
modelResponseEvent
|
|
940
|
-
)) {
|
|
941
|
-
if ((_a3 = invocationContext.abortSignal) == null ? void 0 : _a3.aborted) {
|
|
942
|
-
return;
|
|
943
|
-
}
|
|
944
|
-
for await (const event of this.postprocess(
|
|
981
|
+
try {
|
|
982
|
+
yield* (0, import_tracing.runAsyncGeneratorWithOtelContext)(
|
|
983
|
+
ctx,
|
|
984
|
+
this,
|
|
985
|
+
async function* () {
|
|
986
|
+
const responsesGenerator = /* @__PURE__ */ __name(async function* () {
|
|
987
|
+
var _a3, _b3, _c2;
|
|
988
|
+
for await (const llmResponse of this.callLlmAsync(
|
|
945
989
|
invocationContext,
|
|
946
990
|
llmRequest,
|
|
947
|
-
llmResponse,
|
|
948
991
|
modelResponseEvent
|
|
949
992
|
)) {
|
|
950
|
-
if ((
|
|
993
|
+
if ((_a3 = invocationContext.abortSignal) == null ? void 0 : _a3.aborted) {
|
|
951
994
|
return;
|
|
952
995
|
}
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
996
|
+
if (((_b3 = invocationContext.runConfig) == null ? void 0 : _b3.supportCfc) && (0, import_event.isEvent)(llmResponse)) {
|
|
997
|
+
modelResponseEvent.id = (0, import_event.createNewEventId)();
|
|
998
|
+
modelResponseEvent.timestamp = (/* @__PURE__ */ new Date()).getTime();
|
|
999
|
+
yield llmResponse;
|
|
1000
|
+
continue;
|
|
1001
|
+
}
|
|
1002
|
+
for await (const event of this.postprocess(
|
|
1003
|
+
invocationContext,
|
|
1004
|
+
llmRequest,
|
|
1005
|
+
llmResponse,
|
|
1006
|
+
modelResponseEvent
|
|
1007
|
+
)) {
|
|
1008
|
+
if ((_c2 = invocationContext.abortSignal) == null ? void 0 : _c2.aborted) {
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
if (!event.partial) {
|
|
1012
|
+
modelResponseEvent.id = (0, import_event.createNewEventId)();
|
|
1013
|
+
modelResponseEvent.timestamp = (/* @__PURE__ */ new Date()).getTime();
|
|
1014
|
+
}
|
|
1015
|
+
yield event;
|
|
1016
|
+
}
|
|
956
1017
|
}
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
1018
|
+
}, "responsesGenerator");
|
|
1019
|
+
yield* this.runAndHandleError(
|
|
1020
|
+
responsesGenerator.call(this),
|
|
1021
|
+
invocationContext,
|
|
1022
|
+
llmRequest,
|
|
1023
|
+
modelResponseEvent
|
|
1024
|
+
);
|
|
1025
|
+
}
|
|
1026
|
+
);
|
|
1027
|
+
} finally {
|
|
1028
|
+
span.end();
|
|
1029
|
+
}
|
|
968
1030
|
}
|
|
969
1031
|
async *postprocess(invocationContext, llmRequest, llmResponse, modelResponseEvent) {
|
|
970
1032
|
var _a2, _b2, _c, _d, _e, _f;
|
|
@@ -1090,7 +1152,7 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
1090
1152
|
return agentToRun;
|
|
1091
1153
|
}
|
|
1092
1154
|
async *callLlmAsync(invocationContext, llmRequest, modelResponseEvent) {
|
|
1093
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h;
|
|
1155
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1094
1156
|
const beforeModelResponse = await this.handleBeforeModelCallback(
|
|
1095
1157
|
invocationContext,
|
|
1096
1158
|
llmRequest,
|
|
@@ -1109,14 +1171,39 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
1109
1171
|
llmRequest.config.labels[ADK_AGENT_NAME_LABEL_KEY] = this.name;
|
|
1110
1172
|
}
|
|
1111
1173
|
const llm = this.canonicalModel;
|
|
1174
|
+
invocationContext.incrementLlmCallCount();
|
|
1112
1175
|
if ((_e = invocationContext.runConfig) == null ? void 0 : _e.supportCfc) {
|
|
1113
|
-
|
|
1176
|
+
(_f = invocationContext.liveRequestQueue) != null ? _f : invocationContext.liveRequestQueue = new import_live_request_queue.LiveRequestQueue();
|
|
1177
|
+
const liveRequestQueue = invocationContext.liveRequestQueue;
|
|
1178
|
+
try {
|
|
1179
|
+
for await (const llmResponse of this.runLiveFlow(invocationContext)) {
|
|
1180
|
+
if ((_g = invocationContext.abortSignal) == null ? void 0 : _g.aborted) {
|
|
1181
|
+
return;
|
|
1182
|
+
}
|
|
1183
|
+
const alteredLlmResponse = await this.handleAfterModelCallback(
|
|
1184
|
+
invocationContext,
|
|
1185
|
+
llmResponse,
|
|
1186
|
+
modelResponseEvent
|
|
1187
|
+
);
|
|
1188
|
+
if ((_h = invocationContext.abortSignal) == null ? void 0 : _h.aborted) {
|
|
1189
|
+
return;
|
|
1190
|
+
}
|
|
1191
|
+
const effectiveResponse = alteredLlmResponse ? (0, import_event.createEvent)({ ...llmResponse, ...alteredLlmResponse }) : llmResponse;
|
|
1192
|
+
if (invocationContext.runConfig.streamingMode === import_run_config.StreamingMode.SSE || !effectiveResponse.partial) {
|
|
1193
|
+
yield effectiveResponse;
|
|
1194
|
+
}
|
|
1195
|
+
if (effectiveResponse.turnComplete) {
|
|
1196
|
+
liveRequestQueue.close();
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
} finally {
|
|
1200
|
+
liveRequestQueue.close();
|
|
1201
|
+
}
|
|
1114
1202
|
} else {
|
|
1115
|
-
invocationContext.incrementLlmCallCount();
|
|
1116
1203
|
const responsesGenerator = llm.generateContentAsync(
|
|
1117
1204
|
llmRequest,
|
|
1118
1205
|
/* stream= */
|
|
1119
|
-
((
|
|
1206
|
+
((_i = invocationContext.runConfig) == null ? void 0 : _i.streamingMode) === import_run_config.StreamingMode.SSE,
|
|
1120
1207
|
invocationContext.abortSignal
|
|
1121
1208
|
);
|
|
1122
1209
|
for await (const llmResponse of responsesGenerator) {
|
|
@@ -1126,7 +1213,7 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
1126
1213
|
llmRequest,
|
|
1127
1214
|
llmResponse
|
|
1128
1215
|
});
|
|
1129
|
-
if ((
|
|
1216
|
+
if ((_j = invocationContext.abortSignal) == null ? void 0 : _j.aborted) {
|
|
1130
1217
|
return;
|
|
1131
1218
|
}
|
|
1132
1219
|
const alteredLlmResponse = await this.handleAfterModelCallback(
|
|
@@ -1134,7 +1221,7 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
1134
1221
|
llmResponse,
|
|
1135
1222
|
modelResponseEvent
|
|
1136
1223
|
);
|
|
1137
|
-
if ((
|
|
1224
|
+
if ((_k = invocationContext.abortSignal) == null ? void 0 : _k.aborted) {
|
|
1138
1225
|
return;
|
|
1139
1226
|
}
|
|
1140
1227
|
yield alteredLlmResponse != null ? alteredLlmResponse : llmResponse;
|
|
@@ -55,7 +55,7 @@ const _BasicLlmRequestProcessor = class _BasicLlmRequestProcessor extends import
|
|
|
55
55
|
}
|
|
56
56
|
llmRequest.model = agent.canonicalModel.model;
|
|
57
57
|
llmRequest.config = { ...(_a = agent.generateContentConfig) != null ? _a : {} };
|
|
58
|
-
if (agent.outputSchema && agent.mode !== "task" && (!((_b = agent.tools) == null ? void 0 : _b.length) || (0, import_output_schema_utils.canUseOutputSchemaWithTools)(agent.canonicalModel
|
|
58
|
+
if (agent.outputSchema && agent.mode !== "task" && (!((_b = agent.tools) == null ? void 0 : _b.length) || (0, import_output_schema_utils.canUseOutputSchemaWithTools)(agent.canonicalModel))) {
|
|
59
59
|
(0, import_llm_request.setOutputSchema)(llmRequest, agent.outputSchema);
|
|
60
60
|
}
|
|
61
61
|
if (invocationContext.runConfig) {
|
|
@@ -83,6 +83,14 @@ const DATA_FILE_UTIL_MAP = {
|
|
|
83
83
|
const DATA_FILE_HELPER_LIB = `
|
|
84
84
|
import pandas as pd
|
|
85
85
|
|
|
86
|
+
def crop(s: str, max_chars: int = 64) -> str:
|
|
87
|
+
"""Crops a string to max_chars characters."""
|
|
88
|
+
if len(s) <= max_chars:
|
|
89
|
+
return s
|
|
90
|
+
if max_chars >= 3:
|
|
91
|
+
return s[:max_chars - 3] + '...'
|
|
92
|
+
return s[:max_chars]
|
|
93
|
+
|
|
86
94
|
def explore_df(df: pd.DataFrame) -> None:
|
|
87
95
|
"""Prints some information about a pandas DataFrame."""
|
|
88
96
|
|
|
@@ -244,7 +252,7 @@ async function* runPostProcessor(invocationContext, llmResponse) {
|
|
|
244
252
|
return;
|
|
245
253
|
}
|
|
246
254
|
const responseContent = llmResponse.content;
|
|
247
|
-
const codeStr = (0, import_code_execution_utils.
|
|
255
|
+
const { code: codeStr, language } = (0, import_code_execution_utils.extractCodeBlockAndTruncateContent)(
|
|
248
256
|
responseContent,
|
|
249
257
|
codeExecutor.codeBlockDelimiters
|
|
250
258
|
);
|
|
@@ -265,7 +273,7 @@ async function* runPostProcessor(invocationContext, llmResponse) {
|
|
|
265
273
|
invocationContext,
|
|
266
274
|
codeExecutionInput: {
|
|
267
275
|
code: codeStr,
|
|
268
|
-
language
|
|
276
|
+
language,
|
|
269
277
|
inputFiles: codeExecutorContext.getInputFiles(),
|
|
270
278
|
executionId
|
|
271
279
|
}
|
|
@@ -300,14 +308,15 @@ function extractAndReplaceInlineFiles(codeExecutorContext, llmRequest) {
|
|
|
300
308
|
continue;
|
|
301
309
|
}
|
|
302
310
|
const fileName = `data_${i + 1}_${j + 1}${DATA_FILE_UTIL_MAP[mimeType].extension}`;
|
|
303
|
-
part.text = `
|
|
304
|
-
Available file: \`${fileName}\`
|
|
305
|
-
`;
|
|
306
311
|
const file = {
|
|
307
312
|
name: fileName,
|
|
308
313
|
content: (0, import_env_aware_utils.base64Decode)(part.inlineData.data),
|
|
309
314
|
mimeType
|
|
310
315
|
};
|
|
316
|
+
part.text = `
|
|
317
|
+
Available file: \`${fileName}\`
|
|
318
|
+
`;
|
|
319
|
+
delete part.inlineData;
|
|
311
320
|
if (!savedFileNames.has(fileName)) {
|
|
312
321
|
codeExecutorContext.addInputFiles([file]);
|
|
313
322
|
allInputFiles.push(file);
|
|
@@ -351,7 +360,10 @@ async function postProcessCodeExecutionResult(invocationContext, codeExecutorCon
|
|
|
351
360
|
const version = await invocationContext.artifactService.saveArtifact({
|
|
352
361
|
filename: outputFile.name,
|
|
353
362
|
artifact: {
|
|
354
|
-
inlineData: {
|
|
363
|
+
inlineData: {
|
|
364
|
+
data: outputFile.contentEncoding === import_code_execution_utils.FileContentEncoding.UTF8 ? (0, import_env_aware_utils.base64Encode)(outputFile.content) : outputFile.content,
|
|
365
|
+
mimeType: outputFile.mimeType
|
|
366
|
+
}
|
|
355
367
|
}
|
|
356
368
|
});
|
|
357
369
|
eventActions.artifactDelta[outputFile.name] = version;
|