@google/adk 2.4.0 → 2.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_remote_agent.js +17 -2
- package/dist/cjs/a2a/a2a_remote_agent_utils.js +8 -4
- package/dist/cjs/a2a/agent_card.js +5 -81
- package/dist/cjs/a2a/agent_to_a2a.js +7 -0
- package/dist/cjs/a2a/event_converter_utils.js +10 -3
- package/dist/cjs/agents/agent_engine_client.js +282 -55
- package/dist/cjs/agents/base_agent.js +111 -68
- package/dist/cjs/agents/functions.js +62 -85
- package/dist/cjs/agents/instructions.js +7 -6
- package/dist/cjs/agents/invocation_context.js +2 -2
- package/dist/cjs/agents/llm_agent.js +105 -95
- package/dist/cjs/agents/processors/content_processor_utils.js +42 -15
- package/dist/cjs/agents/processors/content_request_processor.js +28 -11
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +5 -1
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/cjs/agents/processors/nl_planning_processor.js +2 -1
- package/dist/cjs/artifacts/file_artifact_service.js +1 -1
- package/dist/cjs/cli/cli_eval.js +884 -17
- package/dist/cjs/cli/utils/cleanup.js +84 -0
- package/dist/cjs/cli/utils/envs.js +33 -2
- package/dist/cjs/cli/utils/evals.js +75 -8
- package/dist/cjs/cli/utils/logs.js +128 -9
- package/dist/cjs/cli/utils/path_validation.js +83 -0
- package/dist/cjs/code_executors/container_code_executor.js +158 -36
- package/dist/cjs/common.js +50 -12
- package/dist/cjs/context/compaction_utils.js +19 -0
- package/dist/cjs/events/event.js +7 -3
- package/dist/cjs/features/feature_registry.js +5 -0
- package/dist/cjs/index.js +29 -14
- package/dist/cjs/models/google_llm.js +33 -2
- package/dist/cjs/models/interactions_utils.js +3 -0
- package/dist/cjs/plugins/base_plugin.js +45 -21
- package/dist/cjs/plugins/plugin_manager.js +27 -0
- package/dist/cjs/runner/runner.js +306 -189
- package/dist/cjs/sessions/base_session_service.js +1 -4
- package/dist/cjs/sessions/database_session_service.js +191 -19
- package/dist/cjs/sessions/db/operations.js +70 -1
- package/dist/cjs/sessions/db/schema.js +4 -0
- package/dist/cjs/sessions/in_memory_session_service.js +2 -2
- package/dist/cjs/sessions/vertex_ai_session_service.js +11 -3
- package/dist/cjs/skills/loader.js +29 -28
- package/dist/cjs/telemetry/api/instrumentation.js +632 -0
- package/dist/cjs/telemetry/api/internal/common/accumulators.js +169 -0
- package/dist/cjs/telemetry/api/internal/common/attributes.js +131 -0
- package/dist/cjs/telemetry/api/internal/common/config.js +159 -0
- package/dist/cjs/telemetry/api/internal/common/error.js +98 -0
- package/dist/cjs/telemetry/api/internal/common/finish_reason.js +63 -0
- package/dist/cjs/telemetry/api/internal/common/genai_messages.js +217 -0
- package/dist/cjs/telemetry/api/internal/common/http_exchange.js +169 -0
- package/dist/cjs/telemetry/api/internal/common/provider_name.js +87 -0
- package/dist/cjs/telemetry/api/internal/common/redaction.js +148 -0
- package/dist/cjs/telemetry/api/internal/common/serialization.js +58 -0
- package/dist/cjs/telemetry/api/internal/common/token_usage.js +118 -0
- package/dist/cjs/telemetry/api/internal/logs/inference.js +50 -0
- package/dist/cjs/telemetry/api/internal/logs/logger.js +46 -0
- package/dist/cjs/telemetry/api/internal/logs/mcp.js +141 -0
- package/dist/cjs/telemetry/api/internal/metrics/agent.js +128 -0
- package/dist/cjs/telemetry/api/internal/metrics/inference_start_hook.js +56 -0
- package/dist/cjs/telemetry/api/internal/metrics/meters.js +189 -0
- package/dist/cjs/telemetry/api/internal/metrics/tool.js +147 -0
- package/dist/cjs/telemetry/api/internal/metrics/workflow.js +132 -0
- package/dist/cjs/telemetry/api/internal/trace/agent.js +52 -0
- package/dist/cjs/telemetry/api/internal/trace/compaction.js +78 -0
- package/dist/cjs/telemetry/api/internal/trace/inference.js +132 -0
- package/dist/cjs/telemetry/api/internal/trace/live.js +52 -0
- package/dist/cjs/telemetry/api/internal/trace/node.js +73 -0
- package/dist/cjs/telemetry/api/internal/trace/propagation.js +67 -0
- package/dist/cjs/telemetry/api/internal/trace/tool.js +122 -0
- package/dist/cjs/telemetry/api/internal/trace/tracer.js +77 -0
- package/dist/cjs/telemetry/api/internal/trace/workflow.js +77 -0
- package/dist/cjs/telemetry/export/agent_engine.js +90 -0
- package/dist/cjs/telemetry/export/agent_runtime.js +73 -0
- package/dist/cjs/telemetry/export/google_cloud.js +763 -0
- package/dist/cjs/telemetry/export/request_driven_metric_reader.js +303 -0
- package/dist/cjs/telemetry/{setup.js → export/setup.js} +72 -5
- package/dist/cjs/tools/agent_tool.js +9 -1
- package/dist/cjs/tools/application_integration_tool/application_integration_toolset.js +22 -34
- package/dist/cjs/tools/application_integration_tool/clients/connections_client.js +60 -20
- package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +26 -10
- package/dist/cjs/tools/application_integration_tool/integration_connector_tool.js +14 -23
- package/dist/cjs/tools/base_toolset.js +1 -1
- package/dist/cjs/tools/computer_use/base_computer.js +125 -0
- package/dist/cjs/tools/computer_use/computer_use_actions.js +502 -0
- package/dist/cjs/tools/computer_use/computer_use_tool.js +244 -0
- package/dist/cjs/tools/computer_use/computer_use_toolset.js +360 -0
- package/dist/cjs/tools/function_tool.js +15 -5
- package/dist/cjs/tools/google_api_tool/google_api_toolset.js +3 -2
- package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +3 -1
- package/dist/cjs/tools/load_artifacts_tool.js +15 -5
- package/dist/cjs/tools/load_memory_tool.js +2 -5
- package/dist/cjs/tools/mcp/mcp_session_manager.js +23 -3
- package/dist/cjs/tools/mcp/mcp_tool.js +7 -3
- package/dist/cjs/tools/mcp/mcp_toolset.js +18 -6
- package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +30 -29
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -2
- package/dist/cjs/tools/openapi_tool/rest_api_tool.js +45 -14
- package/dist/cjs/tools/skill/load_skill_resource_tool.js +7 -0
- package/dist/cjs/tools/skill/load_skill_tool.js +3 -0
- package/dist/cjs/tools/skill/run_skill_script_tool.js +12 -2
- package/dist/cjs/tools/toolbox_toolset.js +47 -28
- package/dist/cjs/utils/async_queue.js +37 -3
- package/dist/cjs/utils/client_labels.js +9 -11
- package/dist/cjs/utils/env_aware_utils.js +13 -7
- package/dist/cjs/utils/error_utils.js +40 -2
- package/dist/cjs/utils/failover_utils.js +10 -9
- package/dist/cjs/utils/gemini_schema_util.js +125 -12
- package/dist/cjs/utils/id_provider.js +63 -0
- package/dist/cjs/utils/model_name.js +15 -0
- package/dist/cjs/utils/simple_zod_to_json.js +13 -31
- package/dist/cjs/utils/ssrf_guard.js +46 -16
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/workflow/index.js +2 -0
- package/dist/cjs/workflow/node_runner.js +24 -80
- package/dist/cjs/workflow/nodes/parallel_worker.js +18 -7
- package/dist/cjs/workflow/run_llm_agent_as_node.js +19 -14
- package/dist/cjs/workflow/utils/retry_utils.js +2 -2
- package/dist/cjs/workflow/workflow.js +12 -12
- package/dist/esm/a2a/a2a_remote_agent.js +23 -3
- package/dist/esm/a2a/a2a_remote_agent_utils.js +8 -4
- package/dist/esm/a2a/agent_card.js +5 -83
- package/dist/esm/a2a/agent_to_a2a.js +7 -0
- package/dist/esm/a2a/event_converter_utils.js +10 -3
- package/dist/esm/agents/agent_engine_client.js +293 -55
- package/dist/esm/agents/base_agent.js +111 -72
- package/dist/esm/agents/functions.js +67 -89
- package/dist/esm/agents/instructions.js +7 -6
- package/dist/esm/agents/invocation_context.js +2 -2
- package/dist/esm/agents/llm_agent.js +111 -100
- package/dist/esm/agents/processors/content_processor_utils.js +42 -15
- package/dist/esm/agents/processors/content_request_processor.js +28 -11
- package/dist/esm/agents/processors/context_compactor_request_processor.js +5 -1
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/esm/agents/processors/nl_planning_processor.js +2 -1
- package/dist/esm/artifacts/file_artifact_service.js +1 -1
- package/dist/esm/cli/cli_eval.js +880 -17
- package/dist/esm/cli/utils/cleanup.js +56 -0
- package/dist/esm/cli/utils/envs.js +33 -2
- package/dist/esm/cli/utils/evals.js +74 -8
- package/dist/esm/cli/utils/logs.js +128 -9
- package/dist/esm/cli/utils/path_validation.js +45 -0
- package/dist/esm/code_executors/container_code_executor.js +158 -36
- package/dist/esm/common.js +49 -6
- package/dist/esm/context/compaction_utils.js +19 -0
- package/dist/esm/events/event.js +7 -3
- package/dist/esm/features/feature_registry.js +5 -0
- package/dist/esm/index.js +27 -15
- package/dist/esm/models/google_llm.js +33 -2
- package/dist/esm/models/interactions_utils.js +3 -0
- package/dist/esm/plugins/base_plugin.js +45 -21
- package/dist/esm/plugins/plugin_manager.js +27 -0
- package/dist/esm/runner/runner.js +310 -192
- package/dist/esm/sessions/base_session_service.js +1 -4
- package/dist/esm/sessions/database_session_service.js +191 -19
- package/dist/esm/sessions/db/operations.js +70 -1
- package/dist/esm/sessions/db/schema.js +4 -0
- package/dist/esm/sessions/in_memory_session_service.js +2 -2
- package/dist/esm/sessions/vertex_ai_session_service.js +11 -3
- package/dist/esm/skills/loader.js +29 -28
- package/dist/esm/telemetry/api/instrumentation.js +655 -0
- package/dist/esm/telemetry/api/internal/common/accumulators.js +139 -0
- package/dist/esm/telemetry/api/internal/common/attributes.js +94 -0
- package/dist/esm/telemetry/api/internal/common/config.js +128 -0
- package/dist/esm/telemetry/api/internal/common/error.js +69 -0
- package/dist/esm/telemetry/api/internal/common/finish_reason.js +35 -0
- package/dist/esm/telemetry/api/internal/common/genai_messages.js +188 -0
- package/dist/esm/telemetry/api/internal/common/http_exchange.js +142 -0
- package/dist/esm/telemetry/api/internal/common/provider_name.js +59 -0
- package/dist/esm/telemetry/api/internal/common/redaction.js +121 -0
- package/dist/esm/telemetry/api/internal/common/serialization.js +30 -0
- package/dist/esm/telemetry/api/internal/common/token_usage.js +85 -0
- package/dist/esm/telemetry/api/internal/logs/inference.js +23 -0
- package/dist/esm/telemetry/api/internal/logs/logger.js +19 -0
- package/dist/esm/telemetry/api/internal/logs/mcp.js +113 -0
- package/dist/esm/telemetry/api/internal/metrics/agent.js +107 -0
- package/dist/esm/telemetry/api/internal/metrics/inference_start_hook.js +29 -0
- package/dist/esm/telemetry/api/internal/metrics/meters.js +165 -0
- package/dist/esm/telemetry/api/internal/metrics/tool.js +119 -0
- package/dist/esm/telemetry/api/internal/metrics/workflow.js +112 -0
- package/dist/esm/telemetry/api/internal/trace/agent.js +25 -0
- package/dist/esm/telemetry/api/internal/trace/compaction.js +50 -0
- package/dist/esm/telemetry/api/internal/trace/inference.js +107 -0
- package/dist/esm/telemetry/api/internal/trace/live.js +28 -0
- package/dist/esm/telemetry/api/internal/trace/node.js +44 -0
- package/dist/esm/telemetry/api/internal/trace/propagation.js +39 -0
- package/dist/esm/telemetry/api/internal/trace/tool.js +96 -0
- package/dist/esm/telemetry/api/internal/trace/tracer.js +52 -0
- package/dist/esm/telemetry/api/internal/trace/workflow.js +54 -0
- package/dist/esm/telemetry/export/agent_engine.js +67 -0
- package/dist/esm/telemetry/export/agent_runtime.js +46 -0
- package/dist/esm/telemetry/export/google_cloud.js +733 -0
- package/dist/esm/telemetry/export/request_driven_metric_reader.js +276 -0
- package/dist/esm/telemetry/export/setup.js +160 -0
- package/dist/esm/tools/agent_tool.js +9 -1
- package/dist/esm/tools/application_integration_tool/application_integration_toolset.js +23 -35
- package/dist/esm/tools/application_integration_tool/clients/connections_client.js +64 -21
- package/dist/esm/tools/application_integration_tool/clients/integration_client.js +26 -10
- package/dist/esm/tools/application_integration_tool/integration_connector_tool.js +14 -23
- package/dist/esm/tools/base_toolset.js +1 -1
- package/dist/esm/tools/computer_use/base_computer.js +99 -0
- package/dist/esm/tools/computer_use/computer_use_actions.js +477 -0
- package/dist/esm/tools/computer_use/computer_use_tool.js +217 -0
- package/dist/esm/tools/computer_use/computer_use_toolset.js +344 -0
- package/dist/esm/tools/function_tool.js +15 -5
- package/dist/esm/tools/google_api_tool/google_api_toolset.js +3 -2
- package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +3 -1
- package/dist/esm/tools/load_artifacts_tool.js +15 -5
- package/dist/esm/tools/load_memory_tool.js +2 -5
- package/dist/esm/tools/mcp/mcp_session_manager.js +23 -3
- package/dist/esm/tools/mcp/mcp_tool.js +7 -3
- package/dist/esm/tools/mcp/mcp_toolset.js +18 -6
- package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +27 -26
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -2
- package/dist/esm/tools/openapi_tool/rest_api_tool.js +45 -14
- package/dist/esm/tools/skill/load_skill_resource_tool.js +7 -0
- package/dist/esm/tools/skill/load_skill_tool.js +3 -0
- package/dist/esm/tools/skill/run_skill_script_tool.js +12 -2
- package/dist/esm/tools/toolbox_toolset.js +47 -28
- package/dist/esm/utils/async_queue.js +37 -3
- package/dist/esm/utils/client_labels.js +9 -11
- package/dist/esm/utils/env_aware_utils.js +12 -7
- package/dist/esm/utils/error_utils.js +37 -1
- package/dist/esm/utils/failover_utils.js +10 -9
- package/dist/esm/utils/gemini_schema_util.js +124 -11
- package/dist/esm/utils/id_provider.js +33 -0
- package/dist/esm/utils/model_name.js +14 -0
- package/dist/esm/utils/simple_zod_to_json.js +13 -31
- package/dist/esm/utils/ssrf_guard.js +55 -15
- package/dist/esm/version.js +1 -1
- package/dist/esm/workflow/index.js +2 -1
- package/dist/esm/workflow/node_runner.js +26 -80
- package/dist/esm/workflow/nodes/parallel_worker.js +16 -6
- package/dist/esm/workflow/run_llm_agent_as_node.js +19 -14
- package/dist/esm/workflow/utils/retry_utils.js +2 -2
- package/dist/esm/workflow/workflow.js +12 -12
- package/dist/types/a2a/a2a_remote_agent.d.ts +6 -0
- package/dist/types/a2a/a2a_remote_agent_utils.d.ts +3 -2
- package/dist/types/agents/agent_engine_client.d.ts +121 -3
- package/dist/types/agents/base_agent.d.ts +2 -0
- package/dist/types/agents/processors/content_processor_utils.d.ts +9 -9
- package/dist/types/agents/run_config.d.ts +14 -0
- package/dist/types/cli/cli_eval.d.ts +172 -9
- package/dist/types/cli/utils/cleanup.d.ts +18 -0
- package/dist/types/cli/utils/envs.d.ts +13 -3
- package/dist/types/cli/utils/evals.d.ts +64 -1
- package/dist/types/cli/utils/logs.d.ts +19 -2
- package/dist/types/cli/utils/path_validation.d.ts +30 -0
- package/dist/types/code_executors/container_code_executor.d.ts +49 -8
- package/dist/types/common.d.ts +16 -9
- package/dist/types/context/compaction_utils.d.ts +13 -1
- package/dist/types/events/event.d.ts +3 -0
- package/dist/types/features/feature_registry.d.ts +1 -0
- package/dist/types/index.d.ts +9 -6
- package/dist/types/plugins/base_plugin.d.ts +50 -21
- package/dist/types/plugins/plugin_manager.d.ts +13 -0
- package/dist/types/runner/runner.d.ts +11 -0
- package/dist/types/sessions/base_session_service.d.ts +0 -2
- package/dist/types/sessions/db/operations.d.ts +2 -1
- package/dist/types/sessions/db/schema.d.ts +5 -3
- package/dist/types/telemetry/api/instrumentation.d.ts +259 -0
- package/dist/types/telemetry/api/internal/common/accumulators.d.ts +91 -0
- package/dist/types/telemetry/api/internal/common/attributes.d.ts +90 -0
- package/dist/types/telemetry/api/internal/common/config.d.ts +61 -0
- package/dist/types/telemetry/api/internal/common/error.d.ts +29 -0
- package/dist/types/telemetry/api/internal/common/finish_reason.d.ts +18 -0
- package/dist/types/telemetry/api/internal/common/genai_messages.d.ts +26 -0
- package/dist/types/telemetry/api/internal/common/http_exchange.d.ts +50 -0
- package/dist/types/telemetry/api/internal/common/provider_name.d.ts +16 -0
- package/dist/types/telemetry/api/internal/common/redaction.d.ts +14 -0
- package/dist/types/telemetry/api/internal/common/serialization.d.ts +18 -0
- package/dist/types/telemetry/api/internal/common/token_usage.d.ts +47 -0
- package/dist/types/telemetry/api/internal/logs/inference.d.ts +15 -0
- package/dist/types/telemetry/api/internal/logs/logger.d.ts +13 -0
- package/dist/types/telemetry/api/internal/logs/mcp.d.ts +31 -0
- package/dist/types/telemetry/api/internal/metrics/agent.d.ts +28 -0
- package/dist/types/telemetry/api/internal/metrics/inference_start_hook.d.ts +12 -0
- package/dist/types/telemetry/api/internal/metrics/meters.d.ts +57 -0
- package/dist/types/telemetry/api/internal/metrics/tool.d.ts +44 -0
- package/dist/types/telemetry/api/internal/metrics/workflow.d.ts +32 -0
- package/dist/types/telemetry/api/internal/trace/agent.d.ts +14 -0
- package/dist/types/telemetry/api/internal/trace/compaction.d.ts +20 -0
- package/dist/types/telemetry/api/internal/trace/inference.d.ts +31 -0
- package/dist/types/telemetry/api/internal/trace/live.d.ts +21 -0
- package/dist/types/telemetry/api/internal/trace/node.d.ts +22 -0
- package/dist/types/telemetry/api/internal/trace/propagation.d.ts +22 -0
- package/dist/types/telemetry/api/internal/trace/tool.d.ts +57 -0
- package/dist/types/telemetry/api/internal/trace/tracer.d.ts +31 -0
- package/dist/types/telemetry/api/internal/trace/workflow.d.ts +21 -0
- package/dist/types/telemetry/export/agent_engine.d.ts +23 -0
- package/dist/types/telemetry/export/agent_runtime.d.ts +40 -0
- package/dist/types/telemetry/export/google_cloud.d.ts +189 -0
- package/dist/types/telemetry/export/request_driven_metric_reader.d.ts +144 -0
- package/dist/types/telemetry/{setup.d.ts → export/setup.d.ts} +3 -0
- package/dist/types/tools/agent_tool.d.ts +1 -1
- package/dist/types/tools/application_integration_tool/clients/connections_client.d.ts +13 -4
- package/dist/types/tools/base_toolset.d.ts +1 -1
- package/dist/types/tools/computer_use/base_computer.d.ts +281 -0
- package/dist/types/tools/computer_use/computer_use_actions.d.ts +53 -0
- package/dist/types/tools/computer_use/computer_use_tool.d.ts +108 -0
- package/dist/types/tools/computer_use/computer_use_toolset.d.ts +132 -0
- package/dist/types/tools/google_api_tool/google_api_toolset.d.ts +2 -0
- package/dist/types/tools/load_artifacts_tool.d.ts +5 -1
- package/dist/types/tools/load_memory_tool.d.ts +13 -7
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +16 -0
- package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +8 -8
- package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +7 -3
- package/dist/types/tools/toolbox_toolset.d.ts +15 -20
- package/dist/types/utils/async_queue.d.ts +14 -0
- package/dist/types/utils/env_aware_utils.d.ts +11 -0
- package/dist/types/utils/error_utils.d.ts +4 -0
- package/dist/types/utils/gemini_schema_util.d.ts +27 -6
- package/dist/types/utils/id_provider.d.ts +43 -0
- package/dist/types/utils/model_name.d.ts +8 -0
- package/dist/types/utils/ssrf_guard.d.ts +2 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/types/workflow/index.d.ts +1 -1
- package/dist/types/workflow/nodes/parallel_worker.d.ts +8 -1
- package/dist/web/index_web.js +86 -88
- package/dist/web/index_web.js.map +4 -4
- package/package.json +13 -15
- package/dist/cjs/telemetry/google_cloud.js +0 -116
- package/dist/cjs/telemetry/tracing.js +0 -393
- package/dist/esm/telemetry/google_cloud.js +0 -99
- package/dist/esm/telemetry/setup.js +0 -88
- package/dist/esm/telemetry/tracing.js +0 -361
- package/dist/types/telemetry/google_cloud.d.ts +0 -9
- package/dist/types/telemetry/tracing.d.ts +0 -143
|
@@ -51,13 +51,14 @@ var import_lodash_es = require("lodash-es");
|
|
|
51
51
|
var import_event = require("../events/event.js");
|
|
52
52
|
var import_event_actions = require("../events/event_actions.js");
|
|
53
53
|
var import_base_tool = require("../tools/base_tool.js");
|
|
54
|
+
var import_computer_use_tool = require("../tools/computer_use/computer_use_tool.js");
|
|
54
55
|
var import_function_tool = require("../tools/function_tool.js");
|
|
55
56
|
var import_logger = require("../utils/logger.js");
|
|
56
57
|
var import_task = require("../utils/task.js");
|
|
57
58
|
var import_active_streaming_tool = require("./active_streaming_tool.js");
|
|
58
59
|
var import_context = require("./context.js");
|
|
59
60
|
var import_framework_function_calls = require("./framework_function_calls.js");
|
|
60
|
-
var
|
|
61
|
+
var import_instrumentation = require("../telemetry/api/instrumentation.js");
|
|
61
62
|
var import_event2 = require("../events/event.js");
|
|
62
63
|
var import_framework_function_calls2 = require("./framework_function_calls.js");
|
|
63
64
|
/**
|
|
@@ -165,56 +166,45 @@ function generateRequestConfirmationEvent({
|
|
|
165
166
|
}
|
|
166
167
|
__name(generateRequestConfirmationEvent, "generateRequestConfirmationEvent");
|
|
167
168
|
async function callToolAsync(tool, args, toolContext) {
|
|
168
|
-
return
|
|
169
|
-
|
|
169
|
+
return (0, import_instrumentation.recordToolExecution)(
|
|
170
|
+
{ tool, args, invocationContext: toolContext.invocationContext },
|
|
171
|
+
async (scope) => {
|
|
170
172
|
import_logger.logger.debug(`callToolAsync ${tool.name}`);
|
|
171
173
|
const result = await tool.runAsync({ args, toolContext });
|
|
172
|
-
|
|
173
|
-
tool,
|
|
174
|
-
args,
|
|
175
|
-
span,
|
|
174
|
+
scope.recordSuccess({
|
|
176
175
|
functionResponseEvent: buildResponseEvent(
|
|
177
176
|
tool,
|
|
178
177
|
result,
|
|
179
178
|
toolContext,
|
|
180
179
|
toolContext.invocationContext
|
|
181
180
|
),
|
|
182
|
-
|
|
183
|
-
invocationContext: toolContext.invocationContext
|
|
181
|
+
rawResult: result
|
|
184
182
|
});
|
|
185
183
|
return result;
|
|
186
|
-
} catch (error) {
|
|
187
|
-
(0, import_tracing.traceToolCall)({
|
|
188
|
-
tool,
|
|
189
|
-
args,
|
|
190
|
-
span,
|
|
191
|
-
error,
|
|
192
|
-
invocationContext: toolContext.invocationContext
|
|
193
|
-
});
|
|
194
|
-
throw error;
|
|
195
|
-
} finally {
|
|
196
|
-
span.end();
|
|
197
184
|
}
|
|
198
|
-
|
|
185
|
+
);
|
|
199
186
|
}
|
|
200
187
|
__name(callToolAsync, "callToolAsync");
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
const response = result;
|
|
211
|
-
const errorType = (_a2 = response.errorType) != null ? _a2 : response.error_type;
|
|
212
|
-
return typeof errorType === "string" ? errorType : void 0;
|
|
213
|
-
} catch {
|
|
214
|
-
return void 0;
|
|
188
|
+
const BASE64 = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
189
|
+
function buildFunctionResponse({
|
|
190
|
+
tool,
|
|
191
|
+
id,
|
|
192
|
+
response
|
|
193
|
+
}) {
|
|
194
|
+
const image = (0, import_computer_use_tool.isComputerUseTool)(tool) ? response == null ? void 0 : response["image"] : void 0;
|
|
195
|
+
if (typeof image !== "object" || image === null || !("data" in image) || !("mimetype" in image) || typeof image.data !== "string" || typeof image.mimetype !== "string" || !BASE64.test(image.data)) {
|
|
196
|
+
return { id, name: tool.name, response };
|
|
215
197
|
}
|
|
198
|
+
const rest = { ...response };
|
|
199
|
+
delete rest["image"];
|
|
200
|
+
return {
|
|
201
|
+
id,
|
|
202
|
+
name: tool.name,
|
|
203
|
+
response: rest,
|
|
204
|
+
parts: [{ inlineData: { data: image.data, mimeType: image.mimetype } }]
|
|
205
|
+
};
|
|
216
206
|
}
|
|
217
|
-
__name(
|
|
207
|
+
__name(buildFunctionResponse, "buildFunctionResponse");
|
|
218
208
|
function buildResponseEvent(tool, functionResult, toolContext, invocationContext) {
|
|
219
209
|
let responseResult;
|
|
220
210
|
if (typeof functionResult !== "object" || functionResult == null) {
|
|
@@ -225,11 +215,11 @@ function buildResponseEvent(tool, functionResult, toolContext, invocationContext
|
|
|
225
215
|
responseResult = functionResult;
|
|
226
216
|
}
|
|
227
217
|
const partFunctionResponse = {
|
|
228
|
-
functionResponse: {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
218
|
+
functionResponse: buildFunctionResponse({
|
|
219
|
+
tool,
|
|
220
|
+
id: toolContext.functionCallId,
|
|
221
|
+
response: responseResult
|
|
222
|
+
})
|
|
233
223
|
};
|
|
234
224
|
const content = {
|
|
235
225
|
role: "user",
|
|
@@ -332,38 +322,35 @@ async function answerUnresolvableCall({
|
|
|
332
322
|
toolsDict,
|
|
333
323
|
toolContext
|
|
334
324
|
}) {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
325
|
+
var _a2;
|
|
326
|
+
const toolName = functionCall.name || "<unnamed>";
|
|
327
|
+
const error = new Error(
|
|
328
|
+
`Function ${toolName} is not found in the toolsDict.`
|
|
329
|
+
);
|
|
330
|
+
const tool = new ToolNotFoundPlaceholder(toolName, error);
|
|
331
|
+
return (0, import_instrumentation.recordToolExecution)(
|
|
332
|
+
{ tool, args: (_a2 = functionCall.args) != null ? _a2 : {}, invocationContext },
|
|
333
|
+
async () => {
|
|
334
|
+
var _a3, _b2;
|
|
335
|
+
const onToolErrorResponse = await invocationContext.pluginManager.runOnToolErrorCallback({
|
|
336
|
+
tool,
|
|
337
|
+
toolArgs: (_a3 = functionCall.args) != null ? _a3 : {},
|
|
338
|
+
toolContext,
|
|
339
|
+
error
|
|
340
|
+
});
|
|
341
|
+
if (onToolErrorResponse == null) {
|
|
342
|
+
const callableTools = Object.keys(toolsDict);
|
|
343
|
+
import_logger.logger.warn(
|
|
344
|
+
`Could not resolve tool '${toolName}' for function call '${(_b2 = functionCall.id) != null ? _b2 : ""}'. Callable tools: ${callableTools.length ? callableTools.join(", ") : "(none)"}.
|
|
355
345
|
` + RESOLUTION_FAILURE_CAUSES
|
|
356
|
-
);
|
|
357
|
-
}
|
|
358
|
-
return buildResponseEvent(
|
|
359
|
-
tool,
|
|
360
|
-
onToolErrorResponse != null ? onToolErrorResponse : { error: error.message },
|
|
361
|
-
toolContext,
|
|
362
|
-
invocationContext
|
|
363
346
|
);
|
|
364
|
-
} finally {
|
|
365
|
-
span.end();
|
|
366
347
|
}
|
|
348
|
+
return buildResponseEvent(
|
|
349
|
+
tool,
|
|
350
|
+
onToolErrorResponse != null ? onToolErrorResponse : { error: error.message },
|
|
351
|
+
toolContext,
|
|
352
|
+
invocationContext
|
|
353
|
+
);
|
|
367
354
|
}
|
|
368
355
|
);
|
|
369
356
|
}
|
|
@@ -504,11 +491,11 @@ async function handleFunctionCallList({
|
|
|
504
491
|
invocationId: invocationContext.invocationId,
|
|
505
492
|
author: toolEventAuthor(invocationContext),
|
|
506
493
|
content: (0, import_genai.createUserContent)({
|
|
507
|
-
functionResponse: {
|
|
494
|
+
functionResponse: buildFunctionResponse({
|
|
495
|
+
tool,
|
|
508
496
|
id: toolContext.functionCallId,
|
|
509
|
-
name: tool.name,
|
|
510
497
|
response: functionResponse
|
|
511
|
-
}
|
|
498
|
+
})
|
|
512
499
|
}),
|
|
513
500
|
actions: toolContext.actions,
|
|
514
501
|
branch: invocationContext.branch
|
|
@@ -522,18 +509,8 @@ async function handleFunctionCallList({
|
|
|
522
509
|
functionResponseEvents
|
|
523
510
|
);
|
|
524
511
|
if (functionResponseEvents.length > 1) {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
import_logger.logger.debug("execute_tool (merged)");
|
|
528
|
-
(0, import_tracing.traceMergedToolCalls)({
|
|
529
|
-
responseEventId: mergedEvent.id,
|
|
530
|
-
functionResponseEvent: mergedEvent,
|
|
531
|
-
invocationContext
|
|
532
|
-
});
|
|
533
|
-
} finally {
|
|
534
|
-
span.end();
|
|
535
|
-
}
|
|
536
|
-
});
|
|
512
|
+
import_logger.logger.debug("execute_tool (merged)");
|
|
513
|
+
(0, import_instrumentation.recordMergedToolCalls)({ responseEventId: mergedEvent.id });
|
|
537
514
|
}
|
|
538
515
|
return mergedEvent;
|
|
539
516
|
}
|
|
@@ -63,10 +63,13 @@ async function resolveKey(key, isOptional, rawMatch, readonlyContext) {
|
|
|
63
63
|
}
|
|
64
64
|
throw new Error(`Artifact ${fileName} not found.`);
|
|
65
65
|
}
|
|
66
|
-
return formatValue(
|
|
66
|
+
return formatValue(
|
|
67
|
+
(0, import_load_artifacts_tool.asSafePartForLlm)(artifact, fileName, { inlineMediaAsPlaceholder: true }),
|
|
68
|
+
true
|
|
69
|
+
);
|
|
67
70
|
}
|
|
68
71
|
if (isValidStateName(key)) {
|
|
69
|
-
if (
|
|
72
|
+
if (Object.hasOwn(invocationContext.session.state, key)) {
|
|
70
73
|
return formatValue(invocationContext.session.state[key], false);
|
|
71
74
|
}
|
|
72
75
|
if (isOptional) {
|
|
@@ -188,14 +191,12 @@ async function injectSessionState(template, readonlyContext) {
|
|
|
188
191
|
return result.join("");
|
|
189
192
|
}
|
|
190
193
|
__name(injectSessionState, "injectSessionState");
|
|
191
|
-
const
|
|
192
|
-
return /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
193
|
-
})();
|
|
194
|
+
const IDENTIFIER_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
194
195
|
function isIdentifier(s) {
|
|
195
196
|
if (s === "" || s === void 0) {
|
|
196
197
|
return false;
|
|
197
198
|
}
|
|
198
|
-
return
|
|
199
|
+
return IDENTIFIER_PATTERN.test(s);
|
|
199
200
|
}
|
|
200
201
|
__name(isIdentifier, "isIdentifier");
|
|
201
202
|
const VALID_PREFIXES = [import_state.State.APP_PREFIX, import_state.State.USER_PREFIX, import_state.State.TEMP_PREFIX];
|
|
@@ -32,7 +32,7 @@ __export(invocation_context_exports, {
|
|
|
32
32
|
requireAgent: () => requireAgent
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(invocation_context_exports);
|
|
35
|
-
var
|
|
35
|
+
var import_id_provider = require("../utils/id_provider.js");
|
|
36
36
|
/**
|
|
37
37
|
* @license
|
|
38
38
|
* Copyright 2025 Google LLC
|
|
@@ -141,7 +141,7 @@ const _InvocationContext = class _InvocationContext {
|
|
|
141
141
|
__name(_InvocationContext, "InvocationContext");
|
|
142
142
|
let InvocationContext = _InvocationContext;
|
|
143
143
|
function newInvocationContextId() {
|
|
144
|
-
return `e-${(0,
|
|
144
|
+
return `e-${(0, import_id_provider.newId)()}`;
|
|
145
145
|
}
|
|
146
146
|
__name(newInvocationContextId, "newInvocationContextId");
|
|
147
147
|
function requireAgent(ctx) {
|
|
@@ -30,7 +30,6 @@ __export(llm_agent_exports, {
|
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(llm_agent_exports);
|
|
32
32
|
var import_genai = require("@google/genai");
|
|
33
|
-
var import_api = require("@opentelemetry/api");
|
|
34
33
|
var import_finish_task_tool = require("../tools/finish_task_tool.js");
|
|
35
34
|
var import_function_tool = require("../tools/function_tool.js");
|
|
36
35
|
var import_async_queue = require("../utils/async_queue.js");
|
|
@@ -47,7 +46,7 @@ var import_base_toolset = require("../tools/base_toolset.js");
|
|
|
47
46
|
var import_logger = require("../utils/logger.js");
|
|
48
47
|
var import_output_schema_utils = require("../utils/output_schema_utils.js");
|
|
49
48
|
var import_context = require("./context.js");
|
|
50
|
-
var
|
|
49
|
+
var import_instrumentation = require("../telemetry/api/instrumentation.js");
|
|
51
50
|
var import_schema = require("../utils/schema.js");
|
|
52
51
|
var import_simple_zod_to_json = require("../utils/simple_zod_to_json.js");
|
|
53
52
|
var import_base_agent = require("./base_agent.js");
|
|
@@ -104,6 +103,13 @@ function sleep(ms) {
|
|
|
104
103
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
105
104
|
}
|
|
106
105
|
__name(sleep, "sleep");
|
|
106
|
+
function hasSettledResponses(functionResponseEvent) {
|
|
107
|
+
const awaiting = functionResponseEvent.actions.requestedToolConfirmations;
|
|
108
|
+
return (0, import_event.getFunctionResponses)(functionResponseEvent).some(
|
|
109
|
+
(response) => !response.id || !Object.hasOwn(awaiting, response.id)
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
__name(hasSettledResponses, "hasSettledResponses");
|
|
107
113
|
const LIVE_KEYS = [
|
|
108
114
|
"responseModalities",
|
|
109
115
|
"speechConfig",
|
|
@@ -129,14 +135,14 @@ function applyLiveRunConfig(runConfig, llmRequest) {
|
|
|
129
135
|
}
|
|
130
136
|
__name(applyLiveRunConfig, "applyLiveRunConfig");
|
|
131
137
|
const ADK_AGENT_NAME_LABEL_KEY = "adk_agent_name";
|
|
132
|
-
async function convertToolUnionToTools(toolUnion,
|
|
138
|
+
async function convertToolUnionToTools(toolUnion, context) {
|
|
133
139
|
if ((0, import_base_tool.isBaseTool)(toolUnion)) {
|
|
134
140
|
return [toolUnion];
|
|
135
141
|
}
|
|
136
142
|
if ((0, import_base_node.isBaseNode)(toolUnion)) {
|
|
137
143
|
return [new import_node_tool.NodeTool(toolUnion)];
|
|
138
144
|
}
|
|
139
|
-
return await toolUnion.getTools(
|
|
145
|
+
return await toolUnion.getTools(context);
|
|
140
146
|
}
|
|
141
147
|
__name(convertToolUnionToTools, "convertToolUnionToTools");
|
|
142
148
|
const LLM_AGENT_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for("google.adk.llmAgent");
|
|
@@ -227,7 +233,7 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
227
233
|
}
|
|
228
234
|
if (config.generateContentConfig.responseSchema) {
|
|
229
235
|
throw new Error(
|
|
230
|
-
"Response schema must be set via LlmAgent.
|
|
236
|
+
"Response schema must be set via LlmAgent.outputSchema."
|
|
231
237
|
);
|
|
232
238
|
}
|
|
233
239
|
if (config.generateContentConfig.thinkingConfig && (0, import_built_in_planner.isBuiltInPlanner)(this.planner) && this.planner.thinkingConfig) {
|
|
@@ -288,12 +294,12 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
288
294
|
* @param context The context to retrieve the session state.
|
|
289
295
|
* @returns The resolved instruction field.
|
|
290
296
|
*/
|
|
291
|
-
async canonicalInstruction(
|
|
297
|
+
async canonicalInstruction(context) {
|
|
292
298
|
if (typeof this.instruction === "string") {
|
|
293
299
|
return { instruction: this.instruction, requireStateInjection: true };
|
|
294
300
|
}
|
|
295
301
|
return {
|
|
296
|
-
instruction: await this.instruction(
|
|
302
|
+
instruction: await this.instruction(context),
|
|
297
303
|
requireStateInjection: false
|
|
298
304
|
};
|
|
299
305
|
}
|
|
@@ -305,7 +311,7 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
305
311
|
* @returns The resolved globalInstruction field.
|
|
306
312
|
* @deprecated Use GlobalInstructionPlugin instead.
|
|
307
313
|
*/
|
|
308
|
-
async canonicalGlobalInstruction(
|
|
314
|
+
async canonicalGlobalInstruction(context) {
|
|
309
315
|
if (typeof this.globalInstruction === "string") {
|
|
310
316
|
return {
|
|
311
317
|
instruction: this.globalInstruction,
|
|
@@ -313,7 +319,7 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
313
319
|
};
|
|
314
320
|
}
|
|
315
321
|
return {
|
|
316
|
-
instruction: await this.globalInstruction(
|
|
322
|
+
instruction: await this.globalInstruction(context),
|
|
317
323
|
requireStateInjection: false
|
|
318
324
|
};
|
|
319
325
|
}
|
|
@@ -322,10 +328,10 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
322
328
|
*
|
|
323
329
|
* This method is only for use by Agent Development Kit.
|
|
324
330
|
*/
|
|
325
|
-
async canonicalTools(
|
|
331
|
+
async canonicalTools(context) {
|
|
326
332
|
const resolvedTools = [];
|
|
327
333
|
for (const toolUnion of this.tools) {
|
|
328
|
-
const tools = await convertToolUnionToTools(toolUnion,
|
|
334
|
+
const tools = await convertToolUnionToTools(toolUnion, context);
|
|
329
335
|
resolvedTools.push(...tools);
|
|
330
336
|
}
|
|
331
337
|
return resolvedTools;
|
|
@@ -415,7 +421,15 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
415
421
|
);
|
|
416
422
|
return;
|
|
417
423
|
}
|
|
418
|
-
|
|
424
|
+
if (!event.content.parts.some(
|
|
425
|
+
(part) => part.text !== void 0 && !part.thought
|
|
426
|
+
)) {
|
|
427
|
+
import_logger.logger.debug(
|
|
428
|
+
`Skipping output save for agent ${this.name}: event has no text`
|
|
429
|
+
);
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
const resultStr = event.content.parts.filter((part) => !part.thought).map((part) => part.text ? part.text : "").join("");
|
|
419
433
|
let result = resultStr;
|
|
420
434
|
if (this.outputSchema) {
|
|
421
435
|
if (!resultStr.trim()) {
|
|
@@ -468,14 +482,14 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
468
482
|
async *runImpl(ctx, nodeInput) {
|
|
469
483
|
yield* (0, import_run_llm_agent_as_node.runLlmAgentAsNode)(this, ctx, nodeInput);
|
|
470
484
|
}
|
|
471
|
-
async *runAsyncImpl(
|
|
485
|
+
async *runAsyncImpl(context) {
|
|
472
486
|
var _a2, _b2;
|
|
473
487
|
while (true) {
|
|
474
488
|
let lastEvent = void 0;
|
|
475
489
|
let stepHadToolCalls = false;
|
|
476
490
|
let stepTransferred = false;
|
|
477
|
-
for await (const event of this.runOneStepAsync(
|
|
478
|
-
if ((_a2 =
|
|
491
|
+
for await (const event of this.runOneStepAsync(context)) {
|
|
492
|
+
if ((_a2 = context.abortSignal) == null ? void 0 : _a2.aborted) {
|
|
479
493
|
return;
|
|
480
494
|
}
|
|
481
495
|
lastEvent = event;
|
|
@@ -501,16 +515,16 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
501
515
|
}
|
|
502
516
|
}
|
|
503
517
|
}
|
|
504
|
-
async *runLiveImpl(
|
|
518
|
+
async *runLiveImpl(context) {
|
|
505
519
|
var _a2;
|
|
506
|
-
for await (const event of this.runLiveFlow(
|
|
507
|
-
if ((_a2 =
|
|
520
|
+
for await (const event of this.runLiveFlow(context)) {
|
|
521
|
+
if ((_a2 = context.abortSignal) == null ? void 0 : _a2.aborted) {
|
|
508
522
|
return;
|
|
509
523
|
}
|
|
510
524
|
this.maybeSaveOutputToState(event);
|
|
511
525
|
yield event;
|
|
512
526
|
}
|
|
513
|
-
if (
|
|
527
|
+
if (context.endInvocation) {
|
|
514
528
|
return;
|
|
515
529
|
}
|
|
516
530
|
}
|
|
@@ -587,18 +601,14 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
587
601
|
throw err;
|
|
588
602
|
}
|
|
589
603
|
if (llmRequest.contents.length > 0 && !invocationContext.liveSessionResumptionHandle) {
|
|
590
|
-
await
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
(0,
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
} finally {
|
|
599
|
-
span.end();
|
|
600
|
-
}
|
|
601
|
-
});
|
|
604
|
+
await (0, import_instrumentation.recordSendData)(
|
|
605
|
+
{
|
|
606
|
+
invocationContext,
|
|
607
|
+
eventId: (0, import_event.createNewEventId)(),
|
|
608
|
+
data: llmRequest.contents
|
|
609
|
+
},
|
|
610
|
+
() => connection.sendHistory(llmRequest.contents)
|
|
611
|
+
);
|
|
602
612
|
}
|
|
603
613
|
let sendError;
|
|
604
614
|
const sendAbort = new AbortController();
|
|
@@ -976,57 +986,45 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
976
986
|
if (invocationContext.endInvocation || ((_d = invocationContext.abortSignal) == null ? void 0 : _d.aborted)) {
|
|
977
987
|
return;
|
|
978
988
|
}
|
|
979
|
-
const
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
for await (const llmResponse of this.callLlmAsync(
|
|
989
|
-
invocationContext,
|
|
990
|
-
llmRequest,
|
|
991
|
-
modelResponseEvent
|
|
992
|
-
)) {
|
|
993
|
-
if ((_a3 = invocationContext.abortSignal) == null ? void 0 : _a3.aborted) {
|
|
994
|
-
return;
|
|
995
|
-
}
|
|
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
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
}, "responsesGenerator");
|
|
1019
|
-
yield* this.runAndHandleError(
|
|
1020
|
-
responsesGenerator.call(this),
|
|
1021
|
-
invocationContext,
|
|
1022
|
-
llmRequest,
|
|
1023
|
-
modelResponseEvent
|
|
1024
|
-
);
|
|
989
|
+
const responsesGenerator = /* @__PURE__ */ __name(async function* () {
|
|
990
|
+
var _a3, _b3, _c2;
|
|
991
|
+
for await (const llmResponse of this.callLlmAsync(
|
|
992
|
+
invocationContext,
|
|
993
|
+
llmRequest,
|
|
994
|
+
modelResponseEvent
|
|
995
|
+
)) {
|
|
996
|
+
if ((_a3 = invocationContext.abortSignal) == null ? void 0 : _a3.aborted) {
|
|
997
|
+
return;
|
|
1025
998
|
}
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
999
|
+
if (((_b3 = invocationContext.runConfig) == null ? void 0 : _b3.supportCfc) && (0, import_event.isEvent)(llmResponse)) {
|
|
1000
|
+
modelResponseEvent.id = (0, import_event.createNewEventId)();
|
|
1001
|
+
modelResponseEvent.timestamp = (/* @__PURE__ */ new Date()).getTime();
|
|
1002
|
+
yield llmResponse;
|
|
1003
|
+
continue;
|
|
1004
|
+
}
|
|
1005
|
+
for await (const event of this.postprocess(
|
|
1006
|
+
invocationContext,
|
|
1007
|
+
llmRequest,
|
|
1008
|
+
llmResponse,
|
|
1009
|
+
modelResponseEvent
|
|
1010
|
+
)) {
|
|
1011
|
+
if ((_c2 = invocationContext.abortSignal) == null ? void 0 : _c2.aborted) {
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
if (!event.partial) {
|
|
1015
|
+
modelResponseEvent.id = (0, import_event.createNewEventId)();
|
|
1016
|
+
modelResponseEvent.timestamp = (/* @__PURE__ */ new Date()).getTime();
|
|
1017
|
+
}
|
|
1018
|
+
yield event;
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
}, "responsesGenerator");
|
|
1022
|
+
yield* this.runAndHandleError(
|
|
1023
|
+
responsesGenerator.call(this),
|
|
1024
|
+
invocationContext,
|
|
1025
|
+
llmRequest,
|
|
1026
|
+
modelResponseEvent
|
|
1027
|
+
);
|
|
1030
1028
|
}
|
|
1031
1029
|
async *postprocess(invocationContext, llmRequest, llmResponse, modelResponseEvent) {
|
|
1032
1030
|
var _a2, _b2, _c, _d, _e, _f;
|
|
@@ -1069,6 +1067,9 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
1069
1067
|
if (!((_c = (0, import_event.getFunctionCalls)(mergedEvent)) == null ? void 0 : _c.length)) {
|
|
1070
1068
|
return;
|
|
1071
1069
|
}
|
|
1070
|
+
if (mergedEvent.partial) {
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1072
1073
|
if ((_d = invocationContext.runConfig) == null ? void 0 : _d.pauseOnToolCalls) {
|
|
1073
1074
|
invocationContext.endInvocation = true;
|
|
1074
1075
|
return;
|
|
@@ -1115,6 +1116,15 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
1115
1116
|
functionResponseEvent
|
|
1116
1117
|
});
|
|
1117
1118
|
if (toolConfirmationEvent) {
|
|
1119
|
+
if (hasSettledResponses(functionResponseEvent)) {
|
|
1120
|
+
const { requestedToolConfirmations, skipSummarization, ...settled } = functionResponseEvent.actions;
|
|
1121
|
+
functionResponseEvent.actions = (0, import_event_actions.createEventActions)(settled);
|
|
1122
|
+
toolConfirmationEvent.actions = (0, import_event_actions.createEventActions)({
|
|
1123
|
+
requestedToolConfirmations,
|
|
1124
|
+
skipSummarization
|
|
1125
|
+
});
|
|
1126
|
+
yield functionResponseEvent;
|
|
1127
|
+
}
|
|
1118
1128
|
yield toolConfirmationEvent;
|
|
1119
1129
|
invocationContext.endInvocation = true;
|
|
1120
1130
|
return;
|
|
@@ -1152,7 +1162,7 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
1152
1162
|
return agentToRun;
|
|
1153
1163
|
}
|
|
1154
1164
|
async *callLlmAsync(invocationContext, llmRequest, modelResponseEvent) {
|
|
1155
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j
|
|
1165
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1156
1166
|
const beforeModelResponse = await this.handleBeforeModelCallback(
|
|
1157
1167
|
invocationContext,
|
|
1158
1168
|
llmRequest,
|
|
@@ -1200,20 +1210,20 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
1200
1210
|
liveRequestQueue.close();
|
|
1201
1211
|
}
|
|
1202
1212
|
} else {
|
|
1203
|
-
const responsesGenerator =
|
|
1204
|
-
llmRequest,
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1213
|
+
const responsesGenerator = (0, import_instrumentation.recordInference)(
|
|
1214
|
+
{ invocationContext, llmRequest, modelResponseEvent },
|
|
1215
|
+
() => {
|
|
1216
|
+
var _a3;
|
|
1217
|
+
return llm.generateContentAsync(
|
|
1218
|
+
llmRequest,
|
|
1219
|
+
/* stream= */
|
|
1220
|
+
((_a3 = invocationContext.runConfig) == null ? void 0 : _a3.streamingMode) === import_run_config.StreamingMode.SSE,
|
|
1221
|
+
invocationContext.abortSignal
|
|
1222
|
+
);
|
|
1223
|
+
}
|
|
1208
1224
|
);
|
|
1209
1225
|
for await (const llmResponse of responsesGenerator) {
|
|
1210
|
-
(0
|
|
1211
|
-
invocationContext,
|
|
1212
|
-
eventId: modelResponseEvent.id,
|
|
1213
|
-
llmRequest,
|
|
1214
|
-
llmResponse
|
|
1215
|
-
});
|
|
1216
|
-
if ((_j = invocationContext.abortSignal) == null ? void 0 : _j.aborted) {
|
|
1226
|
+
if ((_i = invocationContext.abortSignal) == null ? void 0 : _i.aborted) {
|
|
1217
1227
|
return;
|
|
1218
1228
|
}
|
|
1219
1229
|
const alteredLlmResponse = await this.handleAfterModelCallback(
|
|
@@ -1221,7 +1231,7 @@ const _LlmAgent = class _LlmAgent extends (_b = import_base_agent.BaseAgent, _a
|
|
|
1221
1231
|
llmResponse,
|
|
1222
1232
|
modelResponseEvent
|
|
1223
1233
|
);
|
|
1224
|
-
if ((
|
|
1234
|
+
if ((_j = invocationContext.abortSignal) == null ? void 0 : _j.aborted) {
|
|
1225
1235
|
return;
|
|
1226
1236
|
}
|
|
1227
1237
|
yield alteredLlmResponse != null ? alteredLlmResponse : llmResponse;
|