@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
|
@@ -39,6 +39,7 @@ __export(functions_exports, {
|
|
|
39
39
|
getLongRunningFunctionCalls: () => getLongRunningFunctionCalls,
|
|
40
40
|
handleFunctionCallList: () => handleFunctionCallList,
|
|
41
41
|
handleFunctionCallsAsync: () => handleFunctionCallsAsync,
|
|
42
|
+
handleFunctionCallsLive: () => handleFunctionCallsLive,
|
|
42
43
|
isToolNotFound: () => isToolNotFound,
|
|
43
44
|
mergeParallelFunctionResponseEvents: () => mergeParallelFunctionResponseEvents,
|
|
44
45
|
populateClientFunctionCallId: () => import_event2.populateClientFunctionCallId,
|
|
@@ -50,7 +51,10 @@ var import_lodash_es = require("lodash-es");
|
|
|
50
51
|
var import_event = require("../events/event.js");
|
|
51
52
|
var import_event_actions = require("../events/event_actions.js");
|
|
52
53
|
var import_base_tool = require("../tools/base_tool.js");
|
|
54
|
+
var import_function_tool = require("../tools/function_tool.js");
|
|
53
55
|
var import_logger = require("../utils/logger.js");
|
|
56
|
+
var import_task = require("../utils/task.js");
|
|
57
|
+
var import_active_streaming_tool = require("./active_streaming_tool.js");
|
|
54
58
|
var import_context = require("./context.js");
|
|
55
59
|
var import_framework_function_calls = require("./framework_function_calls.js");
|
|
56
60
|
var import_tracing = require("../telemetry/tracing.js");
|
|
@@ -69,6 +73,8 @@ function toolEventAuthor(invocationContext) {
|
|
|
69
73
|
__name(toolEventAuthor, "toolEventAuthor");
|
|
70
74
|
const functionsExportedForTestingOnly = {
|
|
71
75
|
handleFunctionCallList,
|
|
76
|
+
handleFunctionCallsLive,
|
|
77
|
+
processFunctionLiveHelper,
|
|
72
78
|
generateAuthEvent,
|
|
73
79
|
generateRequestConfirmationEvent
|
|
74
80
|
};
|
|
@@ -166,20 +172,49 @@ async function callToolAsync(tool, args, toolContext) {
|
|
|
166
172
|
(0, import_tracing.traceToolCall)({
|
|
167
173
|
tool,
|
|
168
174
|
args,
|
|
175
|
+
span,
|
|
169
176
|
functionResponseEvent: buildResponseEvent(
|
|
170
177
|
tool,
|
|
171
178
|
result,
|
|
172
179
|
toolContext,
|
|
173
180
|
toolContext.invocationContext
|
|
174
|
-
)
|
|
181
|
+
),
|
|
182
|
+
errorType: getToolResponseErrorType(result),
|
|
183
|
+
invocationContext: toolContext.invocationContext
|
|
175
184
|
});
|
|
176
185
|
return result;
|
|
186
|
+
} catch (error) {
|
|
187
|
+
(0, import_tracing.traceToolCall)({
|
|
188
|
+
tool,
|
|
189
|
+
args,
|
|
190
|
+
span,
|
|
191
|
+
error,
|
|
192
|
+
invocationContext: toolContext.invocationContext
|
|
193
|
+
});
|
|
194
|
+
throw error;
|
|
177
195
|
} finally {
|
|
178
196
|
span.end();
|
|
179
197
|
}
|
|
180
198
|
});
|
|
181
199
|
}
|
|
182
200
|
__name(callToolAsync, "callToolAsync");
|
|
201
|
+
function getToolResponseErrorType(result) {
|
|
202
|
+
var _a2;
|
|
203
|
+
if (result === null || typeof result !== "object" || Array.isArray(result)) {
|
|
204
|
+
return void 0;
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
if (!Object.hasOwn(result, "error")) {
|
|
208
|
+
return void 0;
|
|
209
|
+
}
|
|
210
|
+
const response = result;
|
|
211
|
+
const errorType = (_a2 = response.errorType) != null ? _a2 : response.error_type;
|
|
212
|
+
return typeof errorType === "string" ? errorType : void 0;
|
|
213
|
+
} catch {
|
|
214
|
+
return void 0;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
__name(getToolResponseErrorType, "getToolResponseErrorType");
|
|
183
218
|
function buildResponseEvent(tool, functionResult, toolContext, invocationContext) {
|
|
184
219
|
let responseResult;
|
|
185
220
|
if (typeof functionResult !== "object" || functionResult == null) {
|
|
@@ -232,6 +267,30 @@ async function handleFunctionCallsAsync({
|
|
|
232
267
|
});
|
|
233
268
|
}
|
|
234
269
|
__name(handleFunctionCallsAsync, "handleFunctionCallsAsync");
|
|
270
|
+
async function handleFunctionCallsLive({
|
|
271
|
+
invocationContext,
|
|
272
|
+
functionCallEvent,
|
|
273
|
+
toolsDict,
|
|
274
|
+
beforeToolCallbacks,
|
|
275
|
+
afterToolCallbacks,
|
|
276
|
+
filters,
|
|
277
|
+
toolConfirmationDict,
|
|
278
|
+
resumeInputsDict
|
|
279
|
+
}) {
|
|
280
|
+
const functionCalls = (0, import_event.getFunctionCalls)(functionCallEvent);
|
|
281
|
+
return handleFunctionCallList({
|
|
282
|
+
invocationContext,
|
|
283
|
+
functionCalls,
|
|
284
|
+
toolsDict,
|
|
285
|
+
beforeToolCallbacks,
|
|
286
|
+
afterToolCallbacks,
|
|
287
|
+
filters,
|
|
288
|
+
toolConfirmationDict,
|
|
289
|
+
resumeInputsDict,
|
|
290
|
+
isLive: true
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
__name(handleFunctionCallsLive, "handleFunctionCallsLive");
|
|
235
294
|
function normalizeCallbackResponse(response) {
|
|
236
295
|
if (response == null) {
|
|
237
296
|
return void 0;
|
|
@@ -317,7 +376,8 @@ async function handleFunctionCallList({
|
|
|
317
376
|
afterToolCallbacks,
|
|
318
377
|
filters,
|
|
319
378
|
toolConfirmationDict,
|
|
320
|
-
resumeInputsDict
|
|
379
|
+
resumeInputsDict,
|
|
380
|
+
isLive = false
|
|
321
381
|
}) {
|
|
322
382
|
var _a2;
|
|
323
383
|
const functionResponseEvents = [];
|
|
@@ -354,7 +414,6 @@ async function handleFunctionCallList({
|
|
|
354
414
|
import_logger.logger.debug(`execute_tool ${tool.name}`);
|
|
355
415
|
const functionArgs = (_a2 = functionCall.args) != null ? _a2 : {};
|
|
356
416
|
let functionResponse = null;
|
|
357
|
-
let functionResponseError;
|
|
358
417
|
functionResponse = await invocationContext.pluginManager.runBeforeToolCallback({
|
|
359
418
|
tool,
|
|
360
419
|
toolArgs: functionArgs,
|
|
@@ -375,7 +434,18 @@ async function handleFunctionCallList({
|
|
|
375
434
|
functionResponse = normalizeCallbackResponse(functionResponse);
|
|
376
435
|
if (functionResponse == null) {
|
|
377
436
|
try {
|
|
378
|
-
|
|
437
|
+
const rawFunctionResponse = isLive ? await processFunctionLiveHelper({
|
|
438
|
+
tool,
|
|
439
|
+
toolContext,
|
|
440
|
+
functionCall,
|
|
441
|
+
functionArgs,
|
|
442
|
+
invocationContext
|
|
443
|
+
}) : await callToolAsync(tool, functionArgs, toolContext);
|
|
444
|
+
if (rawFunctionResponse == null && !tool.isLongRunning) {
|
|
445
|
+
functionResponse = { result: rawFunctionResponse };
|
|
446
|
+
} else {
|
|
447
|
+
functionResponse = normalizeCallbackResponse(rawFunctionResponse);
|
|
448
|
+
}
|
|
379
449
|
} catch (e) {
|
|
380
450
|
if (e instanceof Error) {
|
|
381
451
|
const onToolErrorResponse = await invocationContext.pluginManager.runOnToolErrorCallback({
|
|
@@ -387,18 +457,19 @@ async function handleFunctionCallList({
|
|
|
387
457
|
if (onToolErrorResponse != null) {
|
|
388
458
|
functionResponse = normalizeCallbackResponse(onToolErrorResponse);
|
|
389
459
|
} else {
|
|
390
|
-
|
|
460
|
+
functionResponse = { error: e.message };
|
|
391
461
|
}
|
|
392
462
|
} else {
|
|
393
|
-
|
|
463
|
+
functionResponse = { error: e };
|
|
394
464
|
}
|
|
395
465
|
}
|
|
396
466
|
}
|
|
467
|
+
const callbackResult = functionResponse != null ? functionResponse : {};
|
|
397
468
|
let alteredFunctionResponse = await invocationContext.pluginManager.runAfterToolCallback({
|
|
398
469
|
tool,
|
|
399
470
|
toolArgs: functionArgs,
|
|
400
471
|
toolContext,
|
|
401
|
-
result:
|
|
472
|
+
result: callbackResult
|
|
402
473
|
});
|
|
403
474
|
if (alteredFunctionResponse == null) {
|
|
404
475
|
for (const callback of afterToolCallbacks) {
|
|
@@ -406,7 +477,7 @@ async function handleFunctionCallList({
|
|
|
406
477
|
tool,
|
|
407
478
|
args: functionArgs,
|
|
408
479
|
context: toolContext,
|
|
409
|
-
response:
|
|
480
|
+
response: callbackResult
|
|
410
481
|
});
|
|
411
482
|
if (alteredFunctionResponse) {
|
|
412
483
|
break;
|
|
@@ -429,13 +500,6 @@ async function handleFunctionCallList({
|
|
|
429
500
|
}
|
|
430
501
|
continue;
|
|
431
502
|
}
|
|
432
|
-
if (functionResponseError) {
|
|
433
|
-
functionResponse = { error: functionResponseError };
|
|
434
|
-
} else if (functionResponse == null) {
|
|
435
|
-
functionResponse = { result: functionResponse };
|
|
436
|
-
} else {
|
|
437
|
-
functionResponse = normalizeCallbackResponse(functionResponse);
|
|
438
|
-
}
|
|
439
503
|
const functionResponseEvent = (0, import_event.createEvent)({
|
|
440
504
|
invocationId: invocationContext.invocationId,
|
|
441
505
|
author: toolEventAuthor(invocationContext),
|
|
@@ -449,11 +513,6 @@ async function handleFunctionCallList({
|
|
|
449
513
|
actions: toolContext.actions,
|
|
450
514
|
branch: invocationContext.branch
|
|
451
515
|
});
|
|
452
|
-
import_logger.logger.debug("traceToolCall", {
|
|
453
|
-
tool: tool.name,
|
|
454
|
-
args: functionArgs,
|
|
455
|
-
functionResponseEvent: functionResponseEvent.id
|
|
456
|
-
});
|
|
457
516
|
functionResponseEvents.push(functionResponseEvent);
|
|
458
517
|
}
|
|
459
518
|
if (!functionResponseEvents.length) {
|
|
@@ -466,13 +525,10 @@ async function handleFunctionCallList({
|
|
|
466
525
|
import_tracing.tracer.startActiveSpan("execute_tool (merged)", (span) => {
|
|
467
526
|
try {
|
|
468
527
|
import_logger.logger.debug("execute_tool (merged)");
|
|
469
|
-
import_logger.logger.debug("traceMergedToolCalls", {
|
|
470
|
-
responseEventId: mergedEvent.id,
|
|
471
|
-
functionResponseEvent: mergedEvent.id
|
|
472
|
-
});
|
|
473
528
|
(0, import_tracing.traceMergedToolCalls)({
|
|
474
529
|
responseEventId: mergedEvent.id,
|
|
475
|
-
functionResponseEvent: mergedEvent
|
|
530
|
+
functionResponseEvent: mergedEvent,
|
|
531
|
+
invocationContext
|
|
476
532
|
});
|
|
477
533
|
} finally {
|
|
478
534
|
span.end();
|
|
@@ -510,6 +566,151 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
|
|
|
510
566
|
});
|
|
511
567
|
}
|
|
512
568
|
__name(mergeParallelFunctionResponseEvents, "mergeParallelFunctionResponseEvents");
|
|
569
|
+
function isAsyncGeneratorFunction(fn) {
|
|
570
|
+
return typeof fn === "function" && Object.prototype.toString.call(fn) === "[object AsyncGeneratorFunction]";
|
|
571
|
+
}
|
|
572
|
+
__name(isAsyncGeneratorFunction, "isAsyncGeneratorFunction");
|
|
573
|
+
function isStreamingTool(tool) {
|
|
574
|
+
const candidate = tool;
|
|
575
|
+
if (typeof candidate._callLive !== "function") {
|
|
576
|
+
return false;
|
|
577
|
+
}
|
|
578
|
+
if ((0, import_function_tool.isFunctionTool)(tool)) {
|
|
579
|
+
return isAsyncGeneratorFunction(candidate.execute);
|
|
580
|
+
}
|
|
581
|
+
return isAsyncGeneratorFunction(candidate.execute) || isAsyncGeneratorFunction(candidate.func) || isAsyncGeneratorFunction(candidate._callLive);
|
|
582
|
+
}
|
|
583
|
+
__name(isStreamingTool, "isStreamingTool");
|
|
584
|
+
async function* callToolLive({
|
|
585
|
+
tool,
|
|
586
|
+
args,
|
|
587
|
+
toolContext,
|
|
588
|
+
invocationContext
|
|
589
|
+
}) {
|
|
590
|
+
const results = tool._callLive({
|
|
591
|
+
args,
|
|
592
|
+
toolContext,
|
|
593
|
+
invocationContext
|
|
594
|
+
});
|
|
595
|
+
for await (const result of results) {
|
|
596
|
+
yield result;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
__name(callToolLive, "callToolLive");
|
|
600
|
+
async function waitForTaskWithTimeout(task, timeoutMs) {
|
|
601
|
+
let timeoutId;
|
|
602
|
+
const timeoutPromise = new Promise((resolve) => {
|
|
603
|
+
timeoutId = setTimeout(resolve, timeoutMs);
|
|
604
|
+
});
|
|
605
|
+
try {
|
|
606
|
+
await Promise.race([
|
|
607
|
+
task.promise.then(
|
|
608
|
+
() => void 0,
|
|
609
|
+
() => void 0
|
|
610
|
+
),
|
|
611
|
+
timeoutPromise
|
|
612
|
+
]);
|
|
613
|
+
} finally {
|
|
614
|
+
if (timeoutId !== void 0) {
|
|
615
|
+
clearTimeout(timeoutId);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
__name(waitForTaskWithTimeout, "waitForTaskWithTimeout");
|
|
620
|
+
const STOP_STREAMING_FUNCTION_NAME = "stop_streaming";
|
|
621
|
+
const STOP_STREAMING_TIMEOUT_MS = 1e3;
|
|
622
|
+
async function processFunctionLiveHelper({
|
|
623
|
+
tool,
|
|
624
|
+
toolContext,
|
|
625
|
+
functionCall,
|
|
626
|
+
functionArgs,
|
|
627
|
+
invocationContext
|
|
628
|
+
}) {
|
|
629
|
+
var _a2, _b2;
|
|
630
|
+
let functionResponse = void 0;
|
|
631
|
+
const targetFunctionName = typeof functionArgs["function_name"] === "string" ? functionArgs["function_name"] : typeof functionArgs["functionName"] === "string" ? functionArgs["functionName"] : void 0;
|
|
632
|
+
if (functionCall.name === STOP_STREAMING_FUNCTION_NAME && targetFunctionName !== void 0) {
|
|
633
|
+
const activeTasks = invocationContext.activeStreamingTools;
|
|
634
|
+
const activeTask = (_a2 = activeTasks == null ? void 0 : activeTasks[targetFunctionName]) == null ? void 0 : _a2.task;
|
|
635
|
+
if (activeTasks && activeTask && !activeTask.done()) {
|
|
636
|
+
activeTask.cancel();
|
|
637
|
+
await waitForTaskWithTimeout(activeTask, STOP_STREAMING_TIMEOUT_MS);
|
|
638
|
+
if (!activeTask.done()) {
|
|
639
|
+
import_logger.logger.warn(`The task for ${targetFunctionName} is not cancelled yet.`);
|
|
640
|
+
functionResponse = {
|
|
641
|
+
status: `The task is not cancelled yet for ${targetFunctionName}.`
|
|
642
|
+
};
|
|
643
|
+
} else {
|
|
644
|
+
activeTasks[targetFunctionName].task = void 0;
|
|
645
|
+
functionResponse = {
|
|
646
|
+
status: `Successfully stopped streaming function ${targetFunctionName}`
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
} else {
|
|
650
|
+
functionResponse = {
|
|
651
|
+
status: `No active streaming function named ${targetFunctionName} found`
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
} else if (isStreamingTool(tool)) {
|
|
655
|
+
const task = new import_task.Task(async (abortSignal) => {
|
|
656
|
+
var _a3, _b3;
|
|
657
|
+
const generator = callToolLive({
|
|
658
|
+
tool,
|
|
659
|
+
args: functionArgs,
|
|
660
|
+
toolContext,
|
|
661
|
+
invocationContext
|
|
662
|
+
});
|
|
663
|
+
let abortCleanup;
|
|
664
|
+
const abortPromise = new Promise(
|
|
665
|
+
(resolve) => {
|
|
666
|
+
if (abortSignal.aborted) {
|
|
667
|
+
resolve({ value: void 0, done: true });
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
const onAbort = /* @__PURE__ */ __name(() => {
|
|
671
|
+
resolve({ value: void 0, done: true });
|
|
672
|
+
}, "onAbort");
|
|
673
|
+
abortSignal.addEventListener("abort", onAbort, { once: true });
|
|
674
|
+
abortCleanup = /* @__PURE__ */ __name(() => abortSignal.removeEventListener("abort", onAbort), "abortCleanup");
|
|
675
|
+
}
|
|
676
|
+
);
|
|
677
|
+
try {
|
|
678
|
+
while (!abortSignal.aborted) {
|
|
679
|
+
const nextResult = await Promise.race([
|
|
680
|
+
generator.next(),
|
|
681
|
+
abortPromise
|
|
682
|
+
]);
|
|
683
|
+
if (abortSignal.aborted || nextResult.done) {
|
|
684
|
+
break;
|
|
685
|
+
}
|
|
686
|
+
const result = nextResult.value;
|
|
687
|
+
const updatedContent = (0, import_genai.createUserContent)(
|
|
688
|
+
`Function ${tool.name} returned: ${String(result)}`
|
|
689
|
+
);
|
|
690
|
+
(_a3 = invocationContext.liveRequestQueue) == null ? void 0 : _a3.sendContent(updatedContent);
|
|
691
|
+
}
|
|
692
|
+
} finally {
|
|
693
|
+
abortCleanup == null ? void 0 : abortCleanup();
|
|
694
|
+
if (abortSignal.aborted) {
|
|
695
|
+
void ((_b3 = generator.return) == null ? void 0 : _b3.call(generator, void 0));
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
(_b2 = invocationContext.activeStreamingTools) != null ? _b2 : invocationContext.activeStreamingTools = {};
|
|
700
|
+
if (tool.name in invocationContext.activeStreamingTools) {
|
|
701
|
+
invocationContext.activeStreamingTools[tool.name].task = task;
|
|
702
|
+
} else {
|
|
703
|
+
invocationContext.activeStreamingTools[tool.name] = new import_active_streaming_tool.ActiveStreamingTool({ task });
|
|
704
|
+
}
|
|
705
|
+
functionResponse = {
|
|
706
|
+
status: "The function is running asynchronously and the results are pending."
|
|
707
|
+
};
|
|
708
|
+
} else {
|
|
709
|
+
functionResponse = await callToolAsync(tool, functionArgs, toolContext);
|
|
710
|
+
}
|
|
711
|
+
return functionResponse;
|
|
712
|
+
}
|
|
713
|
+
__name(processFunctionLiveHelper, "processFunctionLiveHelper");
|
|
513
714
|
function findEventByFunctionCallId(events, functionCallId, endIndex = events.length) {
|
|
514
715
|
for (let i = endIndex - 1; i >= 0; i--) {
|
|
515
716
|
const event = events[i];
|
|
@@ -579,6 +780,7 @@ __name(getConflictingFunctionResponseAuthors, "getConflictingFunctionResponseAut
|
|
|
579
780
|
getLongRunningFunctionCalls,
|
|
580
781
|
handleFunctionCallList,
|
|
581
782
|
handleFunctionCallsAsync,
|
|
783
|
+
handleFunctionCallsLive,
|
|
582
784
|
isToolNotFound,
|
|
583
785
|
mergeParallelFunctionResponseEvents,
|
|
584
786
|
populateClientFunctionCallId,
|
|
@@ -29,6 +29,7 @@ __export(instructions_exports, {
|
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(instructions_exports);
|
|
31
31
|
var import_state = require("../sessions/state.js");
|
|
32
|
+
var import_load_artifacts_tool = require("../tools/load_artifacts_tool.js");
|
|
32
33
|
/**
|
|
33
34
|
* @license
|
|
34
35
|
* Copyright 2025 Google LLC
|
|
@@ -62,7 +63,7 @@ async function resolveKey(key, isOptional, rawMatch, readonlyContext) {
|
|
|
62
63
|
}
|
|
63
64
|
throw new Error(`Artifact ${fileName} not found.`);
|
|
64
65
|
}
|
|
65
|
-
return formatValue(artifact, true);
|
|
66
|
+
return formatValue((0, import_load_artifacts_tool.asSafePartForLlm)(artifact, fileName), true);
|
|
66
67
|
}
|
|
67
68
|
if (isValidStateName(key)) {
|
|
68
69
|
if (key in invocationContext.session.state) {
|
|
@@ -117,7 +118,10 @@ async function injectSessionState(template, readonlyContext) {
|
|
|
117
118
|
resolved: resolveSourceNode(match[0], match[1], match[2], scope)
|
|
118
119
|
})) : [];
|
|
119
120
|
const pattern = /\{+[^{}]*}+/g;
|
|
120
|
-
const matches = Array.from(template.matchAll(pattern))
|
|
121
|
+
const matches = Array.from(template.matchAll(pattern)).filter((match) => {
|
|
122
|
+
const previous = template[match.index - 1];
|
|
123
|
+
return previous !== "$" && previous !== "\\";
|
|
124
|
+
});
|
|
121
125
|
if (matches.length === 0 && sourceMatches.length === 0) {
|
|
122
126
|
return template;
|
|
123
127
|
}
|
|
@@ -26,6 +26,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
26
26
|
var invocation_context_exports = {};
|
|
27
27
|
__export(invocation_context_exports, {
|
|
28
28
|
InvocationContext: () => InvocationContext,
|
|
29
|
+
LlmCallsLimitExceededError: () => LlmCallsLimitExceededError,
|
|
30
|
+
isLlmCallsLimitExceededError: () => isLlmCallsLimitExceededError,
|
|
29
31
|
newInvocationContextId: () => newInvocationContextId,
|
|
30
32
|
requireAgent: () => requireAgent
|
|
31
33
|
});
|
|
@@ -36,6 +38,24 @@ var import_env_aware_utils = require("../utils/env_aware_utils.js");
|
|
|
36
38
|
* Copyright 2025 Google LLC
|
|
37
39
|
* SPDX-License-Identifier: Apache-2.0
|
|
38
40
|
*/
|
|
41
|
+
var _a, _b;
|
|
42
|
+
const LLM_CALLS_LIMIT_EXCEEDED_ERROR_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for(
|
|
43
|
+
"google.adk.llmCallsLimitExceededError"
|
|
44
|
+
);
|
|
45
|
+
const _LlmCallsLimitExceededError = class _LlmCallsLimitExceededError extends (_b = Error, _a = LLM_CALLS_LIMIT_EXCEEDED_ERROR_SIGNATURE_SYMBOL, _b) {
|
|
46
|
+
constructor(message) {
|
|
47
|
+
super(message);
|
|
48
|
+
this[_a] = true;
|
|
49
|
+
this.name = "LlmCallsLimitExceededError";
|
|
50
|
+
Object.setPrototypeOf(this, _LlmCallsLimitExceededError.prototype);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
__name(_LlmCallsLimitExceededError, "LlmCallsLimitExceededError");
|
|
54
|
+
let LlmCallsLimitExceededError = _LlmCallsLimitExceededError;
|
|
55
|
+
function isLlmCallsLimitExceededError(obj) {
|
|
56
|
+
return typeof obj === "object" && obj !== null && LLM_CALLS_LIMIT_EXCEEDED_ERROR_SIGNATURE_SYMBOL in obj && obj[LLM_CALLS_LIMIT_EXCEEDED_ERROR_SIGNATURE_SYMBOL] === true;
|
|
57
|
+
}
|
|
58
|
+
__name(isLlmCallsLimitExceededError, "isLlmCallsLimitExceededError");
|
|
39
59
|
const _InvocationCostManager = class _InvocationCostManager {
|
|
40
60
|
constructor() {
|
|
41
61
|
this.numberOfLlmCalls = 0;
|
|
@@ -49,7 +69,7 @@ const _InvocationCostManager = class _InvocationCostManager {
|
|
|
49
69
|
incrementAndEnforceLlmCallsLimit(runConfig) {
|
|
50
70
|
this.numberOfLlmCalls++;
|
|
51
71
|
if (runConfig && runConfig.maxLlmCalls > 0 && this.numberOfLlmCalls > runConfig.maxLlmCalls) {
|
|
52
|
-
throw new
|
|
72
|
+
throw new LlmCallsLimitExceededError(
|
|
53
73
|
`Max number of llm calls limit of ${runConfig.maxLlmCalls} exceeded`
|
|
54
74
|
);
|
|
55
75
|
}
|
|
@@ -62,7 +82,7 @@ const _InvocationContext = class _InvocationContext {
|
|
|
62
82
|
* @param params The parameters for creating an invocation context.
|
|
63
83
|
*/
|
|
64
84
|
constructor(params) {
|
|
65
|
-
var
|
|
85
|
+
var _a2, _b2;
|
|
66
86
|
this.artifactService = params.artifactService;
|
|
67
87
|
this.sessionService = params.sessionService;
|
|
68
88
|
this.memoryService = params.memoryService;
|
|
@@ -79,9 +99,9 @@ const _InvocationContext = class _InvocationContext {
|
|
|
79
99
|
this.abortSignal = params.abortSignal;
|
|
80
100
|
this.workflowInstructionScope = params.workflowInstructionScope;
|
|
81
101
|
this.isolationScope = params.isolationScope;
|
|
82
|
-
this.nodeToolDepth = (
|
|
102
|
+
this.nodeToolDepth = (_a2 = params.nodeToolDepth) != null ? _a2 : 0;
|
|
83
103
|
this.a2aMetadata = params.a2aMetadata;
|
|
84
|
-
this.invocationCostManager = (
|
|
104
|
+
this.invocationCostManager = (_b2 = params.invocationCostManager) != null ? _b2 : new InvocationCostManager();
|
|
85
105
|
this.liveRequestQueue = params.liveRequestQueue;
|
|
86
106
|
this.liveSessionResumptionHandle = params.liveSessionResumptionHandle;
|
|
87
107
|
}
|
|
@@ -136,6 +156,8 @@ __name(requireAgent, "requireAgent");
|
|
|
136
156
|
// Annotate the CommonJS export names for ESM import in node:
|
|
137
157
|
0 && (module.exports = {
|
|
138
158
|
InvocationContext,
|
|
159
|
+
LlmCallsLimitExceededError,
|
|
160
|
+
isLlmCallsLimitExceededError,
|
|
139
161
|
newInvocationContextId,
|
|
140
162
|
requireAgent
|
|
141
163
|
});
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
|
+
var langgraph_agent_exports = {};
|
|
27
|
+
__export(langgraph_agent_exports, {
|
|
28
|
+
LangGraphAgent: () => LangGraphAgent,
|
|
29
|
+
getLastHumanMessages: () => getLastHumanMessages,
|
|
30
|
+
isLangGraphAgent: () => isLangGraphAgent
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(langgraph_agent_exports);
|
|
33
|
+
var import_event = require("../events/event.js");
|
|
34
|
+
var import_base_agent = require("./base_agent.js");
|
|
35
|
+
/**
|
|
36
|
+
* @license
|
|
37
|
+
* Copyright 2026 Google LLC
|
|
38
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
39
|
+
*/
|
|
40
|
+
var _a, _b;
|
|
41
|
+
function getLastHumanMessages(events) {
|
|
42
|
+
var _a2, _b2, _c;
|
|
43
|
+
const messages = [];
|
|
44
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
45
|
+
const event = events[i];
|
|
46
|
+
if (messages.length > 0 && event.author !== "user") {
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
const text = (_c = (_b2 = (_a2 = event.content) == null ? void 0 : _a2.parts) == null ? void 0 : _b2[0]) == null ? void 0 : _c.text;
|
|
50
|
+
if (event.author === "user" && text !== void 0) {
|
|
51
|
+
messages.push({ type: "human", content: text });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return messages.reverse();
|
|
55
|
+
}
|
|
56
|
+
__name(getLastHumanMessages, "getLastHumanMessages");
|
|
57
|
+
function extractMessageText(content) {
|
|
58
|
+
if (typeof content === "string") {
|
|
59
|
+
return content;
|
|
60
|
+
}
|
|
61
|
+
return content.map((part) => {
|
|
62
|
+
var _a2;
|
|
63
|
+
return typeof part === "string" ? part : (_a2 = part.text) != null ? _a2 : "";
|
|
64
|
+
}).join("");
|
|
65
|
+
}
|
|
66
|
+
__name(extractMessageText, "extractMessageText");
|
|
67
|
+
const LANGGRAPH_AGENT_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for(
|
|
68
|
+
"google.adk.langGraphAgent"
|
|
69
|
+
);
|
|
70
|
+
function isLangGraphAgent(obj) {
|
|
71
|
+
return typeof obj === "object" && obj !== null && LANGGRAPH_AGENT_SIGNATURE_SYMBOL in obj && obj[LANGGRAPH_AGENT_SIGNATURE_SYMBOL] === true;
|
|
72
|
+
}
|
|
73
|
+
__name(isLangGraphAgent, "isLangGraphAgent");
|
|
74
|
+
const _LangGraphAgent = class _LangGraphAgent extends (_b = import_base_agent.BaseAgent, _a = LANGGRAPH_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
75
|
+
constructor(config) {
|
|
76
|
+
var _a2;
|
|
77
|
+
super(config);
|
|
78
|
+
this[_a] = true;
|
|
79
|
+
this.graph = config.graph;
|
|
80
|
+
this.instruction = (_a2 = config.instruction) != null ? _a2 : "";
|
|
81
|
+
}
|
|
82
|
+
async *runAsyncImpl(ctx) {
|
|
83
|
+
var _a2, _b2, _c;
|
|
84
|
+
const config = {
|
|
85
|
+
// LangGraph.js checkpointers read `configurable.thread_id`.
|
|
86
|
+
configurable: { thread_id: ctx.session.id }
|
|
87
|
+
};
|
|
88
|
+
let currentGraphState;
|
|
89
|
+
if (this.graph.checkpointer) {
|
|
90
|
+
if (typeof this.graph.getState !== "function") {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`LangGraphAgent '${this.name}' requires graph.getState() when graph.checkpointer is configured.`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
currentGraphState = await this.graph.getState(config);
|
|
96
|
+
}
|
|
97
|
+
const graphMessages = (_b2 = (_a2 = currentGraphState == null ? void 0 : currentGraphState.values) == null ? void 0 : _a2.messages) != null ? _b2 : [];
|
|
98
|
+
const messages = this.instruction && graphMessages.length === 0 ? [{ type: "system", content: this.instruction }] : [];
|
|
99
|
+
messages.push(...this.getMessages(ctx.session.events));
|
|
100
|
+
const finalState = await this.graph.invoke({ messages }, config);
|
|
101
|
+
const finalMessages = (_c = finalState.messages) != null ? _c : [];
|
|
102
|
+
const lastMessage = finalMessages[finalMessages.length - 1];
|
|
103
|
+
if (!lastMessage) {
|
|
104
|
+
throw new Error(
|
|
105
|
+
`LangGraphAgent '${this.name}' received no messages from graph.invoke().`
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
yield (0, import_event.createEvent)({
|
|
109
|
+
invocationId: ctx.invocationId,
|
|
110
|
+
author: this.name,
|
|
111
|
+
branch: ctx.branch,
|
|
112
|
+
content: {
|
|
113
|
+
role: "model",
|
|
114
|
+
parts: [{ text: extractMessageText(lastMessage.content) }]
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
async *runLiveImpl(_ctx) {
|
|
119
|
+
yield* [];
|
|
120
|
+
throw new Error("This is not supported yet for LangGraphAgent.");
|
|
121
|
+
}
|
|
122
|
+
getMessages(events) {
|
|
123
|
+
if (this.graph.checkpointer) {
|
|
124
|
+
return getLastHumanMessages(events);
|
|
125
|
+
}
|
|
126
|
+
return this.getConversationWithAgent(events);
|
|
127
|
+
}
|
|
128
|
+
getConversationWithAgent(events) {
|
|
129
|
+
var _a2, _b2, _c;
|
|
130
|
+
const messages = [];
|
|
131
|
+
for (const event of events) {
|
|
132
|
+
const text = (_c = (_b2 = (_a2 = event.content) == null ? void 0 : _a2.parts) == null ? void 0 : _b2[0]) == null ? void 0 : _c.text;
|
|
133
|
+
if (text === void 0) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (event.author === "user") {
|
|
137
|
+
messages.push({ type: "human", content: text });
|
|
138
|
+
} else if (event.author === this.name) {
|
|
139
|
+
messages.push({ type: "ai", content: text });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return messages;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
__name(_LangGraphAgent, "LangGraphAgent");
|
|
146
|
+
let LangGraphAgent = _LangGraphAgent;
|
|
147
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
148
|
+
0 && (module.exports = {
|
|
149
|
+
LangGraphAgent,
|
|
150
|
+
getLastHumanMessages,
|
|
151
|
+
isLangGraphAgent
|
|
152
|
+
});
|