@google/adk 2.2.0 → 2.3.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/a2a/event_converter_utils.js +5 -1
- package/dist/cjs/a2a/metadata_converter_utils.js +2 -1
- package/dist/cjs/agents/functions.js +199 -25
- package/dist/cjs/agents/instructions.js +4 -1
- 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 +175 -101
- package/dist/cjs/agents/processors/code_execution_request_processor.js +10 -6
- package/dist/cjs/agents/remote_agent.js +187 -0
- 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/common.js +90 -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/events/abort_events.js +135 -0
- package/dist/cjs/events/event.js +4 -2
- package/dist/cjs/events/internal_metadata.js +131 -0
- 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 +97 -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/debug_logging_plugin.js +653 -0
- package/dist/cjs/plugins/plugin_manager.js +1 -1
- package/dist/cjs/plugins/tool_call_integrity_plugin.js +364 -0
- package/dist/cjs/runner/in_memory_runner.js +6 -11
- package/dist/cjs/runner/runner.js +121 -35
- package/dist/cjs/sessions/db/operations.js +1 -1
- package/dist/cjs/sessions/in_memory_session_service.js +3 -1
- package/dist/cjs/sessions/state.js +8 -4
- package/dist/cjs/sessions/vertex_ai_session_service.js +34 -15
- package/dist/cjs/telemetry/tracing.js +97 -66
- package/dist/cjs/tools/agent_tool.js +44 -0
- package/dist/cjs/tools/apihub_tool/apihub_toolset.js +142 -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 +185 -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 +603 -0
- package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +219 -0
- package/dist/cjs/tools/crewai_tool.js +132 -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 +97 -0
- package/dist/cjs/tools/google_api_tool/google_api_tool_set.js +226 -0
- package/dist/cjs/tools/google_api_tool/google_api_tool_sets.js +58 -0
- package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +440 -0
- package/dist/cjs/tools/google_api_tool/index.js +64 -0
- package/dist/cjs/tools/langchain_tool.js +172 -0
- package/dist/cjs/tools/mcp/index.js +12 -0
- package/dist/cjs/tools/mcp/mcp_session_manager.js +25 -0
- 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 +2 -1
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +14 -2
- package/dist/cjs/tools/retrieval/base_retrieval_tool.js +18 -3
- package/dist/cjs/tools/toolbox_tool.js +108 -0
- package/dist/cjs/utils/env_aware_utils.js +6 -8
- package/dist/cjs/utils/error_utils.js +11 -11
- 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 +4 -1
- 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 +7 -1
- package/dist/cjs/utils/object_notation_utils.js +6 -3
- package/dist/cjs/utils/streaming_utils.js +12 -12
- 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/a2a/event_converter_utils.js +5 -1
- package/dist/esm/a2a/metadata_converter_utils.js +2 -1
- package/dist/esm/agents/functions.js +198 -25
- package/dist/esm/agents/instructions.js +4 -1
- 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 +185 -104
- package/dist/esm/agents/processors/code_execution_request_processor.js +13 -8
- package/dist/esm/agents/remote_agent.js +164 -0
- 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/common.js +87 -3
- package/dist/esm/context/summarizers/llm_summarizer.js +12 -10
- package/dist/esm/context/token_based_context_compactor.js +2 -1
- package/dist/esm/events/abort_events.js +110 -0
- package/dist/esm/events/event.js +4 -2
- package/dist/esm/events/internal_metadata.js +97 -0
- 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 +99 -1
- 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/debug_logging_plugin.js +615 -0
- package/dist/esm/plugins/plugin_manager.js +1 -1
- package/dist/esm/plugins/tool_call_integrity_plugin.js +339 -0
- package/dist/esm/runner/in_memory_runner.js +6 -11
- package/dist/esm/runner/runner.js +124 -35
- package/dist/esm/sessions/db/operations.js +1 -1
- package/dist/esm/sessions/in_memory_session_service.js +3 -1
- package/dist/esm/sessions/state.js +8 -4
- package/dist/esm/sessions/vertex_ai_session_service.js +34 -15
- package/dist/esm/telemetry/tracing.js +97 -66
- package/dist/esm/tools/agent_tool.js +44 -0
- package/dist/esm/tools/apihub_tool/apihub_toolset.js +106 -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 +163 -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 +561 -0
- package/dist/esm/tools/application_integration_tool/clients/integration_client.js +215 -0
- package/dist/esm/tools/crewai_tool.js +107 -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 +70 -0
- package/dist/esm/tools/google_api_tool/google_api_tool_set.js +188 -0
- package/dist/esm/tools/google_api_tool/google_api_tool_sets.js +24 -0
- package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +393 -0
- package/dist/esm/tools/google_api_tool/index.js +33 -0
- package/dist/esm/tools/langchain_tool.js +148 -0
- package/dist/esm/tools/mcp/index.js +6 -0
- package/dist/esm/tools/mcp/mcp_session_manager.js +25 -0
- 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 +2 -1
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -2
- package/dist/esm/tools/retrieval/base_retrieval_tool.js +16 -2
- package/dist/esm/tools/toolbox_tool.js +80 -0
- package/dist/esm/utils/env_aware_utils.js +6 -8
- package/dist/esm/utils/error_utils.js +9 -10
- 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 +4 -1
- 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 +7 -1
- package/dist/esm/utils/object_notation_utils.js +4 -2
- package/dist/esm/utils/streaming_utils.js +11 -11
- 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/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/remote_agent.d.ts +68 -0
- 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/common.d.ts +30 -4
- package/dist/types/events/abort_events.d.ts +43 -0
- package/dist/types/events/event.d.ts +4 -0
- package/dist/types/events/internal_metadata.d.ts +78 -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 +16 -1
- 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/debug_logging_plugin.d.ts +157 -0
- package/dist/types/plugins/tool_call_integrity_plugin.d.ts +116 -0
- package/dist/types/runner/in_memory_runner.d.ts +2 -1
- package/dist/types/runner/runner.d.ts +34 -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/skill.d.ts +1 -1
- package/dist/types/telemetry/tracing.d.ts +4 -2
- package/dist/types/tools/apihub_tool/apihub_toolset.d.ts +122 -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 +86 -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 +215 -0
- package/dist/types/tools/application_integration_tool/clients/integration_client.d.ts +72 -0
- package/dist/types/tools/crewai_tool.d.ts +85 -0
- 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 +30 -0
- package/dist/types/tools/google_api_tool/google_api_tool_set.d.ts +78 -0
- package/dist/types/tools/google_api_tool/google_api_tool_sets.d.ts +33 -0
- package/dist/types/tools/google_api_tool/googleapi_to_openapi_converter.d.ts +164 -0
- package/dist/types/tools/google_api_tool/index.d.ts +11 -0
- package/dist/types/tools/langchain_tool.d.ts +103 -0
- 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/tool_auth_handler.d.ts +2 -1
- package/dist/types/tools/retrieval/base_retrieval_tool.d.ts +15 -0
- package/dist/types/tools/toolbox_tool.d.ts +73 -0
- 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 +1 -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/streaming_utils.d.ts +11 -4
- package/dist/types/version.d.ts +1 -1
- package/dist/web/index_web.js +105 -106
- package/dist/web/index_web.js.map +4 -4
- package/package.json +8 -3
|
@@ -8,6 +8,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
8
8
|
* SPDX-License-Identifier: Apache-2.0
|
|
9
9
|
*/
|
|
10
10
|
var _a, _b;
|
|
11
|
+
import { Modality } from "@google/genai";
|
|
11
12
|
import { context, trace } from "@opentelemetry/api";
|
|
12
13
|
import { FinishTaskTool } from "../tools/finish_task_tool.js";
|
|
13
14
|
import { FunctionTool } from "../tools/function_tool.js";
|
|
@@ -20,6 +21,8 @@ import {
|
|
|
20
21
|
createNewEventId,
|
|
21
22
|
getFunctionCalls,
|
|
22
23
|
getFunctionResponses,
|
|
24
|
+
hasTrailingCodeExecutionResult,
|
|
25
|
+
isEvent,
|
|
23
26
|
isFinalResponse,
|
|
24
27
|
populateClientFunctionCallId
|
|
25
28
|
} from "../events/event.js";
|
|
@@ -34,7 +37,8 @@ import { Context } from "./context.js";
|
|
|
34
37
|
import {
|
|
35
38
|
runAsyncGeneratorWithOtelContext,
|
|
36
39
|
traceCallLlm,
|
|
37
|
-
tracer
|
|
40
|
+
tracer,
|
|
41
|
+
traceSendData
|
|
38
42
|
} from "../telemetry/tracing.js";
|
|
39
43
|
import { parseWithSchema } from "../utils/schema.js";
|
|
40
44
|
import { isZodObject, zodObjectToSchema } from "../utils/simple_zod_to_json.js";
|
|
@@ -43,13 +47,18 @@ import {
|
|
|
43
47
|
generateAuthEvent,
|
|
44
48
|
generateRequestConfirmationEvent,
|
|
45
49
|
getLongRunningFunctionCalls,
|
|
46
|
-
handleFunctionCallsAsync
|
|
50
|
+
handleFunctionCallsAsync,
|
|
51
|
+
handleFunctionCallsLive
|
|
47
52
|
} from "./functions.js";
|
|
48
53
|
import { AUTH_PREPROCESSOR } from "../auth/auth_preprocessor.js";
|
|
49
54
|
import { requireAgent } from "./invocation_context.js";
|
|
55
|
+
import { LiveRequestQueue } from "./live_request_queue.js";
|
|
50
56
|
import { AGENT_TRANSFER_LLM_REQUEST_PROCESSOR } from "./processors/agent_transfer_llm_request_processor.js";
|
|
51
57
|
import { BASIC_LLM_REQUEST_PROCESSOR } from "./processors/basic_llm_request_processor.js";
|
|
52
|
-
import {
|
|
58
|
+
import {
|
|
59
|
+
CODE_EXECUTION_REQUEST_PROCESSOR,
|
|
60
|
+
responseProcessor as CODE_EXECUTION_RESPONSE_PROCESSOR
|
|
61
|
+
} from "./processors/code_execution_request_processor.js";
|
|
53
62
|
import { CONTENT_REQUEST_PROCESSOR } from "./processors/content_request_processor.js";
|
|
54
63
|
import { ContextCompactorRequestProcessor } from "./processors/context_compactor_request_processor.js";
|
|
55
64
|
import { IDENTITY_LLM_REQUEST_PROCESSOR } from "./processors/identity_llm_request_processor.js";
|
|
@@ -112,6 +121,9 @@ function applyLiveRunConfig(runConfig, llmRequest) {
|
|
|
112
121
|
liveConfig[k] = runConfig[k];
|
|
113
122
|
}
|
|
114
123
|
}
|
|
124
|
+
if (runConfig.supportCfc) {
|
|
125
|
+
liveConfig.responseModalities = [Modality.TEXT];
|
|
126
|
+
}
|
|
115
127
|
}
|
|
116
128
|
__name(applyLiveRunConfig, "applyLiveRunConfig");
|
|
117
129
|
const ADK_AGENT_NAME_LABEL_KEY = "adk_agent_name";
|
|
@@ -194,7 +206,9 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
194
206
|
}
|
|
195
207
|
}
|
|
196
208
|
this.responseProcessors = (_j = config.responseProcessors) != null ? _j : [
|
|
197
|
-
NL_PLANNING_RESPONSE_PROCESSOR
|
|
209
|
+
NL_PLANNING_RESPONSE_PROCESSOR,
|
|
210
|
+
// Runs the code blocks that a client-side code executor receives.
|
|
211
|
+
CODE_EXECUTION_RESPONSE_PROCESSOR
|
|
198
212
|
];
|
|
199
213
|
const agentTransferDisabled = this.disallowTransferToParent && this.disallowTransferToPeers && !((_k = this.subAgents) == null ? void 0 : _k.length);
|
|
200
214
|
if (!agentTransferDisabled) {
|
|
@@ -457,14 +471,18 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
457
471
|
while (true) {
|
|
458
472
|
let lastEvent = void 0;
|
|
459
473
|
let stepHadToolCalls = false;
|
|
474
|
+
let stepTransferred = false;
|
|
460
475
|
for await (const event of this.runOneStepAsync(context2)) {
|
|
461
476
|
if ((_a2 = context2.abortSignal) == null ? void 0 : _a2.aborted) {
|
|
462
477
|
return;
|
|
463
478
|
}
|
|
464
479
|
lastEvent = event;
|
|
465
|
-
if (getFunctionCalls(event).length > 0 || getFunctionResponses(event).length > 0) {
|
|
480
|
+
if (getFunctionCalls(event).length > 0 || getFunctionResponses(event).length > 0 || !event.partial && hasTrailingCodeExecutionResult(event)) {
|
|
466
481
|
stepHadToolCalls = true;
|
|
467
482
|
}
|
|
483
|
+
if (event.author === this.name && event.actions.transferToAgent) {
|
|
484
|
+
stepTransferred = true;
|
|
485
|
+
}
|
|
468
486
|
this.maybeSaveOutputToState(event);
|
|
469
487
|
yield event;
|
|
470
488
|
}
|
|
@@ -472,7 +490,7 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
472
490
|
break;
|
|
473
491
|
}
|
|
474
492
|
const isEmptyMetadataEvent = lastEvent.author === this.name && !lastEvent.partial && (!((_b2 = lastEvent.content) == null ? void 0 : _b2.parts) || lastEvent.content.parts.length === 0) && isDefaultEventActions(lastEvent.actions);
|
|
475
|
-
if (isFinalResponse(lastEvent) && !(isEmptyMetadataEvent && stepHadToolCalls)) {
|
|
493
|
+
if (isFinalResponse(lastEvent) && !(isEmptyMetadataEvent && stepHadToolCalls && !stepTransferred)) {
|
|
476
494
|
break;
|
|
477
495
|
}
|
|
478
496
|
if (lastEvent.partial) {
|
|
@@ -512,7 +530,7 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
512
530
|
* already holds the conversation state associated with the handle.
|
|
513
531
|
*/
|
|
514
532
|
async *runLiveFlow(invocationContext) {
|
|
515
|
-
var _a2, _b2, _c, _d;
|
|
533
|
+
var _a2, _b2, _c, _d, _e;
|
|
516
534
|
if (!invocationContext.liveRequestQueue) {
|
|
517
535
|
throw new Error("liveRequestQueue is required for LlmAgent.runLiveFlow.");
|
|
518
536
|
}
|
|
@@ -567,16 +585,29 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
567
585
|
throw err;
|
|
568
586
|
}
|
|
569
587
|
if (llmRequest.contents.length > 0 && !invocationContext.liveSessionResumptionHandle) {
|
|
570
|
-
await
|
|
588
|
+
await tracer.startActiveSpan("send_data", async (span) => {
|
|
589
|
+
try {
|
|
590
|
+
await connection.sendHistory(llmRequest.contents);
|
|
591
|
+
traceSendData({
|
|
592
|
+
invocationContext,
|
|
593
|
+
eventId: createNewEventId(),
|
|
594
|
+
data: llmRequest.contents
|
|
595
|
+
});
|
|
596
|
+
} finally {
|
|
597
|
+
span.end();
|
|
598
|
+
}
|
|
599
|
+
});
|
|
571
600
|
}
|
|
572
601
|
let sendError;
|
|
573
602
|
const sendAbort = new AbortController();
|
|
574
603
|
const combinedAbort = invocationContext.abortSignal ? AbortSignal.any([invocationContext.abortSignal, sendAbort.signal]) : sendAbort.signal;
|
|
604
|
+
(_d = invocationContext.activeStreamingTools) != null ? _d : invocationContext.activeStreamingTools = {};
|
|
575
605
|
const sendTask = this.runSendLoop(
|
|
576
606
|
connection,
|
|
577
607
|
invocationContext.liveRequestQueue,
|
|
578
608
|
combinedAbort,
|
|
579
|
-
invocationContext.abortSignal
|
|
609
|
+
invocationContext.abortSignal,
|
|
610
|
+
invocationContext.activeStreamingTools
|
|
580
611
|
);
|
|
581
612
|
sendTask.catch((error) => {
|
|
582
613
|
logger.error("Error in live send loop:", error);
|
|
@@ -608,7 +639,7 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
608
639
|
}
|
|
609
640
|
}
|
|
610
641
|
await this.teardownLiveConnection(sendAbort, connection, sendTask);
|
|
611
|
-
if ((
|
|
642
|
+
if ((_e = invocationContext.abortSignal) == null ? void 0 : _e.aborted) {
|
|
612
643
|
return;
|
|
613
644
|
}
|
|
614
645
|
if (sendError) {
|
|
@@ -654,7 +685,7 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
654
685
|
}
|
|
655
686
|
}
|
|
656
687
|
}
|
|
657
|
-
async runSendLoop(connection, liveRequestQueue, sendAbortSignal, invocationAbortSignal) {
|
|
688
|
+
async runSendLoop(connection, liveRequestQueue, sendAbortSignal, invocationAbortSignal, activeStreamingTools) {
|
|
658
689
|
while (true) {
|
|
659
690
|
if ((sendAbortSignal == null ? void 0 : sendAbortSignal.aborted) || (invocationAbortSignal == null ? void 0 : invocationAbortSignal.aborted)) {
|
|
660
691
|
return;
|
|
@@ -668,6 +699,13 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
668
699
|
}
|
|
669
700
|
throw error;
|
|
670
701
|
}
|
|
702
|
+
if (activeStreamingTools) {
|
|
703
|
+
for (const activeStreamingTool of Object.values(activeStreamingTools)) {
|
|
704
|
+
if (activeStreamingTool.stream) {
|
|
705
|
+
activeStreamingTool.stream.send(liveRequest);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
}
|
|
671
709
|
try {
|
|
672
710
|
await this.dispatchLiveRequest(connection, liveRequest);
|
|
673
711
|
} catch (error) {
|
|
@@ -722,67 +760,74 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
722
760
|
}
|
|
723
761
|
async *runReceiveLoop(invocationContext, connection, llmRequest, sendAbort) {
|
|
724
762
|
var _a2, _b2, _c, _d;
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
if ((_b2 = llmResponse.liveSessionResumptionUpdate) == null ? void 0 : _b2.newHandle) {
|
|
733
|
-
invocationContext.liveSessionResumptionHandle = llmResponse.liveSessionResumptionUpdate.newHandle;
|
|
734
|
-
}
|
|
735
|
-
if (llmResponse.goAway) {
|
|
736
|
-
logger.info("Received goAway from live server; triggering reconnect.");
|
|
737
|
-
throw new LiveReconnectSignal("goAway");
|
|
738
|
-
}
|
|
739
|
-
const author = llmResponse.inputTranscription || ((_c = llmResponse.content) == null ? void 0 : _c.role) === "user" ? "user" : this.name;
|
|
740
|
-
const modelResponseEvent = createEvent({
|
|
741
|
-
invocationId: invocationContext.invocationId,
|
|
742
|
-
author,
|
|
743
|
-
branch: invocationContext.branch
|
|
744
|
-
});
|
|
745
|
-
for await (const event of this.postprocessLive(
|
|
746
|
-
invocationContext,
|
|
747
|
-
llmRequest,
|
|
748
|
-
llmResponse,
|
|
749
|
-
modelResponseEvent
|
|
750
|
-
)) {
|
|
751
|
-
yield event;
|
|
752
|
-
if (event.content && getFunctionResponses(event).length > 0) {
|
|
753
|
-
await connection.sendContent(event.content);
|
|
763
|
+
let receivedAny = true;
|
|
764
|
+
while (receivedAny) {
|
|
765
|
+
receivedAny = false;
|
|
766
|
+
for await (const llmResponse of connection.receive()) {
|
|
767
|
+
receivedAny = true;
|
|
768
|
+
if ((_a2 = invocationContext.abortSignal) == null ? void 0 : _a2.aborted) {
|
|
769
|
+
return;
|
|
754
770
|
}
|
|
755
|
-
|
|
756
|
-
(r) => r.name === "task_completed"
|
|
757
|
-
);
|
|
758
|
-
if (taskCompleted) {
|
|
759
|
-
await sleep(TRANSFER_AGENT_DELAY_MS);
|
|
771
|
+
if (sendAbort.signal.aborted) {
|
|
760
772
|
return;
|
|
761
773
|
}
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
774
|
+
if ((_b2 = llmResponse.liveSessionResumptionUpdate) == null ? void 0 : _b2.newHandle) {
|
|
775
|
+
invocationContext.liveSessionResumptionHandle = llmResponse.liveSessionResumptionUpdate.newHandle;
|
|
776
|
+
}
|
|
777
|
+
if (llmResponse.goAway) {
|
|
778
|
+
logger.info(
|
|
779
|
+
"Received goAway from live server; triggering reconnect."
|
|
780
|
+
);
|
|
781
|
+
throw new LiveReconnectSignal("goAway");
|
|
782
|
+
}
|
|
783
|
+
const author = llmResponse.inputTranscription || ((_c = llmResponse.content) == null ? void 0 : _c.role) === "user" ? "user" : this.name;
|
|
784
|
+
const modelResponseEvent = createEvent({
|
|
785
|
+
invocationId: invocationContext.invocationId,
|
|
786
|
+
author,
|
|
787
|
+
branch: invocationContext.branch
|
|
788
|
+
});
|
|
789
|
+
for await (const event of this.postprocessLive(
|
|
790
|
+
invocationContext,
|
|
791
|
+
llmRequest,
|
|
792
|
+
llmResponse,
|
|
793
|
+
modelResponseEvent
|
|
794
|
+
)) {
|
|
795
|
+
yield event;
|
|
796
|
+
if (event.content && getFunctionResponses(event).length > 0) {
|
|
797
|
+
await connection.sendContent(event.content);
|
|
798
|
+
}
|
|
799
|
+
const taskCompleted = getFunctionResponses(event).some(
|
|
800
|
+
(r) => r.name === "task_completed"
|
|
801
|
+
);
|
|
802
|
+
if (taskCompleted) {
|
|
803
|
+
await sleep(TRANSFER_AGENT_DELAY_MS);
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
const transferTo = (_d = event.actions) == null ? void 0 : _d.transferToAgent;
|
|
807
|
+
if (transferTo) {
|
|
808
|
+
await sleep(TRANSFER_AGENT_DELAY_MS);
|
|
809
|
+
sendAbort.abort();
|
|
810
|
+
await connection.close();
|
|
811
|
+
const agent = requireAgent(invocationContext);
|
|
812
|
+
const subAgent = agent.rootAgent.findAgent(transferTo);
|
|
813
|
+
if (subAgent) {
|
|
814
|
+
const previousAgent = invocationContext.agent;
|
|
815
|
+
invocationContext.agent = subAgent;
|
|
816
|
+
const previousHandle = invocationContext.liveSessionResumptionHandle;
|
|
817
|
+
invocationContext.liveSessionResumptionHandle = void 0;
|
|
818
|
+
try {
|
|
819
|
+
for await (const subEvent of subAgent.runLive(
|
|
820
|
+
invocationContext
|
|
821
|
+
)) {
|
|
822
|
+
yield subEvent;
|
|
823
|
+
}
|
|
824
|
+
} finally {
|
|
825
|
+
invocationContext.agent = previousAgent;
|
|
826
|
+
invocationContext.liveSessionResumptionHandle = previousHandle;
|
|
779
827
|
}
|
|
780
|
-
} finally {
|
|
781
|
-
invocationContext.agent = previousAgent;
|
|
782
|
-
invocationContext.liveSessionResumptionHandle = previousHandle;
|
|
783
828
|
}
|
|
829
|
+
return;
|
|
784
830
|
}
|
|
785
|
-
return;
|
|
786
831
|
}
|
|
787
832
|
}
|
|
788
833
|
}
|
|
@@ -837,7 +882,7 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
837
882
|
if (!functionCalls.length) {
|
|
838
883
|
return;
|
|
839
884
|
}
|
|
840
|
-
const functionResponseEvent = await
|
|
885
|
+
const functionResponseEvent = await handleFunctionCallsLive({
|
|
841
886
|
invocationContext,
|
|
842
887
|
functionCallEvent: mergedEvent,
|
|
843
888
|
toolsDict: llmRequest.toolsDict,
|
|
@@ -919,44 +964,55 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
919
964
|
}
|
|
920
965
|
const span = tracer.startSpan("call_llm");
|
|
921
966
|
const ctx = trace.setSpan(context.active(), span);
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
llmRequest,
|
|
931
|
-
modelResponseEvent
|
|
932
|
-
)) {
|
|
933
|
-
if ((_a3 = invocationContext.abortSignal) == null ? void 0 : _a3.aborted) {
|
|
934
|
-
return;
|
|
935
|
-
}
|
|
936
|
-
for await (const event of this.postprocess(
|
|
967
|
+
try {
|
|
968
|
+
yield* runAsyncGeneratorWithOtelContext(
|
|
969
|
+
ctx,
|
|
970
|
+
this,
|
|
971
|
+
async function* () {
|
|
972
|
+
const responsesGenerator = /* @__PURE__ */ __name(async function* () {
|
|
973
|
+
var _a3, _b3, _c2;
|
|
974
|
+
for await (const llmResponse of this.callLlmAsync(
|
|
937
975
|
invocationContext,
|
|
938
976
|
llmRequest,
|
|
939
|
-
llmResponse,
|
|
940
977
|
modelResponseEvent
|
|
941
978
|
)) {
|
|
942
|
-
if ((
|
|
979
|
+
if ((_a3 = invocationContext.abortSignal) == null ? void 0 : _a3.aborted) {
|
|
943
980
|
return;
|
|
944
981
|
}
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
982
|
+
if (((_b3 = invocationContext.runConfig) == null ? void 0 : _b3.supportCfc) && isEvent(llmResponse)) {
|
|
983
|
+
modelResponseEvent.id = createNewEventId();
|
|
984
|
+
modelResponseEvent.timestamp = (/* @__PURE__ */ new Date()).getTime();
|
|
985
|
+
yield llmResponse;
|
|
986
|
+
continue;
|
|
987
|
+
}
|
|
988
|
+
for await (const event of this.postprocess(
|
|
989
|
+
invocationContext,
|
|
990
|
+
llmRequest,
|
|
991
|
+
llmResponse,
|
|
992
|
+
modelResponseEvent
|
|
993
|
+
)) {
|
|
994
|
+
if ((_c2 = invocationContext.abortSignal) == null ? void 0 : _c2.aborted) {
|
|
995
|
+
return;
|
|
996
|
+
}
|
|
997
|
+
if (!event.partial) {
|
|
998
|
+
modelResponseEvent.id = createNewEventId();
|
|
999
|
+
modelResponseEvent.timestamp = (/* @__PURE__ */ new Date()).getTime();
|
|
1000
|
+
}
|
|
1001
|
+
yield event;
|
|
1002
|
+
}
|
|
948
1003
|
}
|
|
949
|
-
}
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
1004
|
+
}, "responsesGenerator");
|
|
1005
|
+
yield* this.runAndHandleError(
|
|
1006
|
+
responsesGenerator.call(this),
|
|
1007
|
+
invocationContext,
|
|
1008
|
+
llmRequest,
|
|
1009
|
+
modelResponseEvent
|
|
1010
|
+
);
|
|
1011
|
+
}
|
|
1012
|
+
);
|
|
1013
|
+
} finally {
|
|
1014
|
+
span.end();
|
|
1015
|
+
}
|
|
960
1016
|
}
|
|
961
1017
|
async *postprocess(invocationContext, llmRequest, llmResponse, modelResponseEvent) {
|
|
962
1018
|
var _a2, _b2, _c, _d, _e, _f;
|
|
@@ -1082,7 +1138,7 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
1082
1138
|
return agentToRun;
|
|
1083
1139
|
}
|
|
1084
1140
|
async *callLlmAsync(invocationContext, llmRequest, modelResponseEvent) {
|
|
1085
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h;
|
|
1141
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1086
1142
|
const beforeModelResponse = await this.handleBeforeModelCallback(
|
|
1087
1143
|
invocationContext,
|
|
1088
1144
|
llmRequest,
|
|
@@ -1101,14 +1157,39 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
1101
1157
|
llmRequest.config.labels[ADK_AGENT_NAME_LABEL_KEY] = this.name;
|
|
1102
1158
|
}
|
|
1103
1159
|
const llm = this.canonicalModel;
|
|
1160
|
+
invocationContext.incrementLlmCallCount();
|
|
1104
1161
|
if ((_e = invocationContext.runConfig) == null ? void 0 : _e.supportCfc) {
|
|
1105
|
-
|
|
1162
|
+
(_f = invocationContext.liveRequestQueue) != null ? _f : invocationContext.liveRequestQueue = new LiveRequestQueue();
|
|
1163
|
+
const liveRequestQueue = invocationContext.liveRequestQueue;
|
|
1164
|
+
try {
|
|
1165
|
+
for await (const llmResponse of this.runLiveFlow(invocationContext)) {
|
|
1166
|
+
if ((_g = invocationContext.abortSignal) == null ? void 0 : _g.aborted) {
|
|
1167
|
+
return;
|
|
1168
|
+
}
|
|
1169
|
+
const alteredLlmResponse = await this.handleAfterModelCallback(
|
|
1170
|
+
invocationContext,
|
|
1171
|
+
llmResponse,
|
|
1172
|
+
modelResponseEvent
|
|
1173
|
+
);
|
|
1174
|
+
if ((_h = invocationContext.abortSignal) == null ? void 0 : _h.aborted) {
|
|
1175
|
+
return;
|
|
1176
|
+
}
|
|
1177
|
+
const effectiveResponse = alteredLlmResponse ? createEvent({ ...llmResponse, ...alteredLlmResponse }) : llmResponse;
|
|
1178
|
+
if (invocationContext.runConfig.streamingMode === StreamingMode.SSE || !effectiveResponse.partial) {
|
|
1179
|
+
yield effectiveResponse;
|
|
1180
|
+
}
|
|
1181
|
+
if (effectiveResponse.turnComplete) {
|
|
1182
|
+
liveRequestQueue.close();
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
} finally {
|
|
1186
|
+
liveRequestQueue.close();
|
|
1187
|
+
}
|
|
1106
1188
|
} else {
|
|
1107
|
-
invocationContext.incrementLlmCallCount();
|
|
1108
1189
|
const responsesGenerator = llm.generateContentAsync(
|
|
1109
1190
|
llmRequest,
|
|
1110
1191
|
/* stream= */
|
|
1111
|
-
((
|
|
1192
|
+
((_i = invocationContext.runConfig) == null ? void 0 : _i.streamingMode) === StreamingMode.SSE,
|
|
1112
1193
|
invocationContext.abortSignal
|
|
1113
1194
|
);
|
|
1114
1195
|
for await (const llmResponse of responsesGenerator) {
|
|
@@ -1118,7 +1199,7 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
1118
1199
|
llmRequest,
|
|
1119
1200
|
llmResponse
|
|
1120
1201
|
});
|
|
1121
|
-
if ((
|
|
1202
|
+
if ((_j = invocationContext.abortSignal) == null ? void 0 : _j.aborted) {
|
|
1122
1203
|
return;
|
|
1123
1204
|
}
|
|
1124
1205
|
const alteredLlmResponse = await this.handleAfterModelCallback(
|
|
@@ -1126,7 +1207,7 @@ const _LlmAgent = class _LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNAT
|
|
|
1126
1207
|
llmResponse,
|
|
1127
1208
|
modelResponseEvent
|
|
1128
1209
|
);
|
|
1129
|
-
if ((
|
|
1210
|
+
if ((_k = invocationContext.abortSignal) == null ? void 0 : _k.aborted) {
|
|
1130
1211
|
return;
|
|
1131
1212
|
}
|
|
1132
1213
|
yield alteredLlmResponse != null ? alteredLlmResponse : llmResponse;
|
|
@@ -15,13 +15,14 @@ import {
|
|
|
15
15
|
buildExecutableCodePart,
|
|
16
16
|
CodeExecutionLanguage,
|
|
17
17
|
convertCodeExecutionParts,
|
|
18
|
-
|
|
18
|
+
extractCodeBlockAndTruncateContent,
|
|
19
|
+
FileContentEncoding
|
|
19
20
|
} from "../../code_executors/code_execution_utils.js";
|
|
20
21
|
import { CodeExecutorContext } from "../../code_executors/code_executor_context.js";
|
|
21
22
|
import { createEvent } from "../../events/event.js";
|
|
22
23
|
import { createEventActions } from "../../events/event_actions.js";
|
|
23
24
|
import { State } from "../../sessions/state.js";
|
|
24
|
-
import { base64Decode } from "../../utils/env_aware_utils.js";
|
|
25
|
+
import { base64Decode, base64Encode } from "../../utils/env_aware_utils.js";
|
|
25
26
|
import { requireAgent } from "../invocation_context.js";
|
|
26
27
|
import { isLlmAgent } from "../llm_agent.js";
|
|
27
28
|
import {
|
|
@@ -223,7 +224,7 @@ async function* runPostProcessor(invocationContext, llmResponse) {
|
|
|
223
224
|
return;
|
|
224
225
|
}
|
|
225
226
|
const responseContent = llmResponse.content;
|
|
226
|
-
const codeStr =
|
|
227
|
+
const { code: codeStr, language } = extractCodeBlockAndTruncateContent(
|
|
227
228
|
responseContent,
|
|
228
229
|
codeExecutor.codeBlockDelimiters
|
|
229
230
|
);
|
|
@@ -244,7 +245,7 @@ async function* runPostProcessor(invocationContext, llmResponse) {
|
|
|
244
245
|
invocationContext,
|
|
245
246
|
codeExecutionInput: {
|
|
246
247
|
code: codeStr,
|
|
247
|
-
language
|
|
248
|
+
language,
|
|
248
249
|
inputFiles: codeExecutorContext.getInputFiles(),
|
|
249
250
|
executionId
|
|
250
251
|
}
|
|
@@ -279,14 +280,15 @@ function extractAndReplaceInlineFiles(codeExecutorContext, llmRequest) {
|
|
|
279
280
|
continue;
|
|
280
281
|
}
|
|
281
282
|
const fileName = `data_${i + 1}_${j + 1}${DATA_FILE_UTIL_MAP[mimeType].extension}`;
|
|
282
|
-
part.text = `
|
|
283
|
-
Available file: \`${fileName}\`
|
|
284
|
-
`;
|
|
285
283
|
const file = {
|
|
286
284
|
name: fileName,
|
|
287
285
|
content: base64Decode(part.inlineData.data),
|
|
288
286
|
mimeType
|
|
289
287
|
};
|
|
288
|
+
part.text = `
|
|
289
|
+
Available file: \`${fileName}\`
|
|
290
|
+
`;
|
|
291
|
+
delete part.inlineData;
|
|
290
292
|
if (!savedFileNames.has(fileName)) {
|
|
291
293
|
codeExecutorContext.addInputFiles([file]);
|
|
292
294
|
allInputFiles.push(file);
|
|
@@ -330,7 +332,10 @@ async function postProcessCodeExecutionResult(invocationContext, codeExecutorCon
|
|
|
330
332
|
const version = await invocationContext.artifactService.saveArtifact({
|
|
331
333
|
filename: outputFile.name,
|
|
332
334
|
artifact: {
|
|
333
|
-
inlineData: {
|
|
335
|
+
inlineData: {
|
|
336
|
+
data: outputFile.contentEncoding === FileContentEncoding.UTF8 ? base64Encode(outputFile.content) : outputFile.content,
|
|
337
|
+
mimeType: outputFile.mimeType
|
|
338
|
+
}
|
|
334
339
|
}
|
|
335
340
|
});
|
|
336
341
|
eventActions.artifactDelta[outputFile.name] = version;
|