@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
|
@@ -8,7 +8,9 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
8
8
|
* SPDX-License-Identifier: Apache-2.0
|
|
9
9
|
*/
|
|
10
10
|
var _a, _b;
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
createUserContent
|
|
13
|
+
} from "@google/genai";
|
|
12
14
|
import { isEmpty } from "lodash-es";
|
|
13
15
|
import {
|
|
14
16
|
createEvent,
|
|
@@ -21,6 +23,7 @@ import {
|
|
|
21
23
|
mergeEventActions
|
|
22
24
|
} from "../events/event_actions.js";
|
|
23
25
|
import { BaseTool } from "../tools/base_tool.js";
|
|
26
|
+
import { isComputerUseTool } from "../tools/computer_use/computer_use_tool.js";
|
|
24
27
|
import { isFunctionTool } from "../tools/function_tool.js";
|
|
25
28
|
import { logger } from "../utils/logger.js";
|
|
26
29
|
import { Task } from "../utils/task.js";
|
|
@@ -31,10 +34,9 @@ import {
|
|
|
31
34
|
REQUEST_CREDENTIAL_FUNCTION_CALL_NAME
|
|
32
35
|
} from "./framework_function_calls.js";
|
|
33
36
|
import {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
} from "../telemetry/tracing.js";
|
|
37
|
+
recordMergedToolCalls,
|
|
38
|
+
recordToolExecution
|
|
39
|
+
} from "../telemetry/api/instrumentation.js";
|
|
38
40
|
function toolEventAuthor(invocationContext) {
|
|
39
41
|
var _a2, _b2;
|
|
40
42
|
return (_b2 = (_a2 = invocationContext.agent) == null ? void 0 : _a2.name) != null ? _b2 : "";
|
|
@@ -145,56 +147,45 @@ function generateRequestConfirmationEvent({
|
|
|
145
147
|
}
|
|
146
148
|
__name(generateRequestConfirmationEvent, "generateRequestConfirmationEvent");
|
|
147
149
|
async function callToolAsync(tool, args, toolContext) {
|
|
148
|
-
return
|
|
149
|
-
|
|
150
|
+
return recordToolExecution(
|
|
151
|
+
{ tool, args, invocationContext: toolContext.invocationContext },
|
|
152
|
+
async (scope) => {
|
|
150
153
|
logger.debug(`callToolAsync ${tool.name}`);
|
|
151
154
|
const result = await tool.runAsync({ args, toolContext });
|
|
152
|
-
|
|
153
|
-
tool,
|
|
154
|
-
args,
|
|
155
|
-
span,
|
|
155
|
+
scope.recordSuccess({
|
|
156
156
|
functionResponseEvent: buildResponseEvent(
|
|
157
157
|
tool,
|
|
158
158
|
result,
|
|
159
159
|
toolContext,
|
|
160
160
|
toolContext.invocationContext
|
|
161
161
|
),
|
|
162
|
-
|
|
163
|
-
invocationContext: toolContext.invocationContext
|
|
162
|
+
rawResult: result
|
|
164
163
|
});
|
|
165
164
|
return result;
|
|
166
|
-
} catch (error) {
|
|
167
|
-
traceToolCall({
|
|
168
|
-
tool,
|
|
169
|
-
args,
|
|
170
|
-
span,
|
|
171
|
-
error,
|
|
172
|
-
invocationContext: toolContext.invocationContext
|
|
173
|
-
});
|
|
174
|
-
throw error;
|
|
175
|
-
} finally {
|
|
176
|
-
span.end();
|
|
177
165
|
}
|
|
178
|
-
|
|
166
|
+
);
|
|
179
167
|
}
|
|
180
168
|
__name(callToolAsync, "callToolAsync");
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
const response = result;
|
|
191
|
-
const errorType = (_a2 = response.errorType) != null ? _a2 : response.error_type;
|
|
192
|
-
return typeof errorType === "string" ? errorType : void 0;
|
|
193
|
-
} catch {
|
|
194
|
-
return void 0;
|
|
169
|
+
const BASE64 = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
170
|
+
function buildFunctionResponse({
|
|
171
|
+
tool,
|
|
172
|
+
id,
|
|
173
|
+
response
|
|
174
|
+
}) {
|
|
175
|
+
const image = isComputerUseTool(tool) ? response == null ? void 0 : response["image"] : void 0;
|
|
176
|
+
if (typeof image !== "object" || image === null || !("data" in image) || !("mimetype" in image) || typeof image.data !== "string" || typeof image.mimetype !== "string" || !BASE64.test(image.data)) {
|
|
177
|
+
return { id, name: tool.name, response };
|
|
195
178
|
}
|
|
179
|
+
const rest = { ...response };
|
|
180
|
+
delete rest["image"];
|
|
181
|
+
return {
|
|
182
|
+
id,
|
|
183
|
+
name: tool.name,
|
|
184
|
+
response: rest,
|
|
185
|
+
parts: [{ inlineData: { data: image.data, mimeType: image.mimetype } }]
|
|
186
|
+
};
|
|
196
187
|
}
|
|
197
|
-
__name(
|
|
188
|
+
__name(buildFunctionResponse, "buildFunctionResponse");
|
|
198
189
|
function buildResponseEvent(tool, functionResult, toolContext, invocationContext) {
|
|
199
190
|
let responseResult;
|
|
200
191
|
if (typeof functionResult !== "object" || functionResult == null) {
|
|
@@ -205,11 +196,11 @@ function buildResponseEvent(tool, functionResult, toolContext, invocationContext
|
|
|
205
196
|
responseResult = functionResult;
|
|
206
197
|
}
|
|
207
198
|
const partFunctionResponse = {
|
|
208
|
-
functionResponse: {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
199
|
+
functionResponse: buildFunctionResponse({
|
|
200
|
+
tool,
|
|
201
|
+
id: toolContext.functionCallId,
|
|
202
|
+
response: responseResult
|
|
203
|
+
})
|
|
213
204
|
};
|
|
214
205
|
const content = {
|
|
215
206
|
role: "user",
|
|
@@ -312,38 +303,35 @@ async function answerUnresolvableCall({
|
|
|
312
303
|
toolsDict,
|
|
313
304
|
toolContext
|
|
314
305
|
}) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
306
|
+
var _a2;
|
|
307
|
+
const toolName = functionCall.name || "<unnamed>";
|
|
308
|
+
const error = new Error(
|
|
309
|
+
`Function ${toolName} is not found in the toolsDict.`
|
|
310
|
+
);
|
|
311
|
+
const tool = new ToolNotFoundPlaceholder(toolName, error);
|
|
312
|
+
return recordToolExecution(
|
|
313
|
+
{ tool, args: (_a2 = functionCall.args) != null ? _a2 : {}, invocationContext },
|
|
314
|
+
async () => {
|
|
315
|
+
var _a3, _b2;
|
|
316
|
+
const onToolErrorResponse = await invocationContext.pluginManager.runOnToolErrorCallback({
|
|
317
|
+
tool,
|
|
318
|
+
toolArgs: (_a3 = functionCall.args) != null ? _a3 : {},
|
|
319
|
+
toolContext,
|
|
320
|
+
error
|
|
321
|
+
});
|
|
322
|
+
if (onToolErrorResponse == null) {
|
|
323
|
+
const callableTools = Object.keys(toolsDict);
|
|
324
|
+
logger.warn(
|
|
325
|
+
`Could not resolve tool '${toolName}' for function call '${(_b2 = functionCall.id) != null ? _b2 : ""}'. Callable tools: ${callableTools.length ? callableTools.join(", ") : "(none)"}.
|
|
335
326
|
` + RESOLUTION_FAILURE_CAUSES
|
|
336
|
-
);
|
|
337
|
-
}
|
|
338
|
-
return buildResponseEvent(
|
|
339
|
-
tool,
|
|
340
|
-
onToolErrorResponse != null ? onToolErrorResponse : { error: error.message },
|
|
341
|
-
toolContext,
|
|
342
|
-
invocationContext
|
|
343
327
|
);
|
|
344
|
-
} finally {
|
|
345
|
-
span.end();
|
|
346
328
|
}
|
|
329
|
+
return buildResponseEvent(
|
|
330
|
+
tool,
|
|
331
|
+
onToolErrorResponse != null ? onToolErrorResponse : { error: error.message },
|
|
332
|
+
toolContext,
|
|
333
|
+
invocationContext
|
|
334
|
+
);
|
|
347
335
|
}
|
|
348
336
|
);
|
|
349
337
|
}
|
|
@@ -484,11 +472,11 @@ async function handleFunctionCallList({
|
|
|
484
472
|
invocationId: invocationContext.invocationId,
|
|
485
473
|
author: toolEventAuthor(invocationContext),
|
|
486
474
|
content: createUserContent({
|
|
487
|
-
functionResponse: {
|
|
475
|
+
functionResponse: buildFunctionResponse({
|
|
476
|
+
tool,
|
|
488
477
|
id: toolContext.functionCallId,
|
|
489
|
-
name: tool.name,
|
|
490
478
|
response: functionResponse
|
|
491
|
-
}
|
|
479
|
+
})
|
|
492
480
|
}),
|
|
493
481
|
actions: toolContext.actions,
|
|
494
482
|
branch: invocationContext.branch
|
|
@@ -502,18 +490,8 @@ async function handleFunctionCallList({
|
|
|
502
490
|
functionResponseEvents
|
|
503
491
|
);
|
|
504
492
|
if (functionResponseEvents.length > 1) {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
logger.debug("execute_tool (merged)");
|
|
508
|
-
traceMergedToolCalls({
|
|
509
|
-
responseEventId: mergedEvent.id,
|
|
510
|
-
functionResponseEvent: mergedEvent,
|
|
511
|
-
invocationContext
|
|
512
|
-
});
|
|
513
|
-
} finally {
|
|
514
|
-
span.end();
|
|
515
|
-
}
|
|
516
|
-
});
|
|
493
|
+
logger.debug("execute_tool (merged)");
|
|
494
|
+
recordMergedToolCalls({ responseEventId: mergedEvent.id });
|
|
517
495
|
}
|
|
518
496
|
return mergedEvent;
|
|
519
497
|
}
|
|
@@ -37,10 +37,13 @@ async function resolveKey(key, isOptional, rawMatch, readonlyContext) {
|
|
|
37
37
|
}
|
|
38
38
|
throw new Error(`Artifact ${fileName} not found.`);
|
|
39
39
|
}
|
|
40
|
-
return formatValue(
|
|
40
|
+
return formatValue(
|
|
41
|
+
asSafePartForLlm(artifact, fileName, { inlineMediaAsPlaceholder: true }),
|
|
42
|
+
true
|
|
43
|
+
);
|
|
41
44
|
}
|
|
42
45
|
if (isValidStateName(key)) {
|
|
43
|
-
if (
|
|
46
|
+
if (Object.hasOwn(invocationContext.session.state, key)) {
|
|
44
47
|
return formatValue(invocationContext.session.state[key], false);
|
|
45
48
|
}
|
|
46
49
|
if (isOptional) {
|
|
@@ -162,14 +165,12 @@ async function injectSessionState(template, readonlyContext) {
|
|
|
162
165
|
return result.join("");
|
|
163
166
|
}
|
|
164
167
|
__name(injectSessionState, "injectSessionState");
|
|
165
|
-
const
|
|
166
|
-
return /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
167
|
-
})();
|
|
168
|
+
const IDENTIFIER_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
168
169
|
function isIdentifier(s) {
|
|
169
170
|
if (s === "" || s === void 0) {
|
|
170
171
|
return false;
|
|
171
172
|
}
|
|
172
|
-
return
|
|
173
|
+
return IDENTIFIER_PATTERN.test(s);
|
|
173
174
|
}
|
|
174
175
|
__name(isIdentifier, "isIdentifier");
|
|
175
176
|
const VALID_PREFIXES = [State.APP_PREFIX, State.USER_PREFIX, State.TEMP_PREFIX];
|
|
@@ -8,7 +8,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
8
8
|
* SPDX-License-Identifier: Apache-2.0
|
|
9
9
|
*/
|
|
10
10
|
var _a, _b;
|
|
11
|
-
import {
|
|
11
|
+
import { newId } from "../utils/id_provider.js";
|
|
12
12
|
const LLM_CALLS_LIMIT_EXCEEDED_ERROR_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for(
|
|
13
13
|
"google.adk.llmCallsLimitExceededError"
|
|
14
14
|
);
|
|
@@ -111,7 +111,7 @@ const _InvocationContext = class _InvocationContext {
|
|
|
111
111
|
__name(_InvocationContext, "InvocationContext");
|
|
112
112
|
let InvocationContext = _InvocationContext;
|
|
113
113
|
function newInvocationContextId() {
|
|
114
|
-
return `e-${
|
|
114
|
+
return `e-${newId()}`;
|
|
115
115
|
}
|
|
116
116
|
__name(newInvocationContextId, "newInvocationContextId");
|
|
117
117
|
function requireAgent(ctx) {
|
|
@@ -9,7 +9,6 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
9
9
|
*/
|
|
10
10
|
var _a, _b;
|
|
11
11
|
import { Modality } from "@google/genai";
|
|
12
|
-
import { context, trace } from "@opentelemetry/api";
|
|
13
12
|
import { FinishTaskTool } from "../tools/finish_task_tool.js";
|
|
14
13
|
import { FunctionTool } from "../tools/function_tool.js";
|
|
15
14
|
import { AsyncQueue } from "../utils/async_queue.js";
|
|
@@ -26,7 +25,10 @@ import {
|
|
|
26
25
|
isFinalResponse,
|
|
27
26
|
populateClientFunctionCallId
|
|
28
27
|
} from "../events/event.js";
|
|
29
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
createEventActions,
|
|
30
|
+
isDefaultEventActions
|
|
31
|
+
} from "../events/event_actions.js";
|
|
30
32
|
import { isBaseLlm } from "../models/base_llm.js";
|
|
31
33
|
import { LLMRegistry } from "../models/registry.js";
|
|
32
34
|
import { isBuiltInPlanner } from "../planners/built_in_planner.js";
|
|
@@ -36,11 +38,9 @@ import { logger } from "../utils/logger.js";
|
|
|
36
38
|
import { canUseOutputSchemaWithTools } from "../utils/output_schema_utils.js";
|
|
37
39
|
import { Context } from "./context.js";
|
|
38
40
|
import {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
traceSendData
|
|
43
|
-
} from "../telemetry/tracing.js";
|
|
41
|
+
recordInference,
|
|
42
|
+
recordSendData
|
|
43
|
+
} from "../telemetry/api/instrumentation.js";
|
|
44
44
|
import { parseWithSchema } from "../utils/schema.js";
|
|
45
45
|
import { isZodObject, zodObjectToSchema } from "../utils/simple_zod_to_json.js";
|
|
46
46
|
import { BaseAgent } from "./base_agent.js";
|
|
@@ -103,6 +103,13 @@ function sleep(ms) {
|
|
|
103
103
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
104
104
|
}
|
|
105
105
|
__name(sleep, "sleep");
|
|
106
|
+
function hasSettledResponses(functionResponseEvent) {
|
|
107
|
+
const awaiting = functionResponseEvent.actions.requestedToolConfirmations;
|
|
108
|
+
return getFunctionResponses(functionResponseEvent).some(
|
|
109
|
+
(response) => !response.id || !Object.hasOwn(awaiting, response.id)
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
__name(hasSettledResponses, "hasSettledResponses");
|
|
106
113
|
const LIVE_KEYS = [
|
|
107
114
|
"responseModalities",
|
|
108
115
|
"speechConfig",
|
|
@@ -128,14 +135,14 @@ function applyLiveRunConfig(runConfig, llmRequest) {
|
|
|
128
135
|
}
|
|
129
136
|
__name(applyLiveRunConfig, "applyLiveRunConfig");
|
|
130
137
|
const ADK_AGENT_NAME_LABEL_KEY = "adk_agent_name";
|
|
131
|
-
async function convertToolUnionToTools(toolUnion,
|
|
138
|
+
async function convertToolUnionToTools(toolUnion, context) {
|
|
132
139
|
if (isBaseTool(toolUnion)) {
|
|
133
140
|
return [toolUnion];
|
|
134
141
|
}
|
|
135
142
|
if (isBaseNode(toolUnion)) {
|
|
136
143
|
return [new NodeTool(toolUnion)];
|
|
137
144
|
}
|
|
138
|
-
return await toolUnion.getTools(
|
|
145
|
+
return await toolUnion.getTools(context);
|
|
139
146
|
}
|
|
140
147
|
__name(convertToolUnionToTools, "convertToolUnionToTools");
|
|
141
148
|
const LLM_AGENT_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for("google.adk.llmAgent");
|
|
@@ -226,7 +233,7 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
226
233
|
}
|
|
227
234
|
if (config.generateContentConfig.responseSchema) {
|
|
228
235
|
throw new Error(
|
|
229
|
-
"Response schema must be set via LlmAgent.
|
|
236
|
+
"Response schema must be set via LlmAgent.outputSchema."
|
|
230
237
|
);
|
|
231
238
|
}
|
|
232
239
|
if (config.generateContentConfig.thinkingConfig && isBuiltInPlanner(this.planner) && this.planner.thinkingConfig) {
|
|
@@ -287,12 +294,12 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
287
294
|
* @param context The context to retrieve the session state.
|
|
288
295
|
* @returns The resolved instruction field.
|
|
289
296
|
*/
|
|
290
|
-
async canonicalInstruction(
|
|
297
|
+
async canonicalInstruction(context) {
|
|
291
298
|
if (typeof this.instruction === "string") {
|
|
292
299
|
return { instruction: this.instruction, requireStateInjection: true };
|
|
293
300
|
}
|
|
294
301
|
return {
|
|
295
|
-
instruction: await this.instruction(
|
|
302
|
+
instruction: await this.instruction(context),
|
|
296
303
|
requireStateInjection: false
|
|
297
304
|
};
|
|
298
305
|
}
|
|
@@ -304,7 +311,7 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
304
311
|
* @returns The resolved globalInstruction field.
|
|
305
312
|
* @deprecated Use GlobalInstructionPlugin instead.
|
|
306
313
|
*/
|
|
307
|
-
async canonicalGlobalInstruction(
|
|
314
|
+
async canonicalGlobalInstruction(context) {
|
|
308
315
|
if (typeof this.globalInstruction === "string") {
|
|
309
316
|
return {
|
|
310
317
|
instruction: this.globalInstruction,
|
|
@@ -312,7 +319,7 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
312
319
|
};
|
|
313
320
|
}
|
|
314
321
|
return {
|
|
315
|
-
instruction: await this.globalInstruction(
|
|
322
|
+
instruction: await this.globalInstruction(context),
|
|
316
323
|
requireStateInjection: false
|
|
317
324
|
};
|
|
318
325
|
}
|
|
@@ -321,10 +328,10 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
321
328
|
*
|
|
322
329
|
* This method is only for use by Agent Development Kit.
|
|
323
330
|
*/
|
|
324
|
-
async canonicalTools(
|
|
331
|
+
async canonicalTools(context) {
|
|
325
332
|
const resolvedTools = [];
|
|
326
333
|
for (const toolUnion of this.tools) {
|
|
327
|
-
const tools = await convertToolUnionToTools(toolUnion,
|
|
334
|
+
const tools = await convertToolUnionToTools(toolUnion, context);
|
|
328
335
|
resolvedTools.push(...tools);
|
|
329
336
|
}
|
|
330
337
|
return resolvedTools;
|
|
@@ -414,7 +421,15 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
414
421
|
);
|
|
415
422
|
return;
|
|
416
423
|
}
|
|
417
|
-
|
|
424
|
+
if (!event.content.parts.some(
|
|
425
|
+
(part) => part.text !== void 0 && !part.thought
|
|
426
|
+
)) {
|
|
427
|
+
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("");
|
|
418
433
|
let result = resultStr;
|
|
419
434
|
if (this.outputSchema) {
|
|
420
435
|
if (!resultStr.trim()) {
|
|
@@ -467,14 +482,14 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
467
482
|
async *runImpl(ctx, nodeInput) {
|
|
468
483
|
yield* runLlmAgentAsNode(this, ctx, nodeInput);
|
|
469
484
|
}
|
|
470
|
-
async *runAsyncImpl(
|
|
485
|
+
async *runAsyncImpl(context) {
|
|
471
486
|
var _a2, _b2;
|
|
472
487
|
while (true) {
|
|
473
488
|
let lastEvent = void 0;
|
|
474
489
|
let stepHadToolCalls = false;
|
|
475
490
|
let stepTransferred = false;
|
|
476
|
-
for await (const event of this.runOneStepAsync(
|
|
477
|
-
if ((_a2 =
|
|
491
|
+
for await (const event of this.runOneStepAsync(context)) {
|
|
492
|
+
if ((_a2 = context.abortSignal) == null ? void 0 : _a2.aborted) {
|
|
478
493
|
return;
|
|
479
494
|
}
|
|
480
495
|
lastEvent = event;
|
|
@@ -500,16 +515,16 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
500
515
|
}
|
|
501
516
|
}
|
|
502
517
|
}
|
|
503
|
-
async *runLiveImpl(
|
|
518
|
+
async *runLiveImpl(context) {
|
|
504
519
|
var _a2;
|
|
505
|
-
for await (const event of this.runLiveFlow(
|
|
506
|
-
if ((_a2 =
|
|
520
|
+
for await (const event of this.runLiveFlow(context)) {
|
|
521
|
+
if ((_a2 = context.abortSignal) == null ? void 0 : _a2.aborted) {
|
|
507
522
|
return;
|
|
508
523
|
}
|
|
509
524
|
this.maybeSaveOutputToState(event);
|
|
510
525
|
yield event;
|
|
511
526
|
}
|
|
512
|
-
if (
|
|
527
|
+
if (context.endInvocation) {
|
|
513
528
|
return;
|
|
514
529
|
}
|
|
515
530
|
}
|
|
@@ -586,18 +601,14 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
586
601
|
throw err;
|
|
587
602
|
}
|
|
588
603
|
if (llmRequest.contents.length > 0 && !invocationContext.liveSessionResumptionHandle) {
|
|
589
|
-
await
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
} finally {
|
|
598
|
-
span.end();
|
|
599
|
-
}
|
|
600
|
-
});
|
|
604
|
+
await recordSendData(
|
|
605
|
+
{
|
|
606
|
+
invocationContext,
|
|
607
|
+
eventId: createNewEventId(),
|
|
608
|
+
data: llmRequest.contents
|
|
609
|
+
},
|
|
610
|
+
() => connection.sendHistory(llmRequest.contents)
|
|
611
|
+
);
|
|
601
612
|
}
|
|
602
613
|
let sendError;
|
|
603
614
|
const sendAbort = new AbortController();
|
|
@@ -975,57 +986,45 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
975
986
|
if (invocationContext.endInvocation || ((_d = invocationContext.abortSignal) == null ? void 0 : _d.aborted)) {
|
|
976
987
|
return;
|
|
977
988
|
}
|
|
978
|
-
const
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
for await (const llmResponse of this.callLlmAsync(
|
|
988
|
-
invocationContext,
|
|
989
|
-
llmRequest,
|
|
990
|
-
modelResponseEvent
|
|
991
|
-
)) {
|
|
992
|
-
if ((_a3 = invocationContext.abortSignal) == null ? void 0 : _a3.aborted) {
|
|
993
|
-
return;
|
|
994
|
-
}
|
|
995
|
-
if (((_b3 = invocationContext.runConfig) == null ? void 0 : _b3.supportCfc) && isEvent(llmResponse)) {
|
|
996
|
-
modelResponseEvent.id = createNewEventId();
|
|
997
|
-
modelResponseEvent.timestamp = (/* @__PURE__ */ new Date()).getTime();
|
|
998
|
-
yield llmResponse;
|
|
999
|
-
continue;
|
|
1000
|
-
}
|
|
1001
|
-
for await (const event of this.postprocess(
|
|
1002
|
-
invocationContext,
|
|
1003
|
-
llmRequest,
|
|
1004
|
-
llmResponse,
|
|
1005
|
-
modelResponseEvent
|
|
1006
|
-
)) {
|
|
1007
|
-
if ((_c2 = invocationContext.abortSignal) == null ? void 0 : _c2.aborted) {
|
|
1008
|
-
return;
|
|
1009
|
-
}
|
|
1010
|
-
if (!event.partial) {
|
|
1011
|
-
modelResponseEvent.id = createNewEventId();
|
|
1012
|
-
modelResponseEvent.timestamp = (/* @__PURE__ */ new Date()).getTime();
|
|
1013
|
-
}
|
|
1014
|
-
yield event;
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
}, "responsesGenerator");
|
|
1018
|
-
yield* this.runAndHandleError(
|
|
1019
|
-
responsesGenerator.call(this),
|
|
1020
|
-
invocationContext,
|
|
1021
|
-
llmRequest,
|
|
1022
|
-
modelResponseEvent
|
|
1023
|
-
);
|
|
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;
|
|
1024
998
|
}
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
999
|
+
if (((_b3 = invocationContext.runConfig) == null ? void 0 : _b3.supportCfc) && isEvent(llmResponse)) {
|
|
1000
|
+
modelResponseEvent.id = 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 = 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
|
+
);
|
|
1029
1028
|
}
|
|
1030
1029
|
async *postprocess(invocationContext, llmRequest, llmResponse, modelResponseEvent) {
|
|
1031
1030
|
var _a2, _b2, _c, _d, _e, _f;
|
|
@@ -1068,6 +1067,9 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
1068
1067
|
if (!((_c = getFunctionCalls(mergedEvent)) == null ? void 0 : _c.length)) {
|
|
1069
1068
|
return;
|
|
1070
1069
|
}
|
|
1070
|
+
if (mergedEvent.partial) {
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1071
1073
|
if ((_d = invocationContext.runConfig) == null ? void 0 : _d.pauseOnToolCalls) {
|
|
1072
1074
|
invocationContext.endInvocation = true;
|
|
1073
1075
|
return;
|
|
@@ -1114,6 +1116,15 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
1114
1116
|
functionResponseEvent
|
|
1115
1117
|
});
|
|
1116
1118
|
if (toolConfirmationEvent) {
|
|
1119
|
+
if (hasSettledResponses(functionResponseEvent)) {
|
|
1120
|
+
const { requestedToolConfirmations, skipSummarization, ...settled } = functionResponseEvent.actions;
|
|
1121
|
+
functionResponseEvent.actions = createEventActions(settled);
|
|
1122
|
+
toolConfirmationEvent.actions = createEventActions({
|
|
1123
|
+
requestedToolConfirmations,
|
|
1124
|
+
skipSummarization
|
|
1125
|
+
});
|
|
1126
|
+
yield functionResponseEvent;
|
|
1127
|
+
}
|
|
1117
1128
|
yield toolConfirmationEvent;
|
|
1118
1129
|
invocationContext.endInvocation = true;
|
|
1119
1130
|
return;
|
|
@@ -1151,7 +1162,7 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
1151
1162
|
return agentToRun;
|
|
1152
1163
|
}
|
|
1153
1164
|
async *callLlmAsync(invocationContext, llmRequest, modelResponseEvent) {
|
|
1154
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j
|
|
1165
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1155
1166
|
const beforeModelResponse = await this.handleBeforeModelCallback(
|
|
1156
1167
|
invocationContext,
|
|
1157
1168
|
llmRequest,
|
|
@@ -1199,20 +1210,20 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
1199
1210
|
liveRequestQueue.close();
|
|
1200
1211
|
}
|
|
1201
1212
|
} else {
|
|
1202
|
-
const responsesGenerator =
|
|
1203
|
-
llmRequest,
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1213
|
+
const responsesGenerator = 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) === StreamingMode.SSE,
|
|
1221
|
+
invocationContext.abortSignal
|
|
1222
|
+
);
|
|
1223
|
+
}
|
|
1207
1224
|
);
|
|
1208
1225
|
for await (const llmResponse of responsesGenerator) {
|
|
1209
|
-
|
|
1210
|
-
invocationContext,
|
|
1211
|
-
eventId: modelResponseEvent.id,
|
|
1212
|
-
llmRequest,
|
|
1213
|
-
llmResponse
|
|
1214
|
-
});
|
|
1215
|
-
if ((_j = invocationContext.abortSignal) == null ? void 0 : _j.aborted) {
|
|
1226
|
+
if ((_i = invocationContext.abortSignal) == null ? void 0 : _i.aborted) {
|
|
1216
1227
|
return;
|
|
1217
1228
|
}
|
|
1218
1229
|
const alteredLlmResponse = await this.handleAfterModelCallback(
|
|
@@ -1220,7 +1231,7 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
1220
1231
|
llmResponse,
|
|
1221
1232
|
modelResponseEvent
|
|
1222
1233
|
);
|
|
1223
|
-
if ((
|
|
1234
|
+
if ((_j = invocationContext.abortSignal) == null ? void 0 : _j.aborted) {
|
|
1224
1235
|
return;
|
|
1225
1236
|
}
|
|
1226
1237
|
yield alteredLlmResponse != null ? alteredLlmResponse : llmResponse;
|