@google/adk 2.2.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/a2a/a2a_remote_agent.js +4 -1
- package/dist/cjs/a2a/agent_card.js +102 -26
- package/dist/cjs/a2a/agent_to_a2a.js +1 -1
- package/dist/cjs/agents/agent_engine_client.js +172 -0
- package/dist/cjs/agents/base_agent.js +20 -4
- package/dist/cjs/agents/functions.js +227 -25
- package/dist/cjs/agents/instructions.js +6 -2
- package/dist/cjs/agents/invocation_context.js +26 -4
- package/dist/cjs/agents/langgraph_agent.js +152 -0
- package/dist/cjs/agents/llm_agent.js +194 -107
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +1 -1
- package/dist/cjs/agents/processors/code_execution_request_processor.js +18 -6
- package/dist/cjs/agents/processors/content_processor_utils.js +38 -10
- package/dist/cjs/agents/processors/content_request_processor.js +34 -2
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/cjs/agents/processors/nl_planning_processor.js +12 -3
- package/dist/cjs/artifacts/in_memory_artifact_service.js +14 -0
- package/dist/cjs/auth/auth_handler.js +37 -5
- package/dist/cjs/auth/auth_schemes.js +9 -0
- package/dist/cjs/cli/cli_eval.js +532 -0
- package/dist/cjs/cli/utils/envs.js +116 -0
- package/dist/cjs/cli/utils/evals.js +137 -0
- package/dist/cjs/cli/utils/logs.js +150 -0
- package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +7 -2
- package/dist/cjs/code_executors/code_execution_utils.js +48 -16
- package/dist/cjs/code_executors/code_executor_context.js +6 -2
- package/dist/cjs/code_executors/container_code_executor.js +27 -16
- package/dist/cjs/code_executors/unsafe_local_code_executor.js +6 -1
- package/dist/cjs/common.js +61 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +12 -10
- package/dist/cjs/context/token_based_context_compactor.js +2 -1
- package/dist/cjs/errors/input_validation_error.js +3 -2
- package/dist/cjs/events/event.js +4 -2
- package/dist/cjs/examples/example_util.js +23 -2
- package/dist/cjs/flows/llm_flows/audio_transcriber.js +170 -0
- package/dist/cjs/index.js +104 -1
- package/dist/cjs/integrations/agent_registry/helpers.js +1 -1
- package/dist/cjs/models/gemini_llm_connection.js +16 -8
- package/dist/cjs/models/google_llm.js +13 -16
- package/dist/cjs/models/llm_response.js +9 -1
- package/dist/cjs/models/registry.js +1 -1
- package/dist/cjs/models/routed_llm.js +9 -8
- package/dist/cjs/planners/plan_re_act_planner.js +1 -1
- package/dist/cjs/plugins/base_plugin.js +13 -23
- package/dist/cjs/runner/in_memory_runner.js +6 -11
- package/dist/cjs/runner/runner.js +105 -33
- package/dist/cjs/sessions/base_session_service.js +14 -8
- package/dist/cjs/sessions/database_session_service.js +50 -28
- package/dist/cjs/sessions/db/operations.js +1 -1
- package/dist/cjs/sessions/in_memory_session_service.js +3 -1
- package/dist/cjs/sessions/stale_session_error.js +59 -0
- package/dist/cjs/sessions/state.js +8 -4
- package/dist/cjs/sessions/vertex_ai_session_service.js +34 -15
- package/dist/cjs/skills/loader.js +52 -18
- package/dist/cjs/telemetry/setup.js +0 -1
- package/dist/cjs/telemetry/tracing.js +147 -73
- package/dist/cjs/tools/agent_tool.js +44 -0
- package/dist/cjs/tools/apihub_tool/apihub_toolset.js +137 -0
- package/dist/cjs/tools/apihub_tool/clients/apihub_client.js +272 -0
- package/dist/cjs/tools/apihub_tool/clients/secret_client.js +148 -0
- package/dist/cjs/tools/apihub_tool/clients/service_account.js +48 -0
- package/dist/cjs/tools/application_integration_tool/application_integration_toolset.js +263 -0
- package/dist/cjs/tools/application_integration_tool/clients/cloud_request.js +133 -0
- package/dist/cjs/tools/application_integration_tool/clients/connections_client.js +671 -0
- package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +223 -0
- package/dist/cjs/tools/application_integration_tool/integration_connector_tool.js +184 -0
- package/dist/cjs/tools/example_tool.js +10 -0
- package/dist/cjs/tools/function_tool.js +319 -0
- package/dist/cjs/tools/google_api_tool/google_api_tool.js +100 -0
- package/dist/cjs/tools/google_api_tool/google_api_toolset.js +173 -0
- package/dist/cjs/tools/google_api_tool/google_api_toolsets.js +124 -0
- package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +440 -0
- package/dist/cjs/tools/google_api_tool/index.js +61 -0
- package/dist/cjs/tools/load_artifacts_tool.js +12 -6
- package/dist/cjs/tools/load_memory_tool.js +12 -10
- package/dist/cjs/tools/mcp/index.js +12 -0
- package/dist/cjs/tools/mcp/mcp_session_manager.js +25 -0
- package/dist/cjs/tools/mcp/mcp_toolset.js +1 -14
- package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +1 -2
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +46 -2
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +4 -3
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +20 -6
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +17 -6
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +14 -2
- package/dist/cjs/tools/openapi_tool/openapi_toolset.js +7 -13
- package/dist/cjs/tools/openapi_tool/rest_api_tool.js +17 -1
- package/dist/cjs/tools/retrieval/base_retrieval_tool.js +18 -3
- package/dist/cjs/tools/toolbox_toolset.js +174 -0
- package/dist/cjs/tools/webmcp/webmcp_toolset.js +1 -14
- package/dist/cjs/utils/client_labels.js +19 -2
- package/dist/cjs/utils/env_aware_utils.js +6 -8
- package/dist/cjs/utils/error_utils.js +11 -11
- package/dist/cjs/utils/failover_utils.js +1 -1
- package/dist/cjs/utils/file_extension_utils.js +11 -0
- package/dist/cjs/utils/file_utils.js +2 -24
- package/dist/cjs/utils/gemini_schema_util.js +28 -7
- package/dist/cjs/utils/json_utils.js +49 -0
- package/dist/cjs/utils/live_connection_utils.js +4 -5
- package/dist/cjs/utils/logger_node.js +11 -1
- package/dist/cjs/utils/object_notation_utils.js +6 -3
- package/dist/cjs/utils/output_schema_utils.js +5 -2
- package/dist/cjs/utils/streaming_utils.js +12 -12
- package/dist/cjs/utils/task.js +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_remote_agent.js +4 -1
- package/dist/esm/a2a/agent_card.js +103 -27
- package/dist/esm/a2a/agent_to_a2a.js +5 -2
- package/dist/esm/agents/agent_engine_client.js +144 -0
- package/dist/esm/agents/base_agent.js +20 -4
- package/dist/esm/agents/functions.js +226 -25
- package/dist/esm/agents/instructions.js +6 -2
- package/dist/esm/agents/invocation_context.js +24 -4
- package/dist/esm/agents/langgraph_agent.js +123 -0
- package/dist/esm/agents/llm_agent.js +204 -110
- package/dist/esm/agents/processors/basic_llm_request_processor.js +1 -1
- package/dist/esm/agents/processors/code_execution_request_processor.js +21 -8
- package/dist/esm/agents/processors/content_processor_utils.js +38 -10
- package/dist/esm/agents/processors/content_request_processor.js +34 -2
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/esm/agents/processors/nl_planning_processor.js +12 -3
- package/dist/esm/artifacts/in_memory_artifact_service.js +14 -0
- package/dist/esm/auth/auth_handler.js +37 -5
- package/dist/esm/auth/auth_schemes.js +8 -0
- package/dist/esm/cli/cli_eval.js +510 -0
- package/dist/esm/cli/utils/envs.js +78 -0
- package/dist/esm/cli/utils/evals.js +109 -0
- package/dist/esm/cli/utils/logs.js +111 -0
- package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +7 -2
- package/dist/esm/code_executors/code_execution_utils.js +46 -16
- package/dist/esm/code_executors/code_executor_context.js +5 -2
- package/dist/esm/code_executors/container_code_executor.js +27 -16
- package/dist/esm/code_executors/unsafe_local_code_executor.js +6 -1
- package/dist/esm/common.js +65 -4
- package/dist/esm/context/summarizers/llm_summarizer.js +12 -10
- package/dist/esm/context/token_based_context_compactor.js +2 -1
- package/dist/esm/errors/input_validation_error.js +3 -2
- package/dist/esm/events/event.js +4 -2
- package/dist/esm/examples/example_util.js +21 -1
- package/dist/esm/flows/llm_flows/audio_transcriber.js +142 -0
- package/dist/esm/index.js +114 -2
- package/dist/esm/integrations/agent_registry/helpers.js +1 -1
- package/dist/esm/models/gemini_llm_connection.js +16 -8
- package/dist/esm/models/google_llm.js +14 -17
- package/dist/esm/models/llm_response.js +9 -1
- package/dist/esm/models/registry.js +1 -1
- package/dist/esm/models/routed_llm.js +9 -8
- package/dist/esm/planners/plan_re_act_planner.js +1 -1
- package/dist/esm/plugins/base_plugin.js +13 -23
- package/dist/esm/runner/in_memory_runner.js +6 -11
- package/dist/esm/runner/runner.js +105 -33
- package/dist/esm/sessions/base_session_service.js +12 -7
- package/dist/esm/sessions/database_session_service.js +49 -28
- package/dist/esm/sessions/db/operations.js +1 -1
- package/dist/esm/sessions/in_memory_session_service.js +3 -1
- package/dist/esm/sessions/stale_session_error.js +31 -0
- package/dist/esm/sessions/state.js +8 -4
- package/dist/esm/sessions/vertex_ai_session_service.js +34 -15
- package/dist/esm/skills/loader.js +51 -17
- package/dist/esm/telemetry/setup.js +1 -2
- package/dist/esm/telemetry/tracing.js +151 -74
- package/dist/esm/tools/agent_tool.js +44 -0
- package/dist/esm/tools/apihub_tool/apihub_toolset.js +101 -0
- package/dist/esm/tools/apihub_tool/clients/apihub_client.js +244 -0
- package/dist/esm/tools/apihub_tool/clients/secret_client.js +132 -0
- package/dist/esm/tools/apihub_tool/clients/service_account.js +21 -0
- package/dist/esm/tools/application_integration_tool/application_integration_toolset.js +245 -0
- package/dist/esm/tools/application_integration_tool/clients/cloud_request.js +103 -0
- package/dist/esm/tools/application_integration_tool/clients/connections_client.js +629 -0
- package/dist/esm/tools/application_integration_tool/clients/integration_client.js +219 -0
- package/dist/esm/tools/application_integration_tool/integration_connector_tool.js +158 -0
- package/dist/esm/tools/example_tool.js +13 -1
- package/dist/esm/tools/function_tool.js +316 -0
- package/dist/esm/tools/google_api_tool/google_api_tool.js +73 -0
- package/dist/esm/tools/google_api_tool/google_api_toolset.js +146 -0
- package/dist/esm/tools/google_api_tool/google_api_toolsets.js +94 -0
- package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +393 -0
- package/dist/esm/tools/google_api_tool/index.js +31 -0
- package/dist/esm/tools/load_artifacts_tool.js +10 -5
- package/dist/esm/tools/load_memory_tool.js +12 -10
- package/dist/esm/tools/mcp/index.js +6 -0
- package/dist/esm/tools/mcp/mcp_session_manager.js +25 -0
- package/dist/esm/tools/mcp/mcp_toolset.js +1 -14
- package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +1 -2
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +50 -3
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +4 -3
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +20 -6
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +17 -6
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -2
- package/dist/esm/tools/openapi_tool/openapi_toolset.js +6 -12
- package/dist/esm/tools/openapi_tool/rest_api_tool.js +17 -1
- package/dist/esm/tools/retrieval/base_retrieval_tool.js +16 -2
- package/dist/esm/tools/toolbox_toolset.js +148 -0
- package/dist/esm/tools/webmcp/webmcp_toolset.js +1 -14
- package/dist/esm/utils/client_labels.js +19 -2
- package/dist/esm/utils/env_aware_utils.js +6 -8
- package/dist/esm/utils/error_utils.js +9 -10
- package/dist/esm/utils/failover_utils.js +1 -1
- package/dist/esm/utils/file_extension_utils.js +11 -0
- package/dist/esm/utils/file_utils.js +2 -23
- package/dist/esm/utils/gemini_schema_util.js +27 -7
- package/dist/esm/utils/json_utils.js +21 -0
- package/dist/esm/utils/live_connection_utils.js +4 -5
- package/dist/esm/utils/logger_node.js +11 -1
- package/dist/esm/utils/object_notation_utils.js +4 -2
- package/dist/esm/utils/output_schema_utils.js +5 -2
- package/dist/esm/utils/streaming_utils.js +11 -11
- package/dist/esm/utils/task.js +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +9 -0
- package/dist/types/a2a/agent_card.d.ts +44 -1
- package/dist/types/a2a/agent_to_a2a.d.ts +9 -0
- package/dist/types/a2a/index.d.ts +1 -0
- package/dist/types/agents/agent_engine_client.d.ts +37 -0
- package/dist/types/agents/base_agent.d.ts +12 -0
- package/dist/types/agents/functions.d.ts +33 -1
- package/dist/types/agents/invocation_context.d.ts +20 -1
- package/dist/types/agents/langgraph_agent.d.ts +153 -0
- package/dist/types/agents/llm_agent.d.ts +5 -1
- package/dist/types/agents/processors/content_processor_utils.d.ts +4 -2
- package/dist/types/agents/processors/nl_planning_processor.d.ts +2 -1
- package/dist/types/auth/auth_handler.d.ts +28 -1
- package/dist/types/auth/auth_schemes.d.ts +13 -0
- package/dist/types/cli/cli_eval.d.ts +173 -0
- package/dist/types/cli/utils/envs.d.ts +23 -0
- package/dist/types/cli/utils/evals.d.ts +47 -0
- package/dist/types/cli/utils/logs.d.ts +38 -0
- package/dist/types/code_executors/code_execution_utils.d.ts +39 -0
- package/dist/types/code_executors/code_executor_context.d.ts +1 -0
- package/dist/types/code_executors/container_code_executor.d.ts +17 -5
- package/dist/types/common.d.ts +24 -5
- package/dist/types/errors/input_validation_error.d.ts +2 -1
- package/dist/types/events/event.d.ts +4 -0
- package/dist/types/examples/example_util.d.ts +17 -0
- package/dist/types/flows/llm_flows/audio_transcriber.d.ts +85 -0
- package/dist/types/index.d.ts +19 -2
- package/dist/types/models/gemini_llm_connection.d.ts +6 -7
- package/dist/types/models/routed_llm.d.ts +1 -1
- package/dist/types/plugins/base_plugin.d.ts +0 -10
- package/dist/types/runner/in_memory_runner.d.ts +2 -1
- package/dist/types/runner/runner.d.ts +34 -0
- package/dist/types/sessions/base_session_service.d.ts +5 -0
- package/dist/types/sessions/database_session_service.d.ts +17 -1
- package/dist/types/sessions/stale_session_error.d.ts +21 -0
- package/dist/types/sessions/state.d.ts +5 -1
- package/dist/types/sessions/vertex_ai_session_service.d.ts +8 -0
- package/dist/types/skills/loader.d.ts +3 -2
- package/dist/types/skills/skill.d.ts +1 -1
- package/dist/types/telemetry/tracing.d.ts +20 -4
- package/dist/types/tools/apihub_tool/apihub_toolset.d.ts +115 -0
- package/dist/types/tools/apihub_tool/clients/apihub_client.d.ts +142 -0
- package/dist/types/tools/apihub_tool/clients/secret_client.d.ts +55 -0
- package/dist/types/tools/apihub_tool/clients/service_account.d.ts +11 -0
- package/dist/types/tools/application_integration_tool/application_integration_toolset.d.ts +109 -0
- package/dist/types/tools/application_integration_tool/clients/cloud_request.d.ts +53 -0
- package/dist/types/tools/application_integration_tool/clients/connections_client.d.ts +229 -0
- package/dist/types/tools/application_integration_tool/clients/integration_client.d.ts +72 -0
- package/dist/types/tools/application_integration_tool/integration_connector_tool.d.ts +70 -0
- package/dist/types/tools/base_toolset.d.ts +6 -5
- package/dist/types/tools/example_tool.d.ts +10 -0
- package/dist/types/tools/function_tool.d.ts +32 -0
- package/dist/types/tools/google_api_tool/google_api_tool.d.ts +37 -0
- package/dist/types/tools/google_api_tool/google_api_toolset.d.ts +55 -0
- package/dist/types/tools/google_api_tool/google_api_toolsets.d.ts +48 -0
- package/dist/types/tools/google_api_tool/googleapi_to_openapi_converter.d.ts +165 -0
- package/dist/types/tools/google_api_tool/index.d.ts +10 -0
- package/dist/types/tools/load_artifacts_tool.d.ts +14 -1
- package/dist/types/tools/load_memory_tool.d.ts +23 -1
- package/dist/types/tools/mcp/index.d.ts +3 -0
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +34 -1
- package/dist/types/tools/mcp/mcp_toolset.d.ts +15 -0
- package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +19 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +18 -1
- package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +12 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +8 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +2 -1
- package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +5 -0
- package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +10 -0
- package/dist/types/tools/retrieval/base_retrieval_tool.d.ts +15 -0
- package/dist/types/tools/toolbox_toolset.d.ts +159 -0
- package/dist/types/utils/client_labels.d.ts +2 -1
- package/dist/types/utils/env_aware_utils.d.ts +18 -2
- package/dist/types/utils/error_utils.d.ts +7 -0
- package/dist/types/utils/file_utils.d.ts +6 -1
- package/dist/types/utils/gemini_schema_util.d.ts +9 -2
- package/dist/types/utils/json_utils.d.ts +11 -0
- package/dist/types/utils/object_notation_utils.d.ts +7 -0
- package/dist/types/utils/output_schema_utils.d.ts +3 -2
- package/dist/types/utils/simple_zod_to_json.d.ts +1 -2
- package/dist/types/utils/streaming_utils.d.ts +11 -4
- package/dist/types/version.d.ts +1 -1
- package/dist/web/index_web.js +117 -110
- package/dist/web/index_web.js.map +4 -4
- package/package.json +38 -26
- package/dist/cjs/models/gemini_continuation.js +0 -232
- package/dist/esm/models/gemini_continuation.js +0 -205
- package/dist/types/models/gemini_continuation.d.ts +0 -59
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
/**
|
|
27
|
+
* @license
|
|
28
|
+
* Copyright 2026 Google LLC
|
|
29
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
30
|
+
*/
|
|
31
|
+
import { randomUUID } from "node:crypto";
|
|
32
|
+
import * as fs from "node:fs";
|
|
33
|
+
import * as path from "node:path";
|
|
34
|
+
import { pathToFileURL } from "node:url";
|
|
35
|
+
import { isBaseAgent } from "../agents/base_agent.js";
|
|
36
|
+
import {
|
|
37
|
+
isLlmAgent
|
|
38
|
+
} from "../agents/llm_agent.js";
|
|
39
|
+
import { InMemoryArtifactService } from "../artifacts/in_memory_artifact_service.js";
|
|
40
|
+
import { Runner } from "../runner/runner.js";
|
|
41
|
+
import { InMemorySessionService } from "../sessions/in_memory_session_service.js";
|
|
42
|
+
import { logger } from "../utils/logger.js";
|
|
43
|
+
import {
|
|
44
|
+
convertSessionToEvalFormat,
|
|
45
|
+
createEmptyState
|
|
46
|
+
} from "./utils/evals.js";
|
|
47
|
+
const MISSING_EVAL_DEPENDENCIES_MESSAGE = "Eval module is not installed, please install via `pip install google-adk[eval]`.";
|
|
48
|
+
const TOOL_TRAJECTORY_SCORE_KEY = "tool_trajectory_avg_score";
|
|
49
|
+
const RESPONSE_MATCH_SCORE_KEY = "response_match_score";
|
|
50
|
+
const RESPONSE_EVALUATION_SCORE_KEY = "response_evaluation_score";
|
|
51
|
+
const EVAL_SESSION_ID_PREFIX = "___eval___session___";
|
|
52
|
+
const DEFAULT_CRITERIA = {
|
|
53
|
+
[TOOL_TRAJECTORY_SCORE_KEY]: 1,
|
|
54
|
+
[RESPONSE_MATCH_SCORE_KEY]: 0.8
|
|
55
|
+
};
|
|
56
|
+
var EvalStatus = /* @__PURE__ */ ((EvalStatus2) => {
|
|
57
|
+
EvalStatus2[EvalStatus2["PASSED"] = 1] = "PASSED";
|
|
58
|
+
EvalStatus2[EvalStatus2["FAILED"] = 2] = "FAILED";
|
|
59
|
+
EvalStatus2[EvalStatus2["NOT_EVALUATED"] = 3] = "NOT_EVALUATED";
|
|
60
|
+
return EvalStatus2;
|
|
61
|
+
})(EvalStatus || {});
|
|
62
|
+
function getEvaluationCriteriaOrDefault(evalConfigFilePath) {
|
|
63
|
+
if (evalConfigFilePath) {
|
|
64
|
+
const content = fs.readFileSync(evalConfigFilePath, "utf-8");
|
|
65
|
+
const configData = JSON.parse(content);
|
|
66
|
+
if (typeof configData === "object" && configData !== null && "criteria" in configData && typeof configData.criteria === "object" && configData.criteria !== null && !Array.isArray(configData.criteria)) {
|
|
67
|
+
return configData.criteria;
|
|
68
|
+
}
|
|
69
|
+
throw new Error(
|
|
70
|
+
`Invalid format for test_config.json at ${evalConfigFilePath}. Expected a 'criteria' dictionary.`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
logger.info("No config file supplied. Using default criteria.");
|
|
74
|
+
return { ...DEFAULT_CRITERIA };
|
|
75
|
+
}
|
|
76
|
+
__name(getEvaluationCriteriaOrDefault, "getEvaluationCriteriaOrDefault");
|
|
77
|
+
function resolveAgentModulePath(agentModuleFilePath) {
|
|
78
|
+
const resolved = path.resolve(agentModuleFilePath);
|
|
79
|
+
if (fs.existsSync(resolved) && fs.statSync(resolved).isDirectory()) {
|
|
80
|
+
const candidates = ["agent.js", "agent.ts", "index.js", "index.ts"];
|
|
81
|
+
for (const candidate of candidates) {
|
|
82
|
+
const candidatePath = path.join(resolved, candidate);
|
|
83
|
+
if (fs.existsSync(candidatePath) && fs.statSync(candidatePath).isFile()) {
|
|
84
|
+
return candidatePath;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return resolved;
|
|
89
|
+
}
|
|
90
|
+
__name(resolveAgentModulePath, "resolveAgentModulePath");
|
|
91
|
+
async function getRootAgent(agentModuleFilePath) {
|
|
92
|
+
var _a, _b, _c, _d;
|
|
93
|
+
const resolvedPath = resolveAgentModulePath(agentModuleFilePath);
|
|
94
|
+
const moduleUrl = pathToFileURL(resolvedPath).href;
|
|
95
|
+
const mod = await Promise.resolve().then(() => __toESM(require(moduleUrl)));
|
|
96
|
+
const nestedAgent = typeof mod.agent === "object" && mod.agent !== null ? mod.agent : void 0;
|
|
97
|
+
const candidate = (_d = (_c = (_b = (_a = mod.rootAgent) != null ? _a : mod.root_agent) != null ? _b : mod.default) != null ? _c : nestedAgent == null ? void 0 : nestedAgent.rootAgent) != null ? _d : nestedAgent == null ? void 0 : nestedAgent.root_agent;
|
|
98
|
+
if (isBaseAgent(candidate)) {
|
|
99
|
+
return candidate;
|
|
100
|
+
}
|
|
101
|
+
throw new Error(
|
|
102
|
+
`No rootAgent found in module ${agentModuleFilePath}. Export a BaseAgent as 'rootAgent'.`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
__name(getRootAgent, "getRootAgent");
|
|
106
|
+
async function tryGetResetFunc(agentModuleFilePath) {
|
|
107
|
+
var _a, _b, _c;
|
|
108
|
+
try {
|
|
109
|
+
const resolvedPath = resolveAgentModulePath(agentModuleFilePath);
|
|
110
|
+
const moduleUrl = pathToFileURL(resolvedPath).href;
|
|
111
|
+
const mod = await Promise.resolve().then(() => __toESM(require(moduleUrl)));
|
|
112
|
+
const nestedAgent = typeof mod.agent === "object" && mod.agent !== null ? mod.agent : void 0;
|
|
113
|
+
const resetCandidate = (_c = (_b = (_a = mod.reset_data) != null ? _a : mod.resetData) != null ? _b : nestedAgent == null ? void 0 : nestedAgent.reset_data) != null ? _c : nestedAgent == null ? void 0 : nestedAgent.resetData;
|
|
114
|
+
if (typeof resetCandidate === "function") {
|
|
115
|
+
return resetCandidate;
|
|
116
|
+
}
|
|
117
|
+
} catch {
|
|
118
|
+
}
|
|
119
|
+
return void 0;
|
|
120
|
+
}
|
|
121
|
+
__name(tryGetResetFunc, "tryGetResetFunc");
|
|
122
|
+
function parseAndGetEvalsToRun(evalSetFilePaths) {
|
|
123
|
+
const evalSetToEvals = {};
|
|
124
|
+
for (const inputEvalSet of evalSetFilePaths) {
|
|
125
|
+
let evalSetFile;
|
|
126
|
+
let evals = [];
|
|
127
|
+
if (inputEvalSet.includes(":")) {
|
|
128
|
+
const colonIndex = inputEvalSet.indexOf(":");
|
|
129
|
+
evalSetFile = inputEvalSet.slice(0, colonIndex);
|
|
130
|
+
evals = inputEvalSet.slice(colonIndex + 1).split(",").filter((s) => s.length > 0);
|
|
131
|
+
} else {
|
|
132
|
+
evalSetFile = inputEvalSet;
|
|
133
|
+
}
|
|
134
|
+
if (!Object.prototype.hasOwnProperty.call(evalSetToEvals, evalSetFile)) {
|
|
135
|
+
evalSetToEvals[evalSetFile] = [];
|
|
136
|
+
}
|
|
137
|
+
evalSetToEvals[evalSetFile].push(...evals);
|
|
138
|
+
}
|
|
139
|
+
return evalSetToEvals;
|
|
140
|
+
}
|
|
141
|
+
__name(parseAndGetEvalsToRun, "parseAndGetEvalsToRun");
|
|
142
|
+
function deepEqual(a, b) {
|
|
143
|
+
if (Object.is(a, b)) {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
if (Array.isArray(a) !== Array.isArray(b)) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
153
|
+
if (a.length !== b.length) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
for (let i = 0; i < a.length; i++) {
|
|
157
|
+
if (!deepEqual(a[i], b[i])) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
const keysA = Object.keys(a);
|
|
164
|
+
const keysB = Object.keys(b);
|
|
165
|
+
if (keysA.length !== keysB.length) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
for (const key of keysA) {
|
|
169
|
+
if (!Object.prototype.hasOwnProperty.call(b, key) || !deepEqual(
|
|
170
|
+
a[key],
|
|
171
|
+
b[key]
|
|
172
|
+
)) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
__name(deepEqual, "deepEqual");
|
|
179
|
+
function toolUsesEqual(actual, expected) {
|
|
180
|
+
if (actual.length !== expected.length) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
for (let i = 0; i < actual.length; i++) {
|
|
184
|
+
if (actual[i].tool_name !== expected[i].tool_name || !deepEqual(actual[i].tool_input, expected[i].tool_input)) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
__name(toolUsesEqual, "toolUsesEqual");
|
|
191
|
+
function computeRouge1FMeasure(target, prediction) {
|
|
192
|
+
var _a, _b, _c, _d;
|
|
193
|
+
const targetTokens = (_a = target.toLowerCase().match(/[a-z0-9]+/g)) != null ? _a : [];
|
|
194
|
+
const predictionTokens = (_b = prediction.toLowerCase().match(/[a-z0-9]+/g)) != null ? _b : [];
|
|
195
|
+
if (targetTokens.length === 0 && predictionTokens.length === 0) {
|
|
196
|
+
return 1;
|
|
197
|
+
}
|
|
198
|
+
if (targetTokens.length === 0 || predictionTokens.length === 0) {
|
|
199
|
+
return 0;
|
|
200
|
+
}
|
|
201
|
+
const targetCounts = /* @__PURE__ */ new Map();
|
|
202
|
+
for (const token of targetTokens) {
|
|
203
|
+
targetCounts.set(token, ((_c = targetCounts.get(token)) != null ? _c : 0) + 1);
|
|
204
|
+
}
|
|
205
|
+
let overlap = 0;
|
|
206
|
+
for (const token of predictionTokens) {
|
|
207
|
+
const remaining = (_d = targetCounts.get(token)) != null ? _d : 0;
|
|
208
|
+
if (remaining > 0) {
|
|
209
|
+
overlap += 1;
|
|
210
|
+
targetCounts.set(token, remaining - 1);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const precision = overlap / predictionTokens.length;
|
|
214
|
+
const recall = overlap / targetTokens.length;
|
|
215
|
+
if (precision + recall === 0) {
|
|
216
|
+
return 0;
|
|
217
|
+
}
|
|
218
|
+
return 2 * precision * recall / (precision + recall);
|
|
219
|
+
}
|
|
220
|
+
__name(computeRouge1FMeasure, "computeRouge1FMeasure");
|
|
221
|
+
function evaluateSingleMetric(metric, actualInvocations, expectedInvocations) {
|
|
222
|
+
var _a, _b, _c, _d;
|
|
223
|
+
const numInvocations = Math.min(
|
|
224
|
+
actualInvocations.length,
|
|
225
|
+
expectedInvocations.length
|
|
226
|
+
);
|
|
227
|
+
if (numInvocations === 0) {
|
|
228
|
+
return {
|
|
229
|
+
overall: {
|
|
230
|
+
metric_name: metric.metric_name,
|
|
231
|
+
threshold: metric.threshold,
|
|
232
|
+
score: void 0,
|
|
233
|
+
eval_status: 3 /* NOT_EVALUATED */
|
|
234
|
+
},
|
|
235
|
+
perInvocation: []
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
const perInvocation = [];
|
|
239
|
+
let totalScore = 0;
|
|
240
|
+
for (let i = 0; i < numInvocations; i++) {
|
|
241
|
+
const actual = actualInvocations[i];
|
|
242
|
+
const expected = expectedInvocations[i];
|
|
243
|
+
let score = 0;
|
|
244
|
+
if (metric.metric_name === TOOL_TRAJECTORY_SCORE_KEY) {
|
|
245
|
+
score = toolUsesEqual(
|
|
246
|
+
(_a = actual.expected_tool_use) != null ? _a : [],
|
|
247
|
+
(_b = expected.expected_tool_use) != null ? _b : []
|
|
248
|
+
) ? 1 : 0;
|
|
249
|
+
} else if (metric.metric_name === RESPONSE_MATCH_SCORE_KEY || metric.metric_name === RESPONSE_EVALUATION_SCORE_KEY) {
|
|
250
|
+
score = computeRouge1FMeasure(
|
|
251
|
+
(_c = expected.reference) != null ? _c : "",
|
|
252
|
+
(_d = actual.reference) != null ? _d : ""
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
totalScore += score;
|
|
256
|
+
perInvocation.push({
|
|
257
|
+
metric_name: metric.metric_name,
|
|
258
|
+
threshold: metric.threshold,
|
|
259
|
+
score,
|
|
260
|
+
eval_status: score >= metric.threshold ? 1 /* PASSED */ : 2 /* FAILED */
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
const avgScore = totalScore / numInvocations;
|
|
264
|
+
return {
|
|
265
|
+
overall: {
|
|
266
|
+
metric_name: metric.metric_name,
|
|
267
|
+
threshold: metric.threshold,
|
|
268
|
+
score: avgScore,
|
|
269
|
+
eval_status: avgScore >= metric.threshold ? 1 /* PASSED */ : 2 /* FAILED */
|
|
270
|
+
},
|
|
271
|
+
perInvocation
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
__name(evaluateSingleMetric, "evaluateSingleMetric");
|
|
275
|
+
function installMockToolOutputCallbacks(agent, interceptor, savedCallbacks) {
|
|
276
|
+
if (isLlmAgent(agent) && !savedCallbacks.has(agent)) {
|
|
277
|
+
savedCallbacks.set(agent, agent.beforeToolCallback);
|
|
278
|
+
const existing = agent.beforeToolCallback;
|
|
279
|
+
agent.beforeToolCallback = existing ? [interceptor, ...Array.isArray(existing) ? existing : [existing]] : interceptor;
|
|
280
|
+
}
|
|
281
|
+
for (const subAgent of agent.subAgents) {
|
|
282
|
+
installMockToolOutputCallbacks(subAgent, interceptor, savedCallbacks);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
__name(installMockToolOutputCallbacks, "installMockToolOutputCallbacks");
|
|
286
|
+
async function generateActualInvocations(rootAgent, evalCase, resetFunc, sessionService, artifactService) {
|
|
287
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
288
|
+
if (resetFunc) {
|
|
289
|
+
await resetFunc();
|
|
290
|
+
}
|
|
291
|
+
const appName = (_b = (_a = evalCase.initial_session) == null ? void 0 : _a.app_name) != null ? _b : "EvaluationGenerator";
|
|
292
|
+
const userId = (_d = (_c = evalCase.initial_session) == null ? void 0 : _c.user_id) != null ? _d : "test_user_id";
|
|
293
|
+
const sessionId = `${EVAL_SESSION_ID_PREFIX}${randomUUID()}`;
|
|
294
|
+
const activeSessionService = sessionService != null ? sessionService : new InMemorySessionService();
|
|
295
|
+
const activeArtifactService = artifactService != null ? artifactService : new InMemoryArtifactService();
|
|
296
|
+
const initialState = createEmptyState(
|
|
297
|
+
rootAgent,
|
|
298
|
+
(_f = (_e = evalCase.initial_session) == null ? void 0 : _e.state) != null ? _f : {}
|
|
299
|
+
);
|
|
300
|
+
await activeSessionService.createSession({
|
|
301
|
+
appName,
|
|
302
|
+
userId,
|
|
303
|
+
sessionId,
|
|
304
|
+
state: initialState
|
|
305
|
+
});
|
|
306
|
+
const pendingMockToolUses = [];
|
|
307
|
+
for (const turn of evalCase.data) {
|
|
308
|
+
for (const expectedTool of (_g = turn.expected_tool_use) != null ? _g : []) {
|
|
309
|
+
if (expectedTool.mock_tool_output !== void 0) {
|
|
310
|
+
pendingMockToolUses.push({ ...expectedTool });
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
const savedCallbacks = /* @__PURE__ */ new Map();
|
|
315
|
+
if (pendingMockToolUses.length > 0) {
|
|
316
|
+
const interceptor = /* @__PURE__ */ __name(({ tool, args }) => {
|
|
317
|
+
const idx = pendingMockToolUses.findIndex(
|
|
318
|
+
(expected) => {
|
|
319
|
+
var _a2;
|
|
320
|
+
return expected.mock_tool_output !== void 0 && tool.name === expected.tool_name && deepEqual(args, (_a2 = expected.tool_input) != null ? _a2 : {});
|
|
321
|
+
}
|
|
322
|
+
);
|
|
323
|
+
if (idx !== -1) {
|
|
324
|
+
const [matched] = pendingMockToolUses.splice(idx, 1);
|
|
325
|
+
return { result: matched.mock_tool_output };
|
|
326
|
+
}
|
|
327
|
+
return void 0;
|
|
328
|
+
}, "interceptor");
|
|
329
|
+
installMockToolOutputCallbacks(rootAgent, interceptor, savedCallbacks);
|
|
330
|
+
}
|
|
331
|
+
const runner = new Runner({
|
|
332
|
+
appName,
|
|
333
|
+
agent: rootAgent,
|
|
334
|
+
sessionService: activeSessionService,
|
|
335
|
+
artifactService: activeArtifactService
|
|
336
|
+
});
|
|
337
|
+
try {
|
|
338
|
+
for (const turn of evalCase.data) {
|
|
339
|
+
for await (const _event of runner.runAsync({
|
|
340
|
+
userId,
|
|
341
|
+
sessionId,
|
|
342
|
+
newMessage: {
|
|
343
|
+
role: "user",
|
|
344
|
+
parts: [{ text: turn.query }]
|
|
345
|
+
}
|
|
346
|
+
})) {
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
} finally {
|
|
350
|
+
for (const [llmAgent, originalCallback] of savedCallbacks.entries()) {
|
|
351
|
+
llmAgent.beforeToolCallback = originalCallback;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
const recordedSession = await activeSessionService.getSession({
|
|
355
|
+
appName,
|
|
356
|
+
userId,
|
|
357
|
+
sessionId
|
|
358
|
+
});
|
|
359
|
+
const actualInvocations = convertSessionToEvalFormat(recordedSession);
|
|
360
|
+
while (actualInvocations.length < evalCase.data.length) {
|
|
361
|
+
const idx = actualInvocations.length;
|
|
362
|
+
actualInvocations.push({
|
|
363
|
+
query: evalCase.data[idx].query,
|
|
364
|
+
expected_tool_use: [],
|
|
365
|
+
expected_intermediate_agent_responses: [],
|
|
366
|
+
reference: ""
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
return { actualInvocations, sessionId, userId };
|
|
370
|
+
}
|
|
371
|
+
__name(generateActualInvocations, "generateActualInvocations");
|
|
372
|
+
function resolveEvalCasesForSet(evalSetId, entries) {
|
|
373
|
+
if (entries.length > 0 && typeof entries[0] === "string") {
|
|
374
|
+
const filterNames = entries;
|
|
375
|
+
const fileData = JSON.parse(
|
|
376
|
+
fs.readFileSync(evalSetId, "utf-8")
|
|
377
|
+
);
|
|
378
|
+
return fileData.filter((e) => filterNames.includes(e.name));
|
|
379
|
+
}
|
|
380
|
+
if (entries.length === 0 && fs.existsSync(evalSetId) && fs.statSync(evalSetId).isFile()) {
|
|
381
|
+
return JSON.parse(fs.readFileSync(evalSetId, "utf-8"));
|
|
382
|
+
}
|
|
383
|
+
return entries;
|
|
384
|
+
}
|
|
385
|
+
__name(resolveEvalCasesForSet, "resolveEvalCasesForSet");
|
|
386
|
+
function printCaseDetailedResults(result) {
|
|
387
|
+
var _a;
|
|
388
|
+
logger.info(
|
|
389
|
+
`Eval result for ${result.eval_set_file}:${result.eval_id}: ${EvalStatus[result.final_eval_status]}`
|
|
390
|
+
);
|
|
391
|
+
for (const metricResult of result.overall_eval_metric_results) {
|
|
392
|
+
logger.info(
|
|
393
|
+
` Metric ${metricResult.metric_name}: score=${(_a = metricResult.score) != null ? _a : "N/A"} threshold=${metricResult.threshold} status=${EvalStatus[metricResult.eval_status]}`
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
__name(printCaseDetailedResults, "printCaseDetailedResults");
|
|
398
|
+
async function* runEvals(optionsOrMap, rootAgentArg, resetFuncArg, evalMetricsArg, printDetailedResultsArg = false, sessionServiceArg, artifactServiceArg) {
|
|
399
|
+
var _a, _b;
|
|
400
|
+
let evalCasesByEvalSetId;
|
|
401
|
+
let rootAgent;
|
|
402
|
+
let resetFunc;
|
|
403
|
+
let evalMetrics;
|
|
404
|
+
let printDetailedResults;
|
|
405
|
+
let sessionService;
|
|
406
|
+
let artifactService;
|
|
407
|
+
if (rootAgentArg === void 0 && "evalCasesByEvalSetId" in optionsOrMap && "rootAgent" in optionsOrMap && isBaseAgent(optionsOrMap.rootAgent)) {
|
|
408
|
+
const opts = optionsOrMap;
|
|
409
|
+
evalCasesByEvalSetId = opts.evalCasesByEvalSetId;
|
|
410
|
+
rootAgent = opts.rootAgent;
|
|
411
|
+
resetFunc = opts.resetFunc;
|
|
412
|
+
evalMetrics = (_a = opts.evalMetrics) != null ? _a : Object.entries(DEFAULT_CRITERIA).map(([metric_name, threshold]) => ({
|
|
413
|
+
metric_name,
|
|
414
|
+
threshold
|
|
415
|
+
}));
|
|
416
|
+
printDetailedResults = (_b = opts.printDetailedResults) != null ? _b : false;
|
|
417
|
+
sessionService = opts.sessionService;
|
|
418
|
+
artifactService = opts.artifactService;
|
|
419
|
+
} else {
|
|
420
|
+
evalCasesByEvalSetId = optionsOrMap;
|
|
421
|
+
if (!rootAgentArg) {
|
|
422
|
+
throw new Error("rootAgent is required to run evaluations.");
|
|
423
|
+
}
|
|
424
|
+
rootAgent = rootAgentArg;
|
|
425
|
+
resetFunc = resetFuncArg;
|
|
426
|
+
evalMetrics = evalMetricsArg != null ? evalMetricsArg : Object.entries(DEFAULT_CRITERIA).map(([metric_name, threshold]) => ({
|
|
427
|
+
metric_name,
|
|
428
|
+
threshold
|
|
429
|
+
}));
|
|
430
|
+
printDetailedResults = printDetailedResultsArg;
|
|
431
|
+
sessionService = sessionServiceArg;
|
|
432
|
+
artifactService = artifactServiceArg;
|
|
433
|
+
}
|
|
434
|
+
for (const [evalSetId, rawEntries] of Object.entries(evalCasesByEvalSetId)) {
|
|
435
|
+
const evalCases = resolveEvalCasesForSet(evalSetId, rawEntries);
|
|
436
|
+
for (const evalCase of evalCases) {
|
|
437
|
+
const evalName = evalCase.name;
|
|
438
|
+
const { actualInvocations, sessionId, userId } = await generateActualInvocations(
|
|
439
|
+
rootAgent,
|
|
440
|
+
evalCase,
|
|
441
|
+
resetFunc,
|
|
442
|
+
sessionService,
|
|
443
|
+
artifactService
|
|
444
|
+
);
|
|
445
|
+
const overallEvalMetricResults = [];
|
|
446
|
+
const evalMetricResultsPairs = [];
|
|
447
|
+
const perInvocationMap = evalCase.data.map(
|
|
448
|
+
(expectedInvocation, idx) => ({
|
|
449
|
+
actual_invocation: actualInvocations[idx],
|
|
450
|
+
expected_invocation: expectedInvocation,
|
|
451
|
+
eval_metric_results: []
|
|
452
|
+
})
|
|
453
|
+
);
|
|
454
|
+
for (const metric of evalMetrics) {
|
|
455
|
+
const { overall, perInvocation } = evaluateSingleMetric(
|
|
456
|
+
metric,
|
|
457
|
+
actualInvocations,
|
|
458
|
+
evalCase.data
|
|
459
|
+
);
|
|
460
|
+
overallEvalMetricResults.push(overall);
|
|
461
|
+
evalMetricResultsPairs.push([metric, overall]);
|
|
462
|
+
for (let i = 0; i < perInvocation.length; i++) {
|
|
463
|
+
if (perInvocationMap[i]) {
|
|
464
|
+
perInvocationMap[i].eval_metric_results.push(perInvocation[i]);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
let finalEvalStatus = 3 /* NOT_EVALUATED */;
|
|
469
|
+
for (const overallMetricResult of overallEvalMetricResults) {
|
|
470
|
+
if (overallMetricResult.eval_status === 1 /* PASSED */) {
|
|
471
|
+
if (finalEvalStatus === 3 /* NOT_EVALUATED */) {
|
|
472
|
+
finalEvalStatus = 1 /* PASSED */;
|
|
473
|
+
}
|
|
474
|
+
} else if (overallMetricResult.eval_status === 2 /* FAILED */) {
|
|
475
|
+
finalEvalStatus = 2 /* FAILED */;
|
|
476
|
+
break;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
const result = {
|
|
480
|
+
eval_set_file: evalSetId,
|
|
481
|
+
eval_id: evalName,
|
|
482
|
+
final_eval_status: finalEvalStatus,
|
|
483
|
+
eval_metric_results: evalMetricResultsPairs,
|
|
484
|
+
overall_eval_metric_results: overallEvalMetricResults,
|
|
485
|
+
eval_metric_result_per_invocation: perInvocationMap,
|
|
486
|
+
session_id: sessionId,
|
|
487
|
+
user_id: userId
|
|
488
|
+
};
|
|
489
|
+
if (printDetailedResults) {
|
|
490
|
+
printCaseDetailedResults(result);
|
|
491
|
+
}
|
|
492
|
+
yield result;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
__name(runEvals, "runEvals");
|
|
497
|
+
export {
|
|
498
|
+
DEFAULT_CRITERIA,
|
|
499
|
+
EVAL_SESSION_ID_PREFIX,
|
|
500
|
+
EvalStatus,
|
|
501
|
+
MISSING_EVAL_DEPENDENCIES_MESSAGE,
|
|
502
|
+
RESPONSE_EVALUATION_SCORE_KEY,
|
|
503
|
+
RESPONSE_MATCH_SCORE_KEY,
|
|
504
|
+
TOOL_TRAJECTORY_SCORE_KEY,
|
|
505
|
+
getEvaluationCriteriaOrDefault,
|
|
506
|
+
getRootAgent,
|
|
507
|
+
parseAndGetEvalsToRun,
|
|
508
|
+
runEvals,
|
|
509
|
+
tryGetResetFunc
|
|
510
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
/**
|
|
6
|
+
* @license
|
|
7
|
+
* Copyright 2026 Google LLC
|
|
8
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
*/
|
|
10
|
+
import * as fs from "node:fs";
|
|
11
|
+
import * as path from "node:path";
|
|
12
|
+
import { logger } from "../../utils/logger.js";
|
|
13
|
+
function walkToRootUntilFound(folder, filename = ".env") {
|
|
14
|
+
const checkpath = path.join(folder, filename);
|
|
15
|
+
if (fs.existsSync(checkpath) && fs.statSync(checkpath).isFile()) {
|
|
16
|
+
return path.resolve(checkpath);
|
|
17
|
+
}
|
|
18
|
+
const parentFolder = path.dirname(folder);
|
|
19
|
+
if (parentFolder === folder) {
|
|
20
|
+
return "";
|
|
21
|
+
}
|
|
22
|
+
return walkToRootUntilFound(parentFolder, filename);
|
|
23
|
+
}
|
|
24
|
+
__name(walkToRootUntilFound, "walkToRootUntilFound");
|
|
25
|
+
function parseAndLoadDotenv(content) {
|
|
26
|
+
const lines = content.split(/\r?\n/);
|
|
27
|
+
for (const rawLine of lines) {
|
|
28
|
+
const trimmed = rawLine.trim();
|
|
29
|
+
if (!trimmed || trimmed.startsWith("#")) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const stripped = trimmed.replace(/^export\s+/, "");
|
|
33
|
+
const eqIndex = stripped.indexOf("=");
|
|
34
|
+
if (eqIndex <= 0) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const key = stripped.slice(0, eqIndex).trim();
|
|
38
|
+
if (!key) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
let value = stripped.slice(eqIndex + 1).trim();
|
|
42
|
+
if (value.length >= 2 && (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'"))) {
|
|
43
|
+
const quote = value[0];
|
|
44
|
+
value = value.slice(1, -1);
|
|
45
|
+
if (quote === '"') {
|
|
46
|
+
value = value.replace(/\\n/g, "\n").replace(/\\r/g, "\r").replace(/\\"/g, '"').replace(/\\\\/g, "\\");
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
const commentIndex = value.search(/\s+#/);
|
|
50
|
+
if (commentIndex !== -1) {
|
|
51
|
+
value = value.slice(0, commentIndex).trimEnd();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
process.env[key] = value;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
__name(parseAndLoadDotenv, "parseAndLoadDotenv");
|
|
58
|
+
function loadDotenvForAgent(agentName, agentParentFolder = ".", filename = ".env") {
|
|
59
|
+
let startingFolder = path.resolve(agentParentFolder, agentName);
|
|
60
|
+
if (fs.existsSync(startingFolder) && fs.statSync(startingFolder).isFile()) {
|
|
61
|
+
startingFolder = path.dirname(startingFolder);
|
|
62
|
+
}
|
|
63
|
+
const dotenvFilePath = walkToRootUntilFound(startingFolder, filename);
|
|
64
|
+
if (dotenvFilePath) {
|
|
65
|
+
const content = fs.readFileSync(dotenvFilePath, "utf-8");
|
|
66
|
+
parseAndLoadDotenv(content);
|
|
67
|
+
logger.info(
|
|
68
|
+
`Loaded ${filename} file for ${agentName} at ${dotenvFilePath}`
|
|
69
|
+
);
|
|
70
|
+
} else {
|
|
71
|
+
logger.info(`No ${filename} file found for ${agentName}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
__name(loadDotenvForAgent, "loadDotenvForAgent");
|
|
75
|
+
export {
|
|
76
|
+
loadDotenvForAgent,
|
|
77
|
+
walkToRootUntilFound
|
|
78
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
/**
|
|
6
|
+
* @license
|
|
7
|
+
* Copyright 2026 Google LLC
|
|
8
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
*/
|
|
10
|
+
import { isLlmAgent } from "../../agents/llm_agent.js";
|
|
11
|
+
function convertSessionToEvalFormat(session) {
|
|
12
|
+
var _a, _b, _c;
|
|
13
|
+
const events = session && session.events ? session.events : [];
|
|
14
|
+
const evalCases = [];
|
|
15
|
+
let i = 0;
|
|
16
|
+
while (i < events.length) {
|
|
17
|
+
const event = events[i];
|
|
18
|
+
if (event.author === "user") {
|
|
19
|
+
let userQuery = "";
|
|
20
|
+
if (event.content && event.content.parts) {
|
|
21
|
+
for (const part of event.content.parts) {
|
|
22
|
+
if (part.text) {
|
|
23
|
+
userQuery = part.text;
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const expectedToolUse = [];
|
|
29
|
+
const expectedIntermediateAgentResponses = [];
|
|
30
|
+
let finalResponse = "";
|
|
31
|
+
let j = i + 1;
|
|
32
|
+
while (j < events.length) {
|
|
33
|
+
const subsequentEvent = events[j];
|
|
34
|
+
if (subsequentEvent.author === "user") {
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
if (subsequentEvent.content && subsequentEvent.content.parts) {
|
|
38
|
+
let hasToolAction = false;
|
|
39
|
+
for (const part of subsequentEvent.content.parts) {
|
|
40
|
+
if (part.functionCall) {
|
|
41
|
+
expectedToolUse.push({
|
|
42
|
+
tool_name: (_a = part.functionCall.name) != null ? _a : "",
|
|
43
|
+
tool_input: (_b = part.functionCall.args) != null ? _b : {}
|
|
44
|
+
});
|
|
45
|
+
hasToolAction = true;
|
|
46
|
+
} else if (part.functionResponse) {
|
|
47
|
+
hasToolAction = true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (!hasToolAction) {
|
|
51
|
+
expectedIntermediateAgentResponses.push([
|
|
52
|
+
(_c = subsequentEvent.author) != null ? _c : "",
|
|
53
|
+
subsequentEvent.content.parts
|
|
54
|
+
]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
j += 1;
|
|
58
|
+
}
|
|
59
|
+
if (expectedIntermediateAgentResponses.length > 0) {
|
|
60
|
+
const lastResponse = expectedIntermediateAgentResponses.pop();
|
|
61
|
+
if (lastResponse) {
|
|
62
|
+
const [, lastParts] = lastResponse;
|
|
63
|
+
finalResponse = lastParts.filter((part) => Boolean(part.text)).map((part) => {
|
|
64
|
+
var _a2;
|
|
65
|
+
return (_a2 = part.text) != null ? _a2 : "";
|
|
66
|
+
}).join("");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
evalCases.push({
|
|
70
|
+
query: userQuery,
|
|
71
|
+
expected_tool_use: expectedToolUse,
|
|
72
|
+
expected_intermediate_agent_responses: expectedIntermediateAgentResponses,
|
|
73
|
+
reference: finalResponse
|
|
74
|
+
});
|
|
75
|
+
i = j;
|
|
76
|
+
} else {
|
|
77
|
+
i += 1;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return evalCases;
|
|
81
|
+
}
|
|
82
|
+
__name(convertSessionToEvalFormat, "convertSessionToEvalFormat");
|
|
83
|
+
function populateEmptyState(agent, allState) {
|
|
84
|
+
for (const subAgent of agent.subAgents) {
|
|
85
|
+
populateEmptyState(subAgent, allState);
|
|
86
|
+
}
|
|
87
|
+
if (isLlmAgent(agent) && agent.instruction && typeof agent.instruction === "string") {
|
|
88
|
+
const matches = agent.instruction.matchAll(/\{([\w]+)\}/g);
|
|
89
|
+
for (const match of matches) {
|
|
90
|
+
allState[match[1]] = "";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
__name(populateEmptyState, "populateEmptyState");
|
|
95
|
+
function createEmptyState(agent, initializedStates) {
|
|
96
|
+
const subAgentsState = {};
|
|
97
|
+
populateEmptyState(agent, subAgentsState);
|
|
98
|
+
if (initializedStates) {
|
|
99
|
+
for (const [k, v] of Object.entries(initializedStates)) {
|
|
100
|
+
subAgentsState[k] = v;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return subAgentsState;
|
|
104
|
+
}
|
|
105
|
+
__name(createEmptyState, "createEmptyState");
|
|
106
|
+
export {
|
|
107
|
+
convertSessionToEvalFormat,
|
|
108
|
+
createEmptyState
|
|
109
|
+
};
|