@google/adk 0.2.5 → 0.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/part_converter_utils.js +210 -0
- package/dist/cjs/agents/active_streaming_tool.js +1 -1
- package/dist/cjs/agents/base_agent.js +46 -24
- package/dist/cjs/agents/base_llm_processor.js +1 -1
- package/dist/cjs/agents/callback_context.js +5 -2
- package/dist/cjs/agents/content_processor_utils.js +16 -8
- package/dist/cjs/agents/functions.js +81 -30
- package/dist/cjs/agents/instructions.js +1 -1
- package/dist/cjs/agents/invocation_context.js +1 -1
- package/dist/cjs/agents/live_request_queue.js +1 -1
- package/dist/cjs/agents/llm_agent.js +106 -62
- package/dist/cjs/agents/loop_agent.js +3 -2
- package/dist/cjs/agents/parallel_agent.js +4 -5
- package/dist/cjs/agents/readonly_context.js +13 -1
- package/dist/cjs/agents/run_config.js +2 -1
- package/dist/cjs/agents/sequential_agent.js +1 -1
- package/dist/cjs/agents/transcription_entry.js +1 -1
- package/dist/cjs/artifacts/base_artifact_service.js +1 -1
- package/dist/cjs/artifacts/file_artifact_service.js +491 -0
- package/dist/cjs/artifacts/gcs_artifact_service.js +145 -58
- package/dist/cjs/artifacts/in_memory_artifact_service.js +72 -10
- package/dist/cjs/artifacts/registry.js +55 -0
- package/dist/cjs/auth/auth_credential.js +1 -1
- package/dist/cjs/auth/auth_handler.js +4 -2
- package/dist/cjs/auth/auth_schemes.js +1 -1
- package/dist/cjs/auth/auth_tool.js +1 -1
- package/dist/cjs/auth/credential_service/base_credential_service.js +1 -1
- package/dist/cjs/auth/credential_service/in_memory_credential_service.js +1 -1
- package/dist/cjs/auth/exchanger/base_credential_exchanger.js +1 -1
- package/dist/cjs/auth/exchanger/credential_exchanger_registry.js +1 -1
- package/dist/cjs/code_executors/base_code_executor.js +4 -2
- package/dist/cjs/code_executors/built_in_code_executor.js +8 -4
- package/dist/cjs/code_executors/code_execution_utils.js +1 -1
- package/dist/cjs/code_executors/code_executor_context.js +6 -6
- package/dist/cjs/common.js +18 -1
- package/dist/cjs/events/event.js +34 -7
- package/dist/cjs/events/event_actions.js +2 -2
- package/dist/cjs/events/structured_events.js +105 -0
- package/dist/cjs/examples/base_example_provider.js +1 -1
- package/dist/cjs/examples/example.js +1 -1
- package/dist/cjs/examples/example_util.js +1 -1
- package/dist/cjs/index.js +54 -83
- package/dist/cjs/index_web.js +1 -1
- package/dist/cjs/memory/base_memory_service.js +1 -1
- package/dist/cjs/memory/in_memory_memory_service.js +4 -2
- package/dist/cjs/memory/memory_entry.js +1 -1
- package/dist/cjs/models/apigee_llm.js +182 -0
- package/dist/cjs/models/base_llm.js +9 -5
- package/dist/cjs/models/base_llm_connection.js +1 -1
- package/dist/cjs/models/gemini_llm_connection.js +2 -1
- package/dist/cjs/models/google_llm.js +73 -54
- package/dist/cjs/models/llm_request.js +1 -1
- package/dist/cjs/models/llm_response.js +1 -1
- package/dist/cjs/models/registry.js +3 -1
- package/dist/cjs/plugins/base_plugin.js +13 -1
- package/dist/cjs/plugins/logging_plugin.js +51 -14
- package/dist/cjs/plugins/plugin_manager.js +57 -25
- package/dist/cjs/plugins/security_plugin.js +2 -2
- package/dist/cjs/runner/in_memory_runner.js +1 -1
- package/dist/cjs/runner/runner.js +142 -96
- package/dist/cjs/sessions/base_session_service.js +53 -3
- package/dist/cjs/sessions/database_session_service.js +364 -0
- package/dist/cjs/sessions/db/operations.js +114 -0
- package/dist/cjs/sessions/db/schema.js +204 -0
- package/dist/cjs/sessions/in_memory_session_service.js +60 -34
- package/dist/cjs/sessions/registry.js +49 -0
- package/dist/cjs/sessions/session.js +1 -1
- package/dist/cjs/sessions/state.js +1 -1
- package/dist/cjs/telemetry/google_cloud.js +8 -10
- package/dist/cjs/telemetry/setup.js +16 -8
- package/dist/cjs/telemetry/tracing.js +38 -16
- package/dist/cjs/tools/agent_tool.js +9 -5
- package/dist/cjs/tools/base_tool.js +5 -3
- package/dist/cjs/tools/base_toolset.js +1 -1
- package/dist/cjs/tools/forwarding_artifact_service.js +18 -2
- package/dist/cjs/tools/function_tool.js +2 -3
- package/dist/cjs/tools/google_search_tool.js +2 -3
- package/dist/cjs/tools/long_running_tool.js +1 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +17 -11
- package/dist/cjs/tools/mcp/mcp_tool.js +2 -4
- package/dist/cjs/tools/mcp/mcp_toolset.js +2 -2
- package/dist/cjs/tools/tool_confirmation.js +1 -1
- package/dist/cjs/tools/tool_context.js +1 -1
- package/dist/cjs/utils/client_labels.js +1 -1
- package/dist/cjs/utils/env_aware_utils.js +11 -2
- package/dist/cjs/utils/gemini_schema_util.js +10 -5
- package/dist/cjs/utils/logger.js +48 -4
- package/dist/cjs/utils/model_name.js +1 -1
- package/dist/cjs/utils/object_notation_utils.js +78 -0
- package/dist/cjs/utils/simple_zod_to_json.js +101 -142
- package/dist/cjs/utils/variant_utils.js +3 -9
- package/dist/cjs/version.js +2 -2
- package/dist/esm/a2a/part_converter_utils.js +171 -0
- package/dist/esm/agents/base_agent.js +50 -24
- package/dist/esm/agents/callback_context.js +4 -1
- package/dist/esm/agents/content_processor_utils.js +25 -9
- package/dist/esm/agents/functions.js +84 -29
- package/dist/esm/agents/llm_agent.js +110 -62
- package/dist/esm/agents/loop_agent.js +2 -1
- package/dist/esm/agents/parallel_agent.js +3 -4
- package/dist/esm/agents/readonly_context.js +12 -0
- package/dist/esm/agents/run_config.js +1 -0
- package/dist/esm/artifacts/file_artifact_service.js +451 -0
- package/dist/esm/artifacts/gcs_artifact_service.js +144 -57
- package/dist/esm/artifacts/in_memory_artifact_service.js +69 -8
- package/dist/esm/artifacts/registry.js +28 -0
- package/dist/esm/auth/auth_handler.js +3 -1
- package/dist/esm/code_executors/base_code_executor.js +3 -1
- package/dist/esm/code_executors/built_in_code_executor.js +7 -3
- package/dist/esm/code_executors/code_executor_context.js +5 -5
- package/dist/esm/common.js +12 -2
- package/dist/esm/events/event.js +30 -5
- package/dist/esm/events/event_actions.js +1 -1
- package/dist/esm/events/structured_events.js +74 -0
- package/dist/esm/index.js +18 -88
- package/dist/esm/memory/in_memory_memory_service.js +3 -1
- package/dist/esm/models/apigee_llm.js +152 -0
- package/dist/esm/models/base_llm.js +8 -4
- package/dist/esm/models/gemini_llm_connection.js +1 -0
- package/dist/esm/models/google_llm.js +75 -53
- package/dist/esm/models/registry.js +2 -0
- package/dist/esm/plugins/base_plugin.js +12 -0
- package/dist/esm/plugins/logging_plugin.js +55 -14
- package/dist/esm/plugins/plugin_manager.js +56 -24
- package/dist/esm/plugins/security_plugin.js +1 -1
- package/dist/esm/runner/runner.js +145 -96
- package/dist/esm/sessions/base_session_service.js +49 -1
- package/dist/esm/sessions/database_session_service.js +350 -0
- package/dist/esm/sessions/db/operations.js +87 -0
- package/dist/esm/sessions/db/schema.js +172 -0
- package/dist/esm/sessions/in_memory_session_service.js +61 -33
- package/dist/esm/sessions/registry.js +25 -0
- package/dist/esm/telemetry/google_cloud.js +7 -9
- package/dist/esm/telemetry/setup.js +23 -9
- package/dist/esm/telemetry/tracing.js +37 -15
- package/dist/esm/tools/agent_tool.js +8 -4
- package/dist/esm/tools/base_tool.js +4 -2
- package/dist/esm/tools/forwarding_artifact_service.js +17 -1
- package/dist/esm/tools/function_tool.js +1 -2
- package/dist/esm/tools/google_search_tool.js +2 -5
- package/dist/esm/tools/long_running_tool.js +3 -1
- package/dist/esm/tools/mcp/mcp_session_manager.js +22 -12
- package/dist/esm/tools/mcp/mcp_tool.js +1 -3
- package/dist/esm/tools/mcp/mcp_toolset.js +1 -1
- package/dist/esm/utils/env_aware_utils.js +9 -1
- package/dist/esm/utils/gemini_schema_util.js +9 -4
- package/dist/esm/utils/logger.js +43 -2
- package/dist/esm/utils/object_notation_utils.js +47 -0
- package/dist/esm/utils/simple_zod_to_json.js +102 -141
- package/dist/esm/utils/variant_utils.js +1 -7
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/part_converter_utils.d.ts +47 -0
- package/dist/types/agents/base_agent.d.ts +2 -1
- package/dist/types/agents/callback_context.d.ts +1 -1
- package/dist/types/agents/llm_agent.d.ts +12 -12
- package/dist/types/agents/loop_agent.d.ts +1 -1
- package/dist/types/agents/parallel_agent.d.ts +1 -1
- package/dist/types/agents/readonly_context.d.ts +8 -0
- package/dist/types/agents/run_config.d.ts +6 -0
- package/dist/types/artifacts/base_artifact_service.d.ts +31 -0
- package/dist/types/artifacts/file_artifact_service.d.ts +43 -0
- package/dist/types/artifacts/gcs_artifact_service.d.ts +3 -1
- package/dist/types/artifacts/in_memory_artifact_service.d.ts +8 -5
- package/dist/types/artifacts/registry.d.ts +7 -0
- package/dist/types/code_executors/built_in_code_executor.d.ts +1 -1
- package/dist/types/code_executors/code_executor_context.d.ts +2 -4
- package/dist/types/common.d.ts +13 -3
- package/dist/types/events/event.d.ts +15 -1
- package/dist/types/events/event_actions.d.ts +1 -1
- package/dist/types/events/structured_events.d.ts +106 -0
- package/dist/types/index.d.ts +7 -3
- package/dist/types/models/apigee_llm.d.ts +59 -0
- package/dist/types/models/base_llm_connection.d.ts +1 -1
- package/dist/types/models/google_llm.d.ts +5 -2
- package/dist/types/models/llm_response.d.ts +1 -1
- package/dist/types/plugins/logging_plugin.d.ts +12 -12
- package/dist/types/plugins/plugin_manager.d.ts +12 -12
- package/dist/types/plugins/security_plugin.d.ts +1 -1
- package/dist/types/runner/runner.d.ts +16 -1
- package/dist/types/sessions/base_session_service.d.ts +20 -0
- package/dist/types/sessions/database_session_service.d.ts +31 -0
- package/dist/types/sessions/db/operations.d.ts +29 -0
- package/dist/types/sessions/db/schema.d.ts +45 -0
- package/dist/types/sessions/in_memory_session_service.d.ts +9 -6
- package/dist/types/sessions/registry.d.ts +7 -0
- package/dist/types/telemetry/setup.d.ts +1 -1
- package/dist/types/telemetry/tracing.d.ts +7 -6
- package/dist/types/tools/agent_tool.d.ts +1 -1
- package/dist/types/tools/base_tool.d.ts +1 -1
- package/dist/types/tools/base_toolset.d.ts +2 -1
- package/dist/types/tools/forwarding_artifact_service.d.ts +4 -2
- package/dist/types/tools/function_tool.d.ts +4 -3
- package/dist/types/tools/google_search_tool.d.ts +3 -3
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +10 -3
- package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -2
- package/dist/types/utils/env_aware_utils.d.ts +7 -0
- package/dist/types/utils/gemini_schema_util.d.ts +4 -12
- package/dist/types/utils/logger.d.ts +11 -10
- package/dist/types/utils/object_notation_utils.d.ts +21 -0
- package/dist/types/utils/simple_zod_to_json.d.ts +5 -4
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/part_converter_utils.js +171 -0
- package/dist/web/agents/base_agent.js +96 -35
- package/dist/web/agents/callback_context.js +4 -1
- package/dist/web/agents/content_processor_utils.js +25 -9
- package/dist/web/agents/functions.js +84 -29
- package/dist/web/agents/llm_agent.js +166 -83
- package/dist/web/agents/loop_agent.js +2 -1
- package/dist/web/agents/parallel_agent.js +3 -4
- package/dist/web/agents/readonly_context.js +12 -0
- package/dist/web/agents/run_config.js +2 -1
- package/dist/web/artifacts/file_artifact_service.js +506 -0
- package/dist/web/artifacts/gcs_artifact_service.js +139 -54
- package/dist/web/artifacts/in_memory_artifact_service.js +69 -8
- package/dist/web/artifacts/registry.js +28 -0
- package/dist/web/auth/auth_handler.js +3 -1
- package/dist/web/code_executors/base_code_executor.js +3 -1
- package/dist/web/code_executors/built_in_code_executor.js +7 -3
- package/dist/web/code_executors/code_executor_context.js +5 -5
- package/dist/web/common.js +12 -2
- package/dist/web/events/event.js +30 -5
- package/dist/web/events/event_actions.js +1 -1
- package/dist/web/events/structured_events.js +74 -0
- package/dist/web/index.js +18 -8
- package/dist/web/memory/in_memory_memory_service.js +3 -1
- package/dist/web/models/apigee_llm.js +219 -0
- package/dist/web/models/base_llm.js +8 -4
- package/dist/web/models/gemini_llm_connection.js +1 -0
- package/dist/web/models/google_llm.js +75 -50
- package/dist/web/models/registry.js +2 -0
- package/dist/web/plugins/base_plugin.js +12 -0
- package/dist/web/plugins/logging_plugin.js +55 -14
- package/dist/web/plugins/plugin_manager.js +56 -24
- package/dist/web/plugins/security_plugin.js +1 -1
- package/dist/web/runner/runner.js +192 -108
- package/dist/web/sessions/base_session_service.js +49 -1
- package/dist/web/sessions/database_session_service.js +368 -0
- package/dist/web/sessions/db/operations.js +87 -0
- package/dist/web/sessions/db/schema.js +172 -0
- package/dist/web/sessions/in_memory_session_service.js +61 -33
- package/dist/web/sessions/registry.js +25 -0
- package/dist/web/telemetry/google_cloud.js +7 -9
- package/dist/web/telemetry/setup.js +23 -9
- package/dist/web/telemetry/tracing.js +37 -15
- package/dist/web/tools/agent_tool.js +8 -4
- package/dist/web/tools/base_tool.js +4 -2
- package/dist/web/tools/forwarding_artifact_service.js +17 -1
- package/dist/web/tools/function_tool.js +1 -2
- package/dist/web/tools/google_search_tool.js +2 -5
- package/dist/web/tools/long_running_tool.js +3 -1
- package/dist/web/tools/mcp/mcp_session_manager.js +22 -12
- package/dist/web/tools/mcp/mcp_tool.js +1 -3
- package/dist/web/tools/mcp/mcp_toolset.js +1 -1
- package/dist/web/utils/env_aware_utils.js +9 -1
- package/dist/web/utils/gemini_schema_util.js +9 -4
- package/dist/web/utils/logger.js +43 -2
- package/dist/web/utils/object_notation_utils.js +47 -0
- package/dist/web/utils/simple_zod_to_json.js +102 -155
- package/dist/web/utils/variant_utils.js +1 -7
- package/dist/web/version.js +1 -1
- package/package.json +16 -5
- package/dist/cjs/index.js.map +0 -7
- package/dist/esm/index.js.map +0 -7
- package/dist/web/index.js.map +0 -7
|
@@ -25,17 +25,18 @@ export interface Logger {
|
|
|
25
25
|
*/
|
|
26
26
|
export declare function setLogLevel(level: LogLevel): void;
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
28
|
+
* Sets a custom logger for ADK, or null to disable logging.
|
|
29
29
|
*/
|
|
30
|
-
declare
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
export declare function setLogger(customLogger: Logger | null): void;
|
|
31
|
+
/**
|
|
32
|
+
* Gets the current logger instance.
|
|
33
|
+
*/
|
|
34
|
+
export declare function getLogger(): Logger;
|
|
35
|
+
/**
|
|
36
|
+
* Resets the logger to the default SimpleLogger.
|
|
37
|
+
*/
|
|
38
|
+
export declare function resetLogger(): void;
|
|
37
39
|
/**
|
|
38
40
|
* The logger instance for ADK.
|
|
39
41
|
*/
|
|
40
|
-
export declare const logger:
|
|
41
|
-
export {};
|
|
42
|
+
export declare const logger: Logger;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Converts an object with snake_case keys to camelCase keys.
|
|
8
|
+
*
|
|
9
|
+
* @param obj The object to convert.
|
|
10
|
+
* @param preserveKeys Keys to preserve in their original form.
|
|
11
|
+
* @returns The object with camelCase keys.
|
|
12
|
+
*/
|
|
13
|
+
export declare function toCamelCase(obj: unknown, preserveKeys?: string[]): unknown;
|
|
14
|
+
/**
|
|
15
|
+
* Converts an object with camelCase keys to snake_case keys.
|
|
16
|
+
*
|
|
17
|
+
* @param obj The object to convert.
|
|
18
|
+
* @param preserveKeys Keys to preserve in their original form.
|
|
19
|
+
* @returns The object with snake_case keys.
|
|
20
|
+
*/
|
|
21
|
+
export declare function toSnakeCase(obj: unknown, preserveKeys?: string[]): unknown;
|
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { Schema } from '@google/genai';
|
|
7
|
-
import {
|
|
7
|
+
import { z as z3 } from 'zod/v3';
|
|
8
|
+
import { z as z4 } from 'zod/v4';
|
|
8
9
|
/**
|
|
9
|
-
* Returns true if the given object is a
|
|
10
|
+
* Returns true if the given object is a ZodObject (supports both Zod v3 and v4).
|
|
10
11
|
*/
|
|
11
|
-
export declare function isZodObject(obj: unknown): obj is ZodObject<
|
|
12
|
-
export declare function zodObjectToSchema(schema: ZodObject<
|
|
12
|
+
export declare function isZodObject(obj: unknown): obj is z3.ZodObject<z3.ZodRawShape> | z4.ZodObject<z4.ZodRawShape>;
|
|
13
|
+
export declare function zodObjectToSchema(schema: z3.ZodObject<z3.ZodRawShape> | z4.ZodObject<z4.ZodRawShape>): Schema;
|
package/dist/types/version.d.ts
CHANGED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
var MetadataKeys = /* @__PURE__ */ ((MetadataKeys2) => {
|
|
7
|
+
MetadataKeys2["TYPE"] = "adk_type";
|
|
8
|
+
MetadataKeys2["LONG_RUNNING"] = "adk_is_long_running";
|
|
9
|
+
MetadataKeys2["THOUGHT"] = "adk_thought";
|
|
10
|
+
return MetadataKeys2;
|
|
11
|
+
})(MetadataKeys || {});
|
|
12
|
+
var DataPartType = /* @__PURE__ */ ((DataPartType2) => {
|
|
13
|
+
DataPartType2["FUNCTION_CALL"] = "function_call";
|
|
14
|
+
DataPartType2["FUNCTION_RESPONSE"] = "function_response";
|
|
15
|
+
DataPartType2["CODE_EXEC_RESULT"] = "code_execution_result";
|
|
16
|
+
DataPartType2["CODE_EXECUTABLE_CODE"] = "executable_code";
|
|
17
|
+
return DataPartType2;
|
|
18
|
+
})(DataPartType || {});
|
|
19
|
+
function toA2AParts(parts, longRunningToolIDs = []) {
|
|
20
|
+
return parts.map((part) => toA2APart(part, longRunningToolIDs));
|
|
21
|
+
}
|
|
22
|
+
function toA2APart(part, longRunningToolIDs) {
|
|
23
|
+
if (part.text !== void 0 && part.text !== null) {
|
|
24
|
+
return toA2ATextPart(part);
|
|
25
|
+
}
|
|
26
|
+
if (part.inlineData || part.fileData) {
|
|
27
|
+
return toA2AFilePart(part);
|
|
28
|
+
}
|
|
29
|
+
return toA2ADataPart(part, longRunningToolIDs);
|
|
30
|
+
}
|
|
31
|
+
function toA2ATextPart(part) {
|
|
32
|
+
const a2aPart = { kind: "text", text: part.text || "" };
|
|
33
|
+
if ("thought" in part && part["thought"]) {
|
|
34
|
+
a2aPart.metadata = {
|
|
35
|
+
["adk_thought" /* THOUGHT */]: true
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return a2aPart;
|
|
39
|
+
}
|
|
40
|
+
function toA2AFilePart(part) {
|
|
41
|
+
if (part.fileData) {
|
|
42
|
+
return {
|
|
43
|
+
kind: "file",
|
|
44
|
+
file: {
|
|
45
|
+
uri: part.fileData.fileUri || "",
|
|
46
|
+
mimeType: part.fileData.mimeType
|
|
47
|
+
},
|
|
48
|
+
metadata: {}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (part.inlineData) {
|
|
52
|
+
return {
|
|
53
|
+
kind: "file",
|
|
54
|
+
file: {
|
|
55
|
+
bytes: part.inlineData.data || "",
|
|
56
|
+
mimeType: part.inlineData.mimeType
|
|
57
|
+
},
|
|
58
|
+
metadata: {}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
throw new Error("Not a file part: ".concat(JSON.stringify(part)));
|
|
62
|
+
}
|
|
63
|
+
function toA2ADataPart(part, longRunningToolIDs = []) {
|
|
64
|
+
let type;
|
|
65
|
+
let data;
|
|
66
|
+
if (part.functionCall) {
|
|
67
|
+
type = "function_call" /* FUNCTION_CALL */;
|
|
68
|
+
data = part.functionCall;
|
|
69
|
+
} else if (part.functionResponse) {
|
|
70
|
+
type = "function_response" /* FUNCTION_RESPONSE */;
|
|
71
|
+
data = part.functionResponse;
|
|
72
|
+
} else if (part.executableCode) {
|
|
73
|
+
type = "executable_code" /* CODE_EXECUTABLE_CODE */;
|
|
74
|
+
data = part.executableCode;
|
|
75
|
+
} else if (part.codeExecutionResult) {
|
|
76
|
+
type = "code_execution_result" /* CODE_EXEC_RESULT */;
|
|
77
|
+
data = part.codeExecutionResult;
|
|
78
|
+
} else {
|
|
79
|
+
throw new Error("Unknown part type: ".concat(JSON.stringify(part)));
|
|
80
|
+
}
|
|
81
|
+
const metadata = {
|
|
82
|
+
["adk_type" /* TYPE */]: type
|
|
83
|
+
};
|
|
84
|
+
if (part.functionCall && part.functionCall.name && longRunningToolIDs.includes(part.functionCall.name)) {
|
|
85
|
+
metadata["adk_is_long_running" /* LONG_RUNNING */] = true;
|
|
86
|
+
}
|
|
87
|
+
if (part.functionResponse && part.functionResponse.name && longRunningToolIDs.includes(part.functionResponse.name)) {
|
|
88
|
+
metadata["adk_is_long_running" /* LONG_RUNNING */] = true;
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
kind: "data",
|
|
92
|
+
data,
|
|
93
|
+
metadata
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function toGenAIParts(a2aParts) {
|
|
97
|
+
return a2aParts.map((a2aPart) => toGenAIPart(a2aPart));
|
|
98
|
+
}
|
|
99
|
+
function toGenAIPart(a2aPart) {
|
|
100
|
+
if (a2aPart.kind === "text") {
|
|
101
|
+
return toGenAIPartText(a2aPart);
|
|
102
|
+
}
|
|
103
|
+
if (a2aPart.kind === "file") {
|
|
104
|
+
return toGenAIPartFile(a2aPart);
|
|
105
|
+
}
|
|
106
|
+
if (a2aPart.kind === "data") {
|
|
107
|
+
return toGenAIPartData(a2aPart);
|
|
108
|
+
}
|
|
109
|
+
throw new Error("Unknown part kind: ".concat(JSON.stringify(a2aPart)));
|
|
110
|
+
}
|
|
111
|
+
function toGenAIPartText(a2aPart) {
|
|
112
|
+
var _a;
|
|
113
|
+
return {
|
|
114
|
+
text: a2aPart.text,
|
|
115
|
+
thought: !!((_a = a2aPart.metadata) == null ? void 0 : _a["adk_thought" /* THOUGHT */])
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function toGenAIPartFile(a2aPart) {
|
|
119
|
+
if ("bytes" in a2aPart.file) {
|
|
120
|
+
return {
|
|
121
|
+
inlineData: {
|
|
122
|
+
data: a2aPart.file.bytes,
|
|
123
|
+
mimeType: a2aPart.file.mimeType || ""
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
if ("uri" in a2aPart.file) {
|
|
128
|
+
return {
|
|
129
|
+
fileData: {
|
|
130
|
+
fileUri: a2aPart.file.uri,
|
|
131
|
+
mimeType: a2aPart.file.mimeType || ""
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
throw new Error("Not a file part: ".concat(JSON.stringify(a2aPart)));
|
|
136
|
+
}
|
|
137
|
+
function toGenAIPartData(a2aPart) {
|
|
138
|
+
var _a;
|
|
139
|
+
if (!a2aPart.data) {
|
|
140
|
+
throw new Error("No data in part: ".concat(JSON.stringify(a2aPart)));
|
|
141
|
+
}
|
|
142
|
+
const data = a2aPart.data;
|
|
143
|
+
const type = (_a = a2aPart.metadata) == null ? void 0 : _a["adk_type" /* TYPE */];
|
|
144
|
+
if (type === "function_call" /* FUNCTION_CALL */) {
|
|
145
|
+
return { functionCall: data };
|
|
146
|
+
}
|
|
147
|
+
if (type === "function_response" /* FUNCTION_RESPONSE */) {
|
|
148
|
+
return { functionResponse: data };
|
|
149
|
+
}
|
|
150
|
+
if (type === "executable_code" /* CODE_EXECUTABLE_CODE */) {
|
|
151
|
+
return { executableCode: data };
|
|
152
|
+
}
|
|
153
|
+
if (type === "code_execution_result" /* CODE_EXEC_RESULT */) {
|
|
154
|
+
return { codeExecutionResult: data };
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
text: JSON.stringify(a2aPart.data)
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
export {
|
|
161
|
+
toA2ADataPart,
|
|
162
|
+
toA2AFilePart,
|
|
163
|
+
toA2APart,
|
|
164
|
+
toA2AParts,
|
|
165
|
+
toA2ATextPart,
|
|
166
|
+
toGenAIPart,
|
|
167
|
+
toGenAIPartData,
|
|
168
|
+
toGenAIPartFile,
|
|
169
|
+
toGenAIPartText,
|
|
170
|
+
toGenAIParts
|
|
171
|
+
};
|
|
@@ -5,6 +5,9 @@ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
7
|
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
8
|
+
var __typeError = (msg) => {
|
|
9
|
+
throw TypeError(msg);
|
|
10
|
+
};
|
|
8
11
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
12
|
var __spreadValues = (a, b) => {
|
|
10
13
|
for (var prop in b || (b = {}))
|
|
@@ -33,6 +36,34 @@ var __asyncGenerator = (__this, __arguments, generator) => {
|
|
|
33
36
|
}, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
|
|
34
37
|
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
35
38
|
};
|
|
39
|
+
var __yieldStar = (value) => {
|
|
40
|
+
var obj = value[__knownSymbol("asyncIterator")], isAwait = false, method, it = {};
|
|
41
|
+
if (obj == null) {
|
|
42
|
+
obj = value[__knownSymbol("iterator")]();
|
|
43
|
+
method = (k) => it[k] = (x) => obj[k](x);
|
|
44
|
+
} else {
|
|
45
|
+
obj = obj.call(value);
|
|
46
|
+
method = (k) => it[k] = (v) => {
|
|
47
|
+
if (isAwait) {
|
|
48
|
+
isAwait = false;
|
|
49
|
+
if (k === "throw") throw v;
|
|
50
|
+
return v;
|
|
51
|
+
}
|
|
52
|
+
isAwait = true;
|
|
53
|
+
return {
|
|
54
|
+
done: false,
|
|
55
|
+
value: new __await(new Promise((resolve) => {
|
|
56
|
+
var x = obj[k](v);
|
|
57
|
+
if (!(x instanceof Object)) __typeError("Object expected");
|
|
58
|
+
resolve(x);
|
|
59
|
+
}), 1)
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return it[__knownSymbol("iterator")] = () => it, method("next"), "throw" in obj ? method("throw") : it.throw = (x) => {
|
|
64
|
+
throw x;
|
|
65
|
+
}, "return" in obj && method("return"), it;
|
|
66
|
+
};
|
|
36
67
|
var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
|
|
37
68
|
/**
|
|
38
69
|
* @license
|
|
@@ -40,8 +71,13 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
|
|
|
40
71
|
* SPDX-License-Identifier: Apache-2.0
|
|
41
72
|
*/
|
|
42
73
|
var _a;
|
|
43
|
-
import { trace } from "@opentelemetry/api";
|
|
74
|
+
import { context, trace } from "@opentelemetry/api";
|
|
44
75
|
import { createEvent } from "../events/event.js";
|
|
76
|
+
import {
|
|
77
|
+
runAsyncGeneratorWithOtelContext,
|
|
78
|
+
traceAgentInvocation,
|
|
79
|
+
tracer
|
|
80
|
+
} from "../telemetry/tracing.js";
|
|
45
81
|
import { CallbackContext } from "./callback_context.js";
|
|
46
82
|
import { InvocationContext } from "./invocation_context.js";
|
|
47
83
|
const BASE_AGENT_SIGNATURE_SYMBOL = Symbol.for("google.adk.baseAgent");
|
|
@@ -59,13 +95,19 @@ class BaseAgent {
|
|
|
59
95
|
this.description = config.description;
|
|
60
96
|
this.parentAgent = config.parentAgent;
|
|
61
97
|
this.subAgents = config.subAgents || [];
|
|
62
|
-
this.rootAgent = getRootAgent(this);
|
|
63
98
|
this.beforeAgentCallback = getCannonicalCallback(
|
|
64
99
|
config.beforeAgentCallback
|
|
65
100
|
);
|
|
66
101
|
this.afterAgentCallback = getCannonicalCallback(config.afterAgentCallback);
|
|
67
102
|
this.setParentAgentForSubAgents();
|
|
68
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Root agent of this agent.
|
|
106
|
+
* Computed dynamically by traversing up the parent chain.
|
|
107
|
+
*/
|
|
108
|
+
get rootAgent() {
|
|
109
|
+
return getRootAgent(this);
|
|
110
|
+
}
|
|
69
111
|
/**
|
|
70
112
|
* Entry method to run an agent via text-based conversation.
|
|
71
113
|
*
|
|
@@ -75,38 +117,48 @@ class BaseAgent {
|
|
|
75
117
|
*/
|
|
76
118
|
runAsync(parentContext) {
|
|
77
119
|
return __asyncGenerator(this, null, function* () {
|
|
78
|
-
const span =
|
|
120
|
+
const span = tracer.startSpan("invoke_agent ".concat(this.name));
|
|
121
|
+
const ctx = trace.setSpan(context.active(), span);
|
|
79
122
|
try {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
123
|
+
yield* __yieldStar(runAsyncGeneratorWithOtelContext(
|
|
124
|
+
ctx,
|
|
125
|
+
this,
|
|
126
|
+
function() {
|
|
127
|
+
return __asyncGenerator(this, null, function* () {
|
|
128
|
+
const context2 = this.createInvocationContext(parentContext);
|
|
129
|
+
const beforeAgentCallbackEvent = yield new __await(this.handleBeforeAgentCallback(context2));
|
|
130
|
+
if (beforeAgentCallbackEvent) {
|
|
131
|
+
yield beforeAgentCallbackEvent;
|
|
132
|
+
}
|
|
133
|
+
if (context2.endInvocation) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
traceAgentInvocation({ agent: this, invocationContext: context2 });
|
|
137
|
+
try {
|
|
138
|
+
for (var iter = __forAwait(this.runAsyncImpl(context2)), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
139
|
+
const event = temp.value;
|
|
140
|
+
yield event;
|
|
141
|
+
}
|
|
142
|
+
} catch (temp) {
|
|
143
|
+
error = [temp];
|
|
144
|
+
} finally {
|
|
145
|
+
try {
|
|
146
|
+
more && (temp = iter.return) && (yield new __await(temp.call(iter)));
|
|
147
|
+
} finally {
|
|
148
|
+
if (error)
|
|
149
|
+
throw error[0];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (context2.endInvocation) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const afterAgentCallbackEvent = yield new __await(this.handleAfterAgentCallback(context2));
|
|
156
|
+
if (afterAgentCallbackEvent) {
|
|
157
|
+
yield afterAgentCallbackEvent;
|
|
158
|
+
}
|
|
159
|
+
});
|
|
92
160
|
}
|
|
93
|
-
|
|
94
|
-
error = [temp];
|
|
95
|
-
} finally {
|
|
96
|
-
try {
|
|
97
|
-
more && (temp = iter.return) && (yield new __await(temp.call(iter)));
|
|
98
|
-
} finally {
|
|
99
|
-
if (error)
|
|
100
|
-
throw error[0];
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (context.endInvocation) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
const afterAgentCallbackEvent = yield new __await(this.handleAfterAgentCallback(context));
|
|
107
|
-
if (afterAgentCallbackEvent) {
|
|
108
|
-
yield afterAgentCallbackEvent;
|
|
109
|
-
}
|
|
161
|
+
));
|
|
110
162
|
} finally {
|
|
111
163
|
span.end();
|
|
112
164
|
}
|
|
@@ -121,8 +173,17 @@ class BaseAgent {
|
|
|
121
173
|
*/
|
|
122
174
|
runLive(parentContext) {
|
|
123
175
|
return __asyncGenerator(this, null, function* () {
|
|
124
|
-
const span =
|
|
176
|
+
const span = tracer.startSpan("invoke_agent ".concat(this.name));
|
|
177
|
+
const ctx = trace.setSpan(context.active(), span);
|
|
125
178
|
try {
|
|
179
|
+
yield* __yieldStar(runAsyncGeneratorWithOtelContext(
|
|
180
|
+
ctx,
|
|
181
|
+
this,
|
|
182
|
+
function() {
|
|
183
|
+
return __asyncGenerator(this, null, function* () {
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
));
|
|
126
187
|
throw new Error("Live mode is not implemented yet.");
|
|
127
188
|
} finally {
|
|
128
189
|
span.end();
|
|
@@ -250,7 +311,7 @@ class BaseAgent {
|
|
|
250
311
|
function validateAgentName(name) {
|
|
251
312
|
if (!isIdentifier(name)) {
|
|
252
313
|
throw new Error(
|
|
253
|
-
'Found invalid agent name: "'.concat(name, '". Agent name must be a valid identifier. It should start with a letter (a-z, A-Z) or an underscore (_), and can only contain letters, digits (0-9), and
|
|
314
|
+
'Found invalid agent name: "'.concat(name, '". Agent name must be a valid identifier. It should start with a letter (a-z, A-Z) or an underscore (_), and can only contain letters, digits (0-9), underscores, and hyphens.')
|
|
254
315
|
);
|
|
255
316
|
}
|
|
256
317
|
if (name === "user") {
|
|
@@ -261,7 +322,7 @@ function validateAgentName(name) {
|
|
|
261
322
|
return name;
|
|
262
323
|
}
|
|
263
324
|
function isIdentifier(str) {
|
|
264
|
-
return new RegExp("^[\\p{ID_Start}$_][\\p{ID_Continue}$_]*$", "u").test(str);
|
|
325
|
+
return new RegExp("^[\\p{ID_Start}$_][\\p{ID_Continue}$_-]*$", "u").test(str);
|
|
265
326
|
}
|
|
266
327
|
function getRootAgent(rootAgent) {
|
|
267
328
|
while (rootAgent.parentAgent) {
|
|
@@ -7,7 +7,10 @@ import { createEventActions } from "../events/event_actions.js";
|
|
|
7
7
|
import { State } from "../sessions/state.js";
|
|
8
8
|
import { ReadonlyContext } from "./readonly_context.js";
|
|
9
9
|
class CallbackContext extends ReadonlyContext {
|
|
10
|
-
constructor({
|
|
10
|
+
constructor({
|
|
11
|
+
invocationContext,
|
|
12
|
+
eventActions
|
|
13
|
+
}) {
|
|
11
14
|
super(invocationContext);
|
|
12
15
|
this.eventActions = eventActions || createEventActions();
|
|
13
16
|
this._state = new State(
|
|
@@ -4,8 +4,16 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { cloneDeep } from "lodash-es";
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import {
|
|
8
|
+
createEvent,
|
|
9
|
+
getFunctionCalls,
|
|
10
|
+
getFunctionResponses
|
|
11
|
+
} from "../events/event.js";
|
|
12
|
+
import {
|
|
13
|
+
removeClientFunctionCallId,
|
|
14
|
+
REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
|
|
15
|
+
REQUEST_EUC_FUNCTION_CALL_NAME
|
|
16
|
+
} from "./functions.js";
|
|
9
17
|
function getContents(events, agentName, currentBranch) {
|
|
10
18
|
var _a, _b, _c;
|
|
11
19
|
const filteredEvents = [];
|
|
@@ -79,9 +87,11 @@ function convertForeignEvent(event) {
|
|
|
79
87
|
}
|
|
80
88
|
const content = {
|
|
81
89
|
role: "user",
|
|
82
|
-
parts: [
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
parts: [
|
|
91
|
+
{
|
|
92
|
+
text: "For context:"
|
|
93
|
+
}
|
|
94
|
+
]
|
|
85
95
|
};
|
|
86
96
|
for (const part of event.content.parts) {
|
|
87
97
|
if (part.text && !part.thought) {
|
|
@@ -183,10 +193,14 @@ function rearrangeEventsForLatestFunctionResponse(events) {
|
|
|
183
193
|
const functionCallIds = new Set(
|
|
184
194
|
functionCalls.map((fc) => fc.id).filter((id) => !!id)
|
|
185
195
|
);
|
|
186
|
-
const isSubset = Array.from(functionResponsesIds).every(
|
|
196
|
+
const isSubset = Array.from(functionResponsesIds).every(
|
|
197
|
+
(id) => functionCallIds.has(id)
|
|
198
|
+
);
|
|
187
199
|
if (!isSubset) {
|
|
188
200
|
throw new Error(
|
|
189
|
-
"Last response event should only contain the responses for the function calls in the same function call event. Function" + " call ids found : ".concat(Array.from(functionCallIds).join(
|
|
201
|
+
"Last response event should only contain the responses for the function calls in the same function call event. Function" + " call ids found : ".concat(Array.from(functionCallIds).join(
|
|
202
|
+
", "
|
|
203
|
+
), ", function response") + " ids provided: ".concat(Array.from(functionResponsesIds).join(", "))
|
|
190
204
|
);
|
|
191
205
|
}
|
|
192
206
|
functionResponsesIds = functionCallIds;
|
|
@@ -254,7 +268,9 @@ function rearrangeEventsForAsyncFunctionResponsesInHistory(events) {
|
|
|
254
268
|
const [responseIndex] = [...functionResponseEventsIndices];
|
|
255
269
|
resultEvents.push(events[responseIndex]);
|
|
256
270
|
} else {
|
|
257
|
-
const indicesArray = Array.from(functionResponseEventsIndices).sort(
|
|
271
|
+
const indicesArray = Array.from(functionResponseEventsIndices).sort(
|
|
272
|
+
(a, b) => a - b
|
|
273
|
+
);
|
|
258
274
|
const eventsToMerge = indicesArray.map((index) => events[index]);
|
|
259
275
|
resultEvents.push(mergeFunctionResponseEvents(eventsToMerge));
|
|
260
276
|
}
|
|
@@ -270,7 +286,7 @@ function safeStringify(obj) {
|
|
|
270
286
|
}
|
|
271
287
|
try {
|
|
272
288
|
return JSON.stringify(obj);
|
|
273
|
-
} catch (
|
|
289
|
+
} catch (_e) {
|
|
274
290
|
return String(obj);
|
|
275
291
|
}
|
|
276
292
|
}
|
|
@@ -10,6 +10,11 @@ import { mergeEventActions } from "../events/event_actions.js";
|
|
|
10
10
|
import { ToolContext } from "../tools/tool_context.js";
|
|
11
11
|
import { randomUUID } from "../utils/env_aware_utils.js";
|
|
12
12
|
import { logger } from "../utils/logger.js";
|
|
13
|
+
import {
|
|
14
|
+
traceMergedToolCalls,
|
|
15
|
+
tracer,
|
|
16
|
+
traceToolCall
|
|
17
|
+
} from "../telemetry/tracing.js";
|
|
13
18
|
const AF_FUNCTION_CALL_ID_PREFIX = "adk-";
|
|
14
19
|
const REQUEST_EUC_FUNCTION_CALL_NAME = "adk_request_credential";
|
|
15
20
|
const REQUEST_CONFIRMATION_FUNCTION_CALL_NAME = "adk_request_confirmation";
|
|
@@ -123,12 +128,56 @@ function generateRequestConfirmationEvent({
|
|
|
123
128
|
parts,
|
|
124
129
|
role: functionResponseEvent.content.role
|
|
125
130
|
},
|
|
131
|
+
actions: functionResponseEvent.actions,
|
|
126
132
|
longRunningToolIds: Array.from(longRunningToolIds)
|
|
127
133
|
});
|
|
128
134
|
}
|
|
129
135
|
async function callToolAsync(tool, args, toolContext) {
|
|
130
|
-
|
|
131
|
-
|
|
136
|
+
return tracer.startActiveSpan("execute_tool ".concat(tool.name), async (span) => {
|
|
137
|
+
try {
|
|
138
|
+
logger.debug("callToolAsync ".concat(tool.name));
|
|
139
|
+
const result = await tool.runAsync({ args, toolContext });
|
|
140
|
+
traceToolCall({
|
|
141
|
+
tool,
|
|
142
|
+
args,
|
|
143
|
+
functionResponseEvent: buildResponseEvent(
|
|
144
|
+
tool,
|
|
145
|
+
result,
|
|
146
|
+
toolContext,
|
|
147
|
+
toolContext.invocationContext
|
|
148
|
+
)
|
|
149
|
+
});
|
|
150
|
+
return result;
|
|
151
|
+
} finally {
|
|
152
|
+
span.end();
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function buildResponseEvent(tool, functionResult, toolContext, invocationContext) {
|
|
157
|
+
let responseResult;
|
|
158
|
+
if (typeof functionResult !== "object" || functionResult == null) {
|
|
159
|
+
responseResult = { result: functionResult };
|
|
160
|
+
} else {
|
|
161
|
+
responseResult = functionResult;
|
|
162
|
+
}
|
|
163
|
+
const partFunctionResponse = {
|
|
164
|
+
functionResponse: {
|
|
165
|
+
name: tool.name,
|
|
166
|
+
response: responseResult,
|
|
167
|
+
id: toolContext.functionCallId
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
const content = {
|
|
171
|
+
role: "user",
|
|
172
|
+
parts: [partFunctionResponse]
|
|
173
|
+
};
|
|
174
|
+
return createEvent({
|
|
175
|
+
invocationId: invocationContext.invocationId,
|
|
176
|
+
author: invocationContext.agent.name,
|
|
177
|
+
content,
|
|
178
|
+
actions: toolContext.actions,
|
|
179
|
+
branch: invocationContext.branch
|
|
180
|
+
});
|
|
132
181
|
}
|
|
133
182
|
async function handleFunctionCallsAsync({
|
|
134
183
|
invocationContext,
|
|
@@ -169,14 +218,12 @@ async function handleFunctionCallList({
|
|
|
169
218
|
if (toolConfirmationDict && functionCall.id) {
|
|
170
219
|
toolConfirmation = toolConfirmationDict[functionCall.id];
|
|
171
220
|
}
|
|
172
|
-
const { tool, toolContext } = getToolAndContext(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
);
|
|
221
|
+
const { tool, toolContext } = getToolAndContext({
|
|
222
|
+
invocationContext,
|
|
223
|
+
functionCall,
|
|
224
|
+
toolsDict,
|
|
225
|
+
toolConfirmation
|
|
226
|
+
});
|
|
180
227
|
logger.debug("execute_tool ".concat(tool.name));
|
|
181
228
|
const functionArgs = (_a = functionCall.args) != null ? _a : {};
|
|
182
229
|
let functionResponse = null;
|
|
@@ -200,21 +247,15 @@ async function handleFunctionCallList({
|
|
|
200
247
|
}
|
|
201
248
|
if (functionResponse == null) {
|
|
202
249
|
try {
|
|
203
|
-
functionResponse = await callToolAsync(
|
|
204
|
-
tool,
|
|
205
|
-
functionArgs,
|
|
206
|
-
toolContext
|
|
207
|
-
);
|
|
250
|
+
functionResponse = await callToolAsync(tool, functionArgs, toolContext);
|
|
208
251
|
} catch (e) {
|
|
209
252
|
if (e instanceof Error) {
|
|
210
|
-
const onToolErrorResponse = await invocationContext.pluginManager.runOnToolErrorCallback(
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
);
|
|
253
|
+
const onToolErrorResponse = await invocationContext.pluginManager.runOnToolErrorCallback({
|
|
254
|
+
tool,
|
|
255
|
+
toolArgs: functionArgs,
|
|
256
|
+
toolContext,
|
|
257
|
+
error: e
|
|
258
|
+
});
|
|
218
259
|
if (onToolErrorResponse) {
|
|
219
260
|
functionResponse = onToolErrorResponse;
|
|
220
261
|
} else {
|
|
@@ -278,12 +319,24 @@ async function handleFunctionCallList({
|
|
|
278
319
|
if (!functionResponseEvents.length) {
|
|
279
320
|
return null;
|
|
280
321
|
}
|
|
281
|
-
const mergedEvent = mergeParallelFunctionResponseEvents(
|
|
322
|
+
const mergedEvent = mergeParallelFunctionResponseEvents(
|
|
323
|
+
functionResponseEvents
|
|
324
|
+
);
|
|
282
325
|
if (functionResponseEvents.length > 1) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
326
|
+
tracer.startActiveSpan("execute_tool (merged)", (span) => {
|
|
327
|
+
try {
|
|
328
|
+
logger.debug("execute_tool (merged)");
|
|
329
|
+
logger.debug("traceMergedToolCalls", {
|
|
330
|
+
responseEventId: mergedEvent.id,
|
|
331
|
+
functionResponseEvent: mergedEvent.id
|
|
332
|
+
});
|
|
333
|
+
traceMergedToolCalls({
|
|
334
|
+
responseEventId: mergedEvent.id,
|
|
335
|
+
functionResponseEvent: mergedEvent
|
|
336
|
+
});
|
|
337
|
+
} finally {
|
|
338
|
+
span.end();
|
|
339
|
+
}
|
|
287
340
|
});
|
|
288
341
|
}
|
|
289
342
|
return mergedEvent;
|
|
@@ -321,7 +374,9 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
|
|
|
321
374
|
}
|
|
322
375
|
}
|
|
323
376
|
const baseEvent = functionResponseEvents[0];
|
|
324
|
-
const actionsList = functionResponseEvents.map(
|
|
377
|
+
const actionsList = functionResponseEvents.map(
|
|
378
|
+
(event) => event.actions || {}
|
|
379
|
+
);
|
|
325
380
|
const mergedActions = mergeEventActions(actionsList);
|
|
326
381
|
return createEvent({
|
|
327
382
|
author: baseEvent.author,
|