@google/adk 0.3.0 → 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 +3 -3
- package/dist/cjs/agents/base_llm_processor.js +1 -1
- package/dist/cjs/agents/callback_context.js +1 -1
- package/dist/cjs/agents/content_processor_utils.js +1 -1
- package/dist/cjs/agents/functions.js +2 -1
- 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 +58 -40
- package/dist/cjs/agents/loop_agent.js +1 -1
- package/dist/cjs/agents/parallel_agent.js +1 -1
- 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 +127 -48
- package/dist/cjs/artifacts/in_memory_artifact_service.js +54 -6
- package/dist/cjs/artifacts/registry.js +55 -0
- package/dist/cjs/auth/auth_credential.js +1 -1
- package/dist/cjs/auth/auth_handler.js +1 -1
- 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 +1 -1
- package/dist/cjs/code_executors/built_in_code_executor.js +1 -1
- package/dist/cjs/code_executors/code_execution_utils.js +1 -1
- package/dist/cjs/code_executors/code_executor_context.js +1 -1
- package/dist/cjs/common.js +14 -1
- package/dist/cjs/events/event.js +33 -4
- 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 +1 -1
- 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 +1 -1
- package/dist/cjs/models/base_llm_connection.js +1 -1
- package/dist/cjs/models/gemini_llm_connection.js +1 -1
- package/dist/cjs/models/google_llm.js +70 -51
- 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 +1 -1
- package/dist/cjs/plugins/logging_plugin.js +1 -1
- package/dist/cjs/plugins/plugin_manager.js +1 -1
- package/dist/cjs/plugins/security_plugin.js +1 -1
- package/dist/cjs/runner/in_memory_runner.js +1 -1
- package/dist/cjs/runner/runner.js +32 -1
- 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 +24 -22
- 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 +1 -1
- package/dist/cjs/telemetry/setup.js +1 -1
- package/dist/cjs/telemetry/tracing.js +1 -1
- package/dist/cjs/tools/agent_tool.js +1 -1
- package/dist/cjs/tools/base_tool.js +1 -1
- package/dist/cjs/tools/base_toolset.js +1 -1
- package/dist/cjs/tools/forwarding_artifact_service.js +17 -1
- package/dist/cjs/tools/function_tool.js +1 -1
- package/dist/cjs/tools/google_search_tool.js +1 -1
- package/dist/cjs/tools/long_running_tool.js +1 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +1 -1
- package/dist/cjs/tools/mcp/mcp_tool.js +1 -1
- package/dist/cjs/tools/mcp/mcp_toolset.js +1 -1
- 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 +10 -1
- package/dist/cjs/utils/gemini_schema_util.js +1 -1
- package/dist/cjs/utils/logger.js +1 -1
- 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 +1 -1
- 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 +2 -2
- package/dist/esm/agents/functions.js +1 -0
- package/dist/esm/agents/llm_agent.js +58 -40
- 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 +126 -47
- package/dist/esm/artifacts/in_memory_artifact_service.js +51 -4
- package/dist/esm/artifacts/registry.js +28 -0
- package/dist/esm/common.js +9 -1
- package/dist/esm/events/event.js +29 -2
- 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/models/apigee_llm.js +152 -0
- package/dist/esm/models/google_llm.js +67 -49
- package/dist/esm/models/registry.js +2 -0
- package/dist/esm/runner/runner.js +31 -0
- 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 +23 -21
- package/dist/esm/sessions/registry.js +25 -0
- package/dist/esm/tools/forwarding_artifact_service.js +16 -0
- package/dist/esm/utils/env_aware_utils.js +8 -0
- package/dist/esm/utils/object_notation_utils.js +47 -0
- 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/llm_agent.d.ts +11 -11
- 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 +5 -2
- package/dist/types/artifacts/registry.d.ts +7 -0
- package/dist/types/common.d.ts +11 -2
- 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 +5 -1
- package/dist/types/models/apigee_llm.d.ts +59 -0
- package/dist/types/models/google_llm.d.ts +5 -2
- package/dist/types/runner/runner.d.ts +15 -0
- 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 +4 -1
- package/dist/types/sessions/registry.d.ts +7 -0
- package/dist/types/tools/forwarding_artifact_service.d.ts +3 -1
- package/dist/types/utils/env_aware_utils.d.ts +7 -0
- package/dist/types/utils/object_notation_utils.d.ts +21 -0
- 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 +2 -2
- package/dist/web/agents/functions.js +1 -0
- package/dist/web/agents/llm_agent.js +79 -59
- 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 +123 -46
- package/dist/web/artifacts/in_memory_artifact_service.js +51 -4
- package/dist/web/artifacts/registry.js +28 -0
- package/dist/web/common.js +9 -1
- package/dist/web/events/event.js +29 -2
- 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/models/apigee_llm.js +219 -0
- package/dist/web/models/google_llm.js +67 -46
- package/dist/web/models/registry.js +2 -0
- package/dist/web/runner/runner.js +33 -0
- 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 +23 -21
- package/dist/web/sessions/registry.js +25 -0
- package/dist/web/tools/forwarding_artifact_service.js +16 -0
- package/dist/web/utils/env_aware_utils.js +8 -0
- package/dist/web/utils/object_notation_utils.js +47 -0
- package/dist/web/utils/variant_utils.js +1 -7
- package/dist/web/version.js +1 -1
- package/package.json +13 -4
- 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,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: ${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: ${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: ${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: ${JSON.stringify(a2aPart)}`);
|
|
136
|
+
}
|
|
137
|
+
function toGenAIPartData(a2aPart) {
|
|
138
|
+
var _a;
|
|
139
|
+
if (!a2aPart.data) {
|
|
140
|
+
throw new Error(`No data in part: ${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
|
+
};
|
|
@@ -225,7 +225,7 @@ class BaseAgent {
|
|
|
225
225
|
function validateAgentName(name) {
|
|
226
226
|
if (!isIdentifier(name)) {
|
|
227
227
|
throw new Error(
|
|
228
|
-
`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
|
|
228
|
+
`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.`
|
|
229
229
|
);
|
|
230
230
|
}
|
|
231
231
|
if (name === "user") {
|
|
@@ -236,7 +236,7 @@ function validateAgentName(name) {
|
|
|
236
236
|
return name;
|
|
237
237
|
}
|
|
238
238
|
function isIdentifier(str) {
|
|
239
|
-
return /^[\p{ID_Start}$_][\p{ID_Continue}$_]*$/u.test(str);
|
|
239
|
+
return /^[\p{ID_Start}$_][\p{ID_Continue}$_-]*$/u.test(str);
|
|
240
240
|
}
|
|
241
241
|
function getRootAgent(rootAgent) {
|
|
242
242
|
while (rootAgent.parentAgent) {
|
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
} from "../models/llm_request.js";
|
|
34
34
|
import { LLMRegistry } from "../models/registry.js";
|
|
35
35
|
import { State } from "../sessions/state.js";
|
|
36
|
-
import {
|
|
36
|
+
import { isBaseTool } from "../tools/base_tool.js";
|
|
37
37
|
import { FunctionTool } from "../tools/function_tool.js";
|
|
38
38
|
import { ToolConfirmation } from "../tools/tool_confirmation.js";
|
|
39
39
|
import { ToolContext } from "../tools/tool_context.js";
|
|
@@ -44,6 +44,7 @@ import {
|
|
|
44
44
|
traceCallLlm,
|
|
45
45
|
tracer
|
|
46
46
|
} from "../telemetry/tracing.js";
|
|
47
|
+
import { isZodObject, zodObjectToSchema } from "../utils/simple_zod_to_json.js";
|
|
47
48
|
import { BaseAgent } from "./base_agent.js";
|
|
48
49
|
import {
|
|
49
50
|
BaseLlmRequestProcessor
|
|
@@ -67,7 +68,7 @@ import { ReadonlyContext } from "./readonly_context.js";
|
|
|
67
68
|
import { StreamingMode } from "./run_config.js";
|
|
68
69
|
const ADK_AGENT_NAME_LABEL_KEY = "adk_agent_name";
|
|
69
70
|
async function convertToolUnionToTools(toolUnion, context2) {
|
|
70
|
-
if (toolUnion
|
|
71
|
+
if (isBaseTool(toolUnion)) {
|
|
71
72
|
return [toolUnion];
|
|
72
73
|
}
|
|
73
74
|
return await toolUnion.getTools(context2);
|
|
@@ -116,7 +117,7 @@ class InstructionsLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
|
116
117
|
// eslint-disable-next-line require-yield
|
|
117
118
|
async *runAsync(invocationContext, llmRequest) {
|
|
118
119
|
const agent = invocationContext.agent;
|
|
119
|
-
if (!(agent
|
|
120
|
+
if (!isLlmAgent(agent) || !isLlmAgent(agent.rootAgent)) {
|
|
120
121
|
return;
|
|
121
122
|
}
|
|
122
123
|
const rootAgent = agent.rootAgent;
|
|
@@ -194,7 +195,7 @@ class AgentTransferLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
|
194
195
|
}
|
|
195
196
|
// eslint-disable-next-line require-yield
|
|
196
197
|
async *runAsync(invocationContext, llmRequest) {
|
|
197
|
-
if (!(invocationContext.agent
|
|
198
|
+
if (!isLlmAgent(invocationContext.agent)) {
|
|
198
199
|
return;
|
|
199
200
|
}
|
|
200
201
|
const transferTargets = this.getTransferTargets(invocationContext.agent);
|
|
@@ -380,7 +381,7 @@ class RequestConfirmationLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
|
380
381
|
const REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR = new RequestConfirmationLlmRequestProcessor();
|
|
381
382
|
class CodeExecutionRequestProcessor extends BaseLlmRequestProcessor {
|
|
382
383
|
async *runAsync(invocationContext, llmRequest) {
|
|
383
|
-
if (!(invocationContext.agent
|
|
384
|
+
if (!isLlmAgent(invocationContext.agent)) {
|
|
384
385
|
return;
|
|
385
386
|
}
|
|
386
387
|
if (!invocationContext.agent.codeExecutor) {
|
|
@@ -730,8 +731,8 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
730
731
|
this.disallowTransferToParent = (_d = config.disallowTransferToParent) != null ? _d : false;
|
|
731
732
|
this.disallowTransferToPeers = (_e = config.disallowTransferToPeers) != null ? _e : false;
|
|
732
733
|
this.includeContents = (_f = config.includeContents) != null ? _f : "default";
|
|
733
|
-
this.inputSchema = config.inputSchema;
|
|
734
|
-
this.outputSchema = config.outputSchema;
|
|
734
|
+
this.inputSchema = isZodObject(config.inputSchema) ? zodObjectToSchema(config.inputSchema) : config.inputSchema;
|
|
735
|
+
this.outputSchema = isZodObject(config.outputSchema) ? zodObjectToSchema(config.outputSchema) : config.outputSchema;
|
|
735
736
|
this.outputKey = config.outputKey;
|
|
736
737
|
this.beforeModelCallback = config.beforeModelCallback;
|
|
737
738
|
this.afterModelCallback = config.afterModelCallback;
|
|
@@ -776,16 +777,6 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
776
777
|
this.disallowTransferToParent = true;
|
|
777
778
|
this.disallowTransferToPeers = true;
|
|
778
779
|
}
|
|
779
|
-
if (this.subAgents && this.subAgents.length > 0) {
|
|
780
|
-
throw new Error(
|
|
781
|
-
`Invalid config for agent ${this.name}: if outputSchema is set, subAgents must be empty to disable agent transfer.`
|
|
782
|
-
);
|
|
783
|
-
}
|
|
784
|
-
if (this.tools && this.tools.length > 0) {
|
|
785
|
-
throw new Error(
|
|
786
|
-
`Invalid config for agent ${this.name}: if outputSchema is set, tools must be empty`
|
|
787
|
-
);
|
|
788
|
-
}
|
|
789
780
|
}
|
|
790
781
|
}
|
|
791
782
|
/**
|
|
@@ -1029,28 +1020,36 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
1029
1020
|
ctx,
|
|
1030
1021
|
this,
|
|
1031
1022
|
async function* () {
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
llmRequest,
|
|
1035
|
-
modelResponseEvent
|
|
1036
|
-
)) {
|
|
1037
|
-
for await (const event of this.postprocess(
|
|
1023
|
+
const responsesGenerator = async function* () {
|
|
1024
|
+
for await (const llmResponse of this.callLlmAsync(
|
|
1038
1025
|
invocationContext,
|
|
1039
1026
|
llmRequest,
|
|
1040
|
-
llmResponse,
|
|
1041
1027
|
modelResponseEvent
|
|
1042
1028
|
)) {
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1029
|
+
for await (const event of this.postprocess(
|
|
1030
|
+
invocationContext,
|
|
1031
|
+
llmRequest,
|
|
1032
|
+
llmResponse,
|
|
1033
|
+
modelResponseEvent
|
|
1034
|
+
)) {
|
|
1035
|
+
modelResponseEvent.id = createNewEventId();
|
|
1036
|
+
modelResponseEvent.timestamp = (/* @__PURE__ */ new Date()).getTime();
|
|
1037
|
+
yield event;
|
|
1038
|
+
}
|
|
1046
1039
|
}
|
|
1047
|
-
}
|
|
1040
|
+
};
|
|
1041
|
+
yield* this.runAndHandleError(
|
|
1042
|
+
responsesGenerator.call(this),
|
|
1043
|
+
invocationContext,
|
|
1044
|
+
llmRequest,
|
|
1045
|
+
modelResponseEvent
|
|
1046
|
+
);
|
|
1048
1047
|
}
|
|
1049
1048
|
);
|
|
1050
1049
|
span.end();
|
|
1051
1050
|
}
|
|
1052
1051
|
async *postprocess(invocationContext, llmRequest, llmResponse, modelResponseEvent) {
|
|
1053
|
-
var _a2;
|
|
1052
|
+
var _a2, _b2;
|
|
1054
1053
|
for (const processor of this.responseProcessors) {
|
|
1055
1054
|
for await (const event of processor.runAsync(
|
|
1056
1055
|
invocationContext,
|
|
@@ -1079,6 +1078,10 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
1079
1078
|
if (!((_a2 = getFunctionCalls(mergedEvent)) == null ? void 0 : _a2.length)) {
|
|
1080
1079
|
return;
|
|
1081
1080
|
}
|
|
1081
|
+
if ((_b2 = invocationContext.runConfig) == null ? void 0 : _b2.pauseOnToolCalls) {
|
|
1082
|
+
invocationContext.endInvocation = true;
|
|
1083
|
+
return;
|
|
1084
|
+
}
|
|
1082
1085
|
const functionResponseEvent = await handleFunctionCallsAsync({
|
|
1083
1086
|
invocationContext,
|
|
1084
1087
|
functionCallEvent: mergedEvent,
|
|
@@ -1103,6 +1106,8 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
1103
1106
|
});
|
|
1104
1107
|
if (toolConfirmationEvent) {
|
|
1105
1108
|
yield toolConfirmationEvent;
|
|
1109
|
+
invocationContext.endInvocation = true;
|
|
1110
|
+
return;
|
|
1106
1111
|
}
|
|
1107
1112
|
yield functionResponseEvent;
|
|
1108
1113
|
const nextAgentName = functionResponseEvent.actions.transferToAgent;
|
|
@@ -1159,12 +1164,7 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
1159
1164
|
/* stream= */
|
|
1160
1165
|
((_e = invocationContext.runConfig) == null ? void 0 : _e.streamingMode) === StreamingMode.SSE
|
|
1161
1166
|
);
|
|
1162
|
-
for await (const llmResponse of
|
|
1163
|
-
responsesGenerator,
|
|
1164
|
-
invocationContext,
|
|
1165
|
-
llmRequest,
|
|
1166
|
-
modelResponseEvent
|
|
1167
|
-
)) {
|
|
1167
|
+
for await (const llmResponse of responsesGenerator) {
|
|
1168
1168
|
traceCallLlm({
|
|
1169
1169
|
invocationContext,
|
|
1170
1170
|
eventId: modelResponseEvent.id,
|
|
@@ -1245,11 +1245,29 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
1245
1245
|
if (onModelErrorCallbackResponse) {
|
|
1246
1246
|
yield onModelErrorCallbackResponse;
|
|
1247
1247
|
} else {
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1248
|
+
let errorCode = "UNKNOWN_ERROR";
|
|
1249
|
+
let errorMessage = modelError.message;
|
|
1250
|
+
try {
|
|
1251
|
+
const errorResponse = JSON.parse(modelError.message);
|
|
1252
|
+
if (errorResponse == null ? void 0 : errorResponse.error) {
|
|
1253
|
+
errorCode = String(errorResponse.error.code || "UNKNOWN_ERROR");
|
|
1254
|
+
errorMessage = errorResponse.error.message || errorMessage;
|
|
1255
|
+
}
|
|
1256
|
+
} catch {
|
|
1257
|
+
}
|
|
1258
|
+
if (modelResponseEvent.actions) {
|
|
1259
|
+
yield createEvent({
|
|
1260
|
+
invocationId: invocationContext.invocationId,
|
|
1261
|
+
author: this.name,
|
|
1262
|
+
errorCode,
|
|
1263
|
+
errorMessage
|
|
1264
|
+
});
|
|
1265
|
+
} else {
|
|
1266
|
+
yield {
|
|
1267
|
+
errorCode,
|
|
1268
|
+
errorMessage
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1253
1271
|
}
|
|
1254
1272
|
} else {
|
|
1255
1273
|
logger.error("Unknown error during response generation", modelError);
|
|
@@ -20,6 +20,18 @@ class ReadonlyContext {
|
|
|
20
20
|
get invocationId() {
|
|
21
21
|
return this.invocationContext.invocationId;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* The user ID of the current session.
|
|
25
|
+
*/
|
|
26
|
+
get userId() {
|
|
27
|
+
return this.invocationContext.userId;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The ID of the current session.
|
|
31
|
+
*/
|
|
32
|
+
get sessionId() {
|
|
33
|
+
return this.invocationContext.session.id;
|
|
34
|
+
}
|
|
23
35
|
/**
|
|
24
36
|
* The current agent name.
|
|
25
37
|
*/
|