@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
|
@@ -0,0 +1,210 @@
|
|
|
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 __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var part_converter_utils_exports = {};
|
|
26
|
+
__export(part_converter_utils_exports, {
|
|
27
|
+
toA2ADataPart: () => toA2ADataPart,
|
|
28
|
+
toA2AFilePart: () => toA2AFilePart,
|
|
29
|
+
toA2APart: () => toA2APart,
|
|
30
|
+
toA2AParts: () => toA2AParts,
|
|
31
|
+
toA2ATextPart: () => toA2ATextPart,
|
|
32
|
+
toGenAIPart: () => toGenAIPart,
|
|
33
|
+
toGenAIPartData: () => toGenAIPartData,
|
|
34
|
+
toGenAIPartFile: () => toGenAIPartFile,
|
|
35
|
+
toGenAIPartText: () => toGenAIPartText,
|
|
36
|
+
toGenAIParts: () => toGenAIParts
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(part_converter_utils_exports);
|
|
39
|
+
/**
|
|
40
|
+
* @license
|
|
41
|
+
* Copyright 2026 Google LLC
|
|
42
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
43
|
+
*/
|
|
44
|
+
var MetadataKeys = /* @__PURE__ */ ((MetadataKeys2) => {
|
|
45
|
+
MetadataKeys2["TYPE"] = "adk_type";
|
|
46
|
+
MetadataKeys2["LONG_RUNNING"] = "adk_is_long_running";
|
|
47
|
+
MetadataKeys2["THOUGHT"] = "adk_thought";
|
|
48
|
+
return MetadataKeys2;
|
|
49
|
+
})(MetadataKeys || {});
|
|
50
|
+
var DataPartType = /* @__PURE__ */ ((DataPartType2) => {
|
|
51
|
+
DataPartType2["FUNCTION_CALL"] = "function_call";
|
|
52
|
+
DataPartType2["FUNCTION_RESPONSE"] = "function_response";
|
|
53
|
+
DataPartType2["CODE_EXEC_RESULT"] = "code_execution_result";
|
|
54
|
+
DataPartType2["CODE_EXECUTABLE_CODE"] = "executable_code";
|
|
55
|
+
return DataPartType2;
|
|
56
|
+
})(DataPartType || {});
|
|
57
|
+
function toA2AParts(parts, longRunningToolIDs = []) {
|
|
58
|
+
return parts.map((part) => toA2APart(part, longRunningToolIDs));
|
|
59
|
+
}
|
|
60
|
+
function toA2APart(part, longRunningToolIDs) {
|
|
61
|
+
if (part.text !== void 0 && part.text !== null) {
|
|
62
|
+
return toA2ATextPart(part);
|
|
63
|
+
}
|
|
64
|
+
if (part.inlineData || part.fileData) {
|
|
65
|
+
return toA2AFilePart(part);
|
|
66
|
+
}
|
|
67
|
+
return toA2ADataPart(part, longRunningToolIDs);
|
|
68
|
+
}
|
|
69
|
+
function toA2ATextPart(part) {
|
|
70
|
+
const a2aPart = { kind: "text", text: part.text || "" };
|
|
71
|
+
if ("thought" in part && part["thought"]) {
|
|
72
|
+
a2aPart.metadata = {
|
|
73
|
+
["adk_thought" /* THOUGHT */]: true
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return a2aPart;
|
|
77
|
+
}
|
|
78
|
+
function toA2AFilePart(part) {
|
|
79
|
+
if (part.fileData) {
|
|
80
|
+
return {
|
|
81
|
+
kind: "file",
|
|
82
|
+
file: {
|
|
83
|
+
uri: part.fileData.fileUri || "",
|
|
84
|
+
mimeType: part.fileData.mimeType
|
|
85
|
+
},
|
|
86
|
+
metadata: {}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (part.inlineData) {
|
|
90
|
+
return {
|
|
91
|
+
kind: "file",
|
|
92
|
+
file: {
|
|
93
|
+
bytes: part.inlineData.data || "",
|
|
94
|
+
mimeType: part.inlineData.mimeType
|
|
95
|
+
},
|
|
96
|
+
metadata: {}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
throw new Error(`Not a file part: ${JSON.stringify(part)}`);
|
|
100
|
+
}
|
|
101
|
+
function toA2ADataPart(part, longRunningToolIDs = []) {
|
|
102
|
+
let type;
|
|
103
|
+
let data;
|
|
104
|
+
if (part.functionCall) {
|
|
105
|
+
type = "function_call" /* FUNCTION_CALL */;
|
|
106
|
+
data = part.functionCall;
|
|
107
|
+
} else if (part.functionResponse) {
|
|
108
|
+
type = "function_response" /* FUNCTION_RESPONSE */;
|
|
109
|
+
data = part.functionResponse;
|
|
110
|
+
} else if (part.executableCode) {
|
|
111
|
+
type = "executable_code" /* CODE_EXECUTABLE_CODE */;
|
|
112
|
+
data = part.executableCode;
|
|
113
|
+
} else if (part.codeExecutionResult) {
|
|
114
|
+
type = "code_execution_result" /* CODE_EXEC_RESULT */;
|
|
115
|
+
data = part.codeExecutionResult;
|
|
116
|
+
} else {
|
|
117
|
+
throw new Error(`Unknown part type: ${JSON.stringify(part)}`);
|
|
118
|
+
}
|
|
119
|
+
const metadata = {
|
|
120
|
+
["adk_type" /* TYPE */]: type
|
|
121
|
+
};
|
|
122
|
+
if (part.functionCall && part.functionCall.name && longRunningToolIDs.includes(part.functionCall.name)) {
|
|
123
|
+
metadata["adk_is_long_running" /* LONG_RUNNING */] = true;
|
|
124
|
+
}
|
|
125
|
+
if (part.functionResponse && part.functionResponse.name && longRunningToolIDs.includes(part.functionResponse.name)) {
|
|
126
|
+
metadata["adk_is_long_running" /* LONG_RUNNING */] = true;
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
kind: "data",
|
|
130
|
+
data,
|
|
131
|
+
metadata
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function toGenAIParts(a2aParts) {
|
|
135
|
+
return a2aParts.map((a2aPart) => toGenAIPart(a2aPart));
|
|
136
|
+
}
|
|
137
|
+
function toGenAIPart(a2aPart) {
|
|
138
|
+
if (a2aPart.kind === "text") {
|
|
139
|
+
return toGenAIPartText(a2aPart);
|
|
140
|
+
}
|
|
141
|
+
if (a2aPart.kind === "file") {
|
|
142
|
+
return toGenAIPartFile(a2aPart);
|
|
143
|
+
}
|
|
144
|
+
if (a2aPart.kind === "data") {
|
|
145
|
+
return toGenAIPartData(a2aPart);
|
|
146
|
+
}
|
|
147
|
+
throw new Error(`Unknown part kind: ${JSON.stringify(a2aPart)}`);
|
|
148
|
+
}
|
|
149
|
+
function toGenAIPartText(a2aPart) {
|
|
150
|
+
var _a;
|
|
151
|
+
return {
|
|
152
|
+
text: a2aPart.text,
|
|
153
|
+
thought: !!((_a = a2aPart.metadata) == null ? void 0 : _a["adk_thought" /* THOUGHT */])
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function toGenAIPartFile(a2aPart) {
|
|
157
|
+
if ("bytes" in a2aPart.file) {
|
|
158
|
+
return {
|
|
159
|
+
inlineData: {
|
|
160
|
+
data: a2aPart.file.bytes,
|
|
161
|
+
mimeType: a2aPart.file.mimeType || ""
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
if ("uri" in a2aPart.file) {
|
|
166
|
+
return {
|
|
167
|
+
fileData: {
|
|
168
|
+
fileUri: a2aPart.file.uri,
|
|
169
|
+
mimeType: a2aPart.file.mimeType || ""
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
throw new Error(`Not a file part: ${JSON.stringify(a2aPart)}`);
|
|
174
|
+
}
|
|
175
|
+
function toGenAIPartData(a2aPart) {
|
|
176
|
+
var _a;
|
|
177
|
+
if (!a2aPart.data) {
|
|
178
|
+
throw new Error(`No data in part: ${JSON.stringify(a2aPart)}`);
|
|
179
|
+
}
|
|
180
|
+
const data = a2aPart.data;
|
|
181
|
+
const type = (_a = a2aPart.metadata) == null ? void 0 : _a["adk_type" /* TYPE */];
|
|
182
|
+
if (type === "function_call" /* FUNCTION_CALL */) {
|
|
183
|
+
return { functionCall: data };
|
|
184
|
+
}
|
|
185
|
+
if (type === "function_response" /* FUNCTION_RESPONSE */) {
|
|
186
|
+
return { functionResponse: data };
|
|
187
|
+
}
|
|
188
|
+
if (type === "executable_code" /* CODE_EXECUTABLE_CODE */) {
|
|
189
|
+
return { executableCode: data };
|
|
190
|
+
}
|
|
191
|
+
if (type === "code_execution_result" /* CODE_EXEC_RESULT */) {
|
|
192
|
+
return { codeExecutionResult: data };
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
text: JSON.stringify(a2aPart.data)
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
199
|
+
0 && (module.exports = {
|
|
200
|
+
toA2ADataPart,
|
|
201
|
+
toA2AFilePart,
|
|
202
|
+
toA2APart,
|
|
203
|
+
toA2AParts,
|
|
204
|
+
toA2ATextPart,
|
|
205
|
+
toGenAIPart,
|
|
206
|
+
toGenAIPartData,
|
|
207
|
+
toGenAIPartFile,
|
|
208
|
+
toGenAIPartText,
|
|
209
|
+
toGenAIParts
|
|
210
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -31,6 +31,7 @@ __export(base_agent_exports, {
|
|
|
31
31
|
module.exports = __toCommonJS(base_agent_exports);
|
|
32
32
|
var import_api = require("@opentelemetry/api");
|
|
33
33
|
var import_event = require("../events/event.js");
|
|
34
|
+
var import_tracing = require("../telemetry/tracing.js");
|
|
34
35
|
var import_callback_context = require("./callback_context.js");
|
|
35
36
|
var import_invocation_context = require("./invocation_context.js");
|
|
36
37
|
/**
|
|
@@ -54,13 +55,19 @@ class BaseAgent {
|
|
|
54
55
|
this.description = config.description;
|
|
55
56
|
this.parentAgent = config.parentAgent;
|
|
56
57
|
this.subAgents = config.subAgents || [];
|
|
57
|
-
this.rootAgent = getRootAgent(this);
|
|
58
58
|
this.beforeAgentCallback = getCannonicalCallback(
|
|
59
59
|
config.beforeAgentCallback
|
|
60
60
|
);
|
|
61
61
|
this.afterAgentCallback = getCannonicalCallback(config.afterAgentCallback);
|
|
62
62
|
this.setParentAgentForSubAgents();
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Root agent of this agent.
|
|
66
|
+
* Computed dynamically by traversing up the parent chain.
|
|
67
|
+
*/
|
|
68
|
+
get rootAgent() {
|
|
69
|
+
return getRootAgent(this);
|
|
70
|
+
}
|
|
64
71
|
/**
|
|
65
72
|
* Entry method to run an agent via text-based conversation.
|
|
66
73
|
*
|
|
@@ -69,26 +76,34 @@ class BaseAgent {
|
|
|
69
76
|
* @returns An AsyncGenerator that yields the events generated by the agent.
|
|
70
77
|
*/
|
|
71
78
|
async *runAsync(parentContext) {
|
|
72
|
-
const span =
|
|
79
|
+
const span = import_tracing.tracer.startSpan(`invoke_agent ${this.name}`);
|
|
80
|
+
const ctx = import_api.trace.setSpan(import_api.context.active(), span);
|
|
73
81
|
try {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
82
|
+
yield* (0, import_tracing.runAsyncGeneratorWithOtelContext)(
|
|
83
|
+
ctx,
|
|
84
|
+
this,
|
|
85
|
+
async function* () {
|
|
86
|
+
const context2 = this.createInvocationContext(parentContext);
|
|
87
|
+
const beforeAgentCallbackEvent = await this.handleBeforeAgentCallback(context2);
|
|
88
|
+
if (beforeAgentCallbackEvent) {
|
|
89
|
+
yield beforeAgentCallbackEvent;
|
|
90
|
+
}
|
|
91
|
+
if (context2.endInvocation) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
(0, import_tracing.traceAgentInvocation)({ agent: this, invocationContext: context2 });
|
|
95
|
+
for await (const event of this.runAsyncImpl(context2)) {
|
|
96
|
+
yield event;
|
|
97
|
+
}
|
|
98
|
+
if (context2.endInvocation) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const afterAgentCallbackEvent = await this.handleAfterAgentCallback(context2);
|
|
102
|
+
if (afterAgentCallbackEvent) {
|
|
103
|
+
yield afterAgentCallbackEvent;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
);
|
|
92
107
|
} finally {
|
|
93
108
|
span.end();
|
|
94
109
|
}
|
|
@@ -101,8 +116,15 @@ class BaseAgent {
|
|
|
101
116
|
* @returns An AsyncGenerator that yields the events generated by the agent.
|
|
102
117
|
*/
|
|
103
118
|
async *runLive(parentContext) {
|
|
104
|
-
const span =
|
|
119
|
+
const span = import_tracing.tracer.startSpan(`invoke_agent ${this.name}`);
|
|
120
|
+
const ctx = import_api.trace.setSpan(import_api.context.active(), span);
|
|
105
121
|
try {
|
|
122
|
+
yield* (0, import_tracing.runAsyncGeneratorWithOtelContext)(
|
|
123
|
+
ctx,
|
|
124
|
+
this,
|
|
125
|
+
async function* () {
|
|
126
|
+
}
|
|
127
|
+
);
|
|
106
128
|
throw new Error("Live mode is not implemented yet.");
|
|
107
129
|
} finally {
|
|
108
130
|
span.end();
|
|
@@ -230,7 +252,7 @@ class BaseAgent {
|
|
|
230
252
|
function validateAgentName(name) {
|
|
231
253
|
if (!isIdentifier(name)) {
|
|
232
254
|
throw new Error(
|
|
233
|
-
`Found invalid agent name: "${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
|
|
255
|
+
`Found invalid agent name: "${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.`
|
|
234
256
|
);
|
|
235
257
|
}
|
|
236
258
|
if (name === "user") {
|
|
@@ -241,7 +263,7 @@ function validateAgentName(name) {
|
|
|
241
263
|
return name;
|
|
242
264
|
}
|
|
243
265
|
function isIdentifier(str) {
|
|
244
|
-
return /^[\p{ID_Start}$_][\p{ID_Continue}$_]*$/u.test(str);
|
|
266
|
+
return /^[\p{ID_Start}$_][\p{ID_Continue}$_-]*$/u.test(str);
|
|
245
267
|
}
|
|
246
268
|
function getRootAgent(rootAgent) {
|
|
247
269
|
while (rootAgent.parentAgent) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -36,7 +36,10 @@ var import_readonly_context = require("./readonly_context.js");
|
|
|
36
36
|
* SPDX-License-Identifier: Apache-2.0
|
|
37
37
|
*/
|
|
38
38
|
class CallbackContext extends import_readonly_context.ReadonlyContext {
|
|
39
|
-
constructor({
|
|
39
|
+
constructor({
|
|
40
|
+
invocationContext,
|
|
41
|
+
eventActions
|
|
42
|
+
}) {
|
|
40
43
|
super(invocationContext);
|
|
41
44
|
this.eventActions = eventActions || (0, import_event_actions.createEventActions)();
|
|
42
45
|
this._state = new import_state.State(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -109,9 +109,11 @@ function convertForeignEvent(event) {
|
|
|
109
109
|
}
|
|
110
110
|
const content = {
|
|
111
111
|
role: "user",
|
|
112
|
-
parts: [
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
parts: [
|
|
113
|
+
{
|
|
114
|
+
text: "For context:"
|
|
115
|
+
}
|
|
116
|
+
]
|
|
115
117
|
};
|
|
116
118
|
for (const part of event.content.parts) {
|
|
117
119
|
if (part.text && !part.thought) {
|
|
@@ -213,10 +215,14 @@ function rearrangeEventsForLatestFunctionResponse(events) {
|
|
|
213
215
|
const functionCallIds = new Set(
|
|
214
216
|
functionCalls.map((fc) => fc.id).filter((id) => !!id)
|
|
215
217
|
);
|
|
216
|
-
const isSubset = Array.from(functionResponsesIds).every(
|
|
218
|
+
const isSubset = Array.from(functionResponsesIds).every(
|
|
219
|
+
(id) => functionCallIds.has(id)
|
|
220
|
+
);
|
|
217
221
|
if (!isSubset) {
|
|
218
222
|
throw new Error(
|
|
219
|
-
`Last response event should only contain the responses for the function calls in the same function call event. Function call ids found : ${Array.from(functionCallIds).join(
|
|
223
|
+
`Last response event should only contain the responses for the function calls in the same function call event. Function call ids found : ${Array.from(functionCallIds).join(
|
|
224
|
+
", "
|
|
225
|
+
)}, function response ids provided: ${Array.from(functionResponsesIds).join(", ")}`
|
|
220
226
|
);
|
|
221
227
|
}
|
|
222
228
|
functionResponsesIds = functionCallIds;
|
|
@@ -284,7 +290,9 @@ function rearrangeEventsForAsyncFunctionResponsesInHistory(events) {
|
|
|
284
290
|
const [responseIndex] = [...functionResponseEventsIndices];
|
|
285
291
|
resultEvents.push(events[responseIndex]);
|
|
286
292
|
} else {
|
|
287
|
-
const indicesArray = Array.from(functionResponseEventsIndices).sort(
|
|
293
|
+
const indicesArray = Array.from(functionResponseEventsIndices).sort(
|
|
294
|
+
(a, b) => a - b
|
|
295
|
+
);
|
|
288
296
|
const eventsToMerge = indicesArray.map((index) => events[index]);
|
|
289
297
|
resultEvents.push(mergeFunctionResponseEvents(eventsToMerge));
|
|
290
298
|
}
|
|
@@ -300,7 +308,7 @@ function safeStringify(obj) {
|
|
|
300
308
|
}
|
|
301
309
|
try {
|
|
302
310
|
return JSON.stringify(obj);
|
|
303
|
-
} catch (
|
|
311
|
+
} catch (_e) {
|
|
304
312
|
return String(obj);
|
|
305
313
|
}
|
|
306
314
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -45,6 +45,7 @@ var import_event_actions = require("../events/event_actions.js");
|
|
|
45
45
|
var import_tool_context = require("../tools/tool_context.js");
|
|
46
46
|
var import_env_aware_utils = require("../utils/env_aware_utils.js");
|
|
47
47
|
var import_logger = require("../utils/logger.js");
|
|
48
|
+
var import_tracing = require("../telemetry/tracing.js");
|
|
48
49
|
/**
|
|
49
50
|
* @license
|
|
50
51
|
* Copyright 2025 Google LLC
|
|
@@ -163,12 +164,56 @@ function generateRequestConfirmationEvent({
|
|
|
163
164
|
parts,
|
|
164
165
|
role: functionResponseEvent.content.role
|
|
165
166
|
},
|
|
167
|
+
actions: functionResponseEvent.actions,
|
|
166
168
|
longRunningToolIds: Array.from(longRunningToolIds)
|
|
167
169
|
});
|
|
168
170
|
}
|
|
169
171
|
async function callToolAsync(tool, args, toolContext) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
+
return import_tracing.tracer.startActiveSpan(`execute_tool ${tool.name}`, async (span) => {
|
|
173
|
+
try {
|
|
174
|
+
import_logger.logger.debug(`callToolAsync ${tool.name}`);
|
|
175
|
+
const result = await tool.runAsync({ args, toolContext });
|
|
176
|
+
(0, import_tracing.traceToolCall)({
|
|
177
|
+
tool,
|
|
178
|
+
args,
|
|
179
|
+
functionResponseEvent: buildResponseEvent(
|
|
180
|
+
tool,
|
|
181
|
+
result,
|
|
182
|
+
toolContext,
|
|
183
|
+
toolContext.invocationContext
|
|
184
|
+
)
|
|
185
|
+
});
|
|
186
|
+
return result;
|
|
187
|
+
} finally {
|
|
188
|
+
span.end();
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function buildResponseEvent(tool, functionResult, toolContext, invocationContext) {
|
|
193
|
+
let responseResult;
|
|
194
|
+
if (typeof functionResult !== "object" || functionResult == null) {
|
|
195
|
+
responseResult = { result: functionResult };
|
|
196
|
+
} else {
|
|
197
|
+
responseResult = functionResult;
|
|
198
|
+
}
|
|
199
|
+
const partFunctionResponse = {
|
|
200
|
+
functionResponse: {
|
|
201
|
+
name: tool.name,
|
|
202
|
+
response: responseResult,
|
|
203
|
+
id: toolContext.functionCallId
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
const content = {
|
|
207
|
+
role: "user",
|
|
208
|
+
parts: [partFunctionResponse]
|
|
209
|
+
};
|
|
210
|
+
return (0, import_event.createEvent)({
|
|
211
|
+
invocationId: invocationContext.invocationId,
|
|
212
|
+
author: invocationContext.agent.name,
|
|
213
|
+
content,
|
|
214
|
+
actions: toolContext.actions,
|
|
215
|
+
branch: invocationContext.branch
|
|
216
|
+
});
|
|
172
217
|
}
|
|
173
218
|
async function handleFunctionCallsAsync({
|
|
174
219
|
invocationContext,
|
|
@@ -209,14 +254,12 @@ async function handleFunctionCallList({
|
|
|
209
254
|
if (toolConfirmationDict && functionCall.id) {
|
|
210
255
|
toolConfirmation = toolConfirmationDict[functionCall.id];
|
|
211
256
|
}
|
|
212
|
-
const { tool, toolContext } = getToolAndContext(
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
);
|
|
257
|
+
const { tool, toolContext } = getToolAndContext({
|
|
258
|
+
invocationContext,
|
|
259
|
+
functionCall,
|
|
260
|
+
toolsDict,
|
|
261
|
+
toolConfirmation
|
|
262
|
+
});
|
|
220
263
|
import_logger.logger.debug(`execute_tool ${tool.name}`);
|
|
221
264
|
const functionArgs = (_a = functionCall.args) != null ? _a : {};
|
|
222
265
|
let functionResponse = null;
|
|
@@ -240,21 +283,15 @@ async function handleFunctionCallList({
|
|
|
240
283
|
}
|
|
241
284
|
if (functionResponse == null) {
|
|
242
285
|
try {
|
|
243
|
-
functionResponse = await callToolAsync(
|
|
244
|
-
tool,
|
|
245
|
-
functionArgs,
|
|
246
|
-
toolContext
|
|
247
|
-
);
|
|
286
|
+
functionResponse = await callToolAsync(tool, functionArgs, toolContext);
|
|
248
287
|
} catch (e) {
|
|
249
288
|
if (e instanceof Error) {
|
|
250
|
-
const onToolErrorResponse = await invocationContext.pluginManager.runOnToolErrorCallback(
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
);
|
|
289
|
+
const onToolErrorResponse = await invocationContext.pluginManager.runOnToolErrorCallback({
|
|
290
|
+
tool,
|
|
291
|
+
toolArgs: functionArgs,
|
|
292
|
+
toolContext,
|
|
293
|
+
error: e
|
|
294
|
+
});
|
|
258
295
|
if (onToolErrorResponse) {
|
|
259
296
|
functionResponse = onToolErrorResponse;
|
|
260
297
|
} else {
|
|
@@ -318,12 +355,24 @@ async function handleFunctionCallList({
|
|
|
318
355
|
if (!functionResponseEvents.length) {
|
|
319
356
|
return null;
|
|
320
357
|
}
|
|
321
|
-
const mergedEvent = mergeParallelFunctionResponseEvents(
|
|
358
|
+
const mergedEvent = mergeParallelFunctionResponseEvents(
|
|
359
|
+
functionResponseEvents
|
|
360
|
+
);
|
|
322
361
|
if (functionResponseEvents.length > 1) {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
362
|
+
import_tracing.tracer.startActiveSpan("execute_tool (merged)", (span) => {
|
|
363
|
+
try {
|
|
364
|
+
import_logger.logger.debug("execute_tool (merged)");
|
|
365
|
+
import_logger.logger.debug("traceMergedToolCalls", {
|
|
366
|
+
responseEventId: mergedEvent.id,
|
|
367
|
+
functionResponseEvent: mergedEvent.id
|
|
368
|
+
});
|
|
369
|
+
(0, import_tracing.traceMergedToolCalls)({
|
|
370
|
+
responseEventId: mergedEvent.id,
|
|
371
|
+
functionResponseEvent: mergedEvent
|
|
372
|
+
});
|
|
373
|
+
} finally {
|
|
374
|
+
span.end();
|
|
375
|
+
}
|
|
327
376
|
});
|
|
328
377
|
}
|
|
329
378
|
return mergedEvent;
|
|
@@ -361,7 +410,9 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
|
|
|
361
410
|
}
|
|
362
411
|
}
|
|
363
412
|
const baseEvent = functionResponseEvents[0];
|
|
364
|
-
const actionsList = functionResponseEvents.map(
|
|
413
|
+
const actionsList = functionResponseEvents.map(
|
|
414
|
+
(event) => event.actions || {}
|
|
415
|
+
);
|
|
365
416
|
const mergedActions = (0, import_event_actions.mergeEventActions)(actionsList);
|
|
366
417
|
return (0, import_event.createEvent)({
|
|
367
418
|
author: baseEvent.author,
|