@google/adk 0.5.0 → 0.6.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/README.md +1 -1
- package/dist/cjs/a2a/a2a_event.js +53 -26
- package/dist/cjs/a2a/a2a_remote_agent.js +174 -0
- package/dist/cjs/a2a/a2a_remote_agent_run_processor.js +198 -0
- package/dist/cjs/a2a/a2a_remote_agent_utils.js +165 -0
- package/dist/cjs/a2a/agent_card.js +380 -0
- package/dist/cjs/a2a/agent_executor.js +221 -0
- package/dist/cjs/a2a/agent_to_a2a.js +115 -0
- package/dist/cjs/a2a/event_processor_utils.js +180 -0
- package/dist/cjs/a2a/executor_context.js +1 -1
- package/dist/cjs/a2a/metadata_converter_utils.js +1 -0
- package/dist/cjs/a2a/part_converter_utils.js +24 -13
- package/dist/cjs/agents/llm_agent.js +17 -0
- package/dist/cjs/agents/{content_processor_utils.js → processors/content_processor_utils.js} +21 -2
- package/dist/cjs/agents/processors/content_request_processor.js +24 -3
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +61 -0
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/cjs/artifacts/file_artifact_service.js +35 -4
- package/dist/cjs/common.js +37 -0
- package/dist/cjs/context/base_context_compactor.js +27 -0
- package/dist/cjs/context/summarizers/base_summarizer.js +27 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +93 -0
- package/dist/cjs/context/token_based_context_compactor.js +135 -0
- package/dist/cjs/context/truncating_context_compactor.js +58 -0
- package/dist/cjs/events/compacted_event.js +53 -0
- package/dist/cjs/index.js +38 -14
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/memory/in_memory_memory_service.js +1 -1
- package/dist/cjs/runner/runner.js +19 -10
- package/dist/cjs/sessions/db/operations.js +4 -14
- package/dist/cjs/sessions/state.js +2 -2
- package/dist/cjs/tools/agent_tool.js +6 -5
- package/dist/cjs/tools/load_artifacts_tool.js +188 -0
- package/dist/cjs/tools/load_memory_tool.js +107 -0
- package/dist/cjs/tools/preload_memory_tool.js +109 -0
- package/dist/cjs/utils/logger.js +1 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_event.js +52 -26
- package/dist/esm/a2a/a2a_remote_agent.js +148 -0
- package/dist/esm/a2a/a2a_remote_agent_run_processor.js +175 -0
- package/dist/esm/a2a/a2a_remote_agent_utils.js +131 -0
- package/dist/esm/a2a/agent_card.js +340 -0
- package/dist/esm/a2a/agent_executor.js +202 -0
- package/dist/esm/a2a/agent_to_a2a.js +80 -0
- package/dist/esm/a2a/event_processor_utils.js +159 -0
- package/dist/esm/a2a/executor_context.js +1 -1
- package/dist/esm/a2a/metadata_converter_utils.js +1 -0
- package/dist/esm/a2a/part_converter_utils.js +24 -13
- package/dist/esm/agents/llm_agent.js +17 -0
- package/dist/esm/agents/{content_processor_utils.js → processors/content_processor_utils.js} +23 -2
- package/dist/esm/agents/processors/content_request_processor.js +25 -4
- package/dist/esm/agents/processors/context_compactor_request_processor.js +31 -0
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/esm/artifacts/file_artifact_service.js +30 -3
- package/dist/esm/common.js +33 -1
- package/dist/esm/context/base_context_compactor.js +5 -0
- package/dist/esm/context/summarizers/base_summarizer.js +5 -0
- package/dist/esm/context/summarizers/llm_summarizer.js +65 -0
- package/dist/esm/context/token_based_context_compactor.js +105 -0
- package/dist/esm/context/truncating_context_compactor.js +28 -0
- package/dist/esm/events/compacted_event.js +22 -0
- package/dist/esm/index.js +38 -14
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/memory/in_memory_memory_service.js +1 -1
- package/dist/esm/runner/runner.js +17 -9
- package/dist/esm/sessions/db/operations.js +4 -14
- package/dist/esm/sessions/state.js +2 -2
- package/dist/esm/tools/agent_tool.js +6 -5
- package/dist/esm/tools/load_artifacts_tool.js +159 -0
- package/dist/esm/tools/load_memory_tool.js +78 -0
- package/dist/esm/tools/preload_memory_tool.js +80 -0
- package/dist/esm/utils/logger.js +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_event.d.ts +23 -6
- package/dist/types/a2a/a2a_remote_agent.d.ts +63 -0
- package/dist/types/a2a/a2a_remote_agent_run_processor.d.ts +31 -0
- package/dist/types/a2a/a2a_remote_agent_utils.d.ts +38 -0
- package/dist/types/a2a/agent_card.d.ts +23 -0
- package/dist/types/a2a/agent_executor.d.ts +52 -0
- package/dist/types/a2a/agent_to_a2a.d.ts +45 -0
- package/dist/types/a2a/event_processor_utils.d.ts +24 -0
- package/dist/types/a2a/executor_context.d.ts +1 -1
- package/dist/types/a2a/metadata_converter_utils.d.ts +2 -1
- package/dist/types/agents/llm_agent.d.ts +6 -0
- package/dist/types/agents/loop_agent.d.ts +1 -1
- package/dist/types/agents/{content_processor_utils.d.ts → processors/content_processor_utils.d.ts} +1 -1
- package/dist/types/agents/processors/context_compactor_request_processor.d.ts +22 -0
- package/dist/types/artifacts/file_artifact_service.d.ts +4 -0
- package/dist/types/common.d.ts +16 -1
- package/dist/types/context/base_context_compactor.d.ts +24 -0
- package/dist/types/context/summarizers/base_summarizer.d.ts +19 -0
- package/dist/types/context/summarizers/llm_summarizer.d.ts +23 -0
- package/dist/types/context/token_based_context_compactor.d.ts +33 -0
- package/dist/types/context/truncating_context_compactor.d.ts +24 -0
- package/dist/types/events/compacted_event.d.ts +33 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/runner/runner.d.ts +13 -0
- package/dist/types/sessions/db/operations.d.ts +2 -3
- package/dist/types/tools/load_artifacts_tool.d.ts +21 -0
- package/dist/types/tools/load_memory_tool.d.ts +22 -0
- package/dist/types/tools/preload_memory_tool.d.ts +23 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/a2a_event.js +52 -26
- package/dist/web/a2a/a2a_remote_agent.js +193 -0
- package/dist/web/a2a/a2a_remote_agent_run_processor.js +175 -0
- package/dist/web/a2a/a2a_remote_agent_utils.js +131 -0
- package/dist/web/a2a/agent_card.js +340 -0
- package/dist/web/a2a/agent_executor.js +216 -0
- package/dist/web/a2a/agent_to_a2a.js +80 -0
- package/dist/web/a2a/event_processor_utils.js +168 -0
- package/dist/web/a2a/executor_context.js +1 -1
- package/dist/web/a2a/metadata_converter_utils.js +1 -0
- package/dist/web/a2a/part_converter_utils.js +24 -13
- package/dist/web/agents/llm_agent.js +17 -0
- package/dist/web/agents/{content_processor_utils.js → processors/content_processor_utils.js} +22 -2
- package/dist/web/agents/processors/content_request_processor.js +25 -4
- package/dist/web/agents/processors/context_compactor_request_processor.js +49 -0
- package/dist/web/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/web/artifacts/file_artifact_service.js +30 -3
- package/dist/web/common.js +33 -1
- package/dist/web/context/base_context_compactor.js +5 -0
- package/dist/web/context/summarizers/base_summarizer.js +5 -0
- package/dist/web/context/summarizers/llm_summarizer.js +74 -0
- package/dist/web/context/token_based_context_compactor.js +105 -0
- package/dist/web/context/truncating_context_compactor.js +28 -0
- package/dist/web/events/compacted_event.js +40 -0
- package/dist/web/index.js +1 -1
- package/dist/web/index.js.map +4 -4
- package/dist/web/memory/in_memory_memory_service.js +1 -1
- package/dist/web/runner/runner.js +17 -9
- package/dist/web/sessions/db/operations.js +4 -14
- package/dist/web/sessions/state.js +2 -2
- package/dist/web/tools/agent_tool.js +6 -5
- package/dist/web/tools/load_artifacts_tool.js +150 -0
- package/dist/web/tools/load_memory_tool.js +77 -0
- package/dist/web/tools/preload_memory_tool.js +75 -0
- package/dist/web/utils/logger.js +1 -0
- package/dist/web/version.js +1 -1
- package/package.json +6 -4
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
/**
|
|
21
|
+
* @license
|
|
22
|
+
* Copyright 2026 Google LLC
|
|
23
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
24
|
+
*/
|
|
25
|
+
import { createEventActions } from "../events/event_actions.js";
|
|
26
|
+
import {
|
|
27
|
+
createInputMissingErrorEvent,
|
|
28
|
+
createTaskCompletedEvent,
|
|
29
|
+
createTaskFailedEvent,
|
|
30
|
+
createTaskInputRequiredEvent,
|
|
31
|
+
isInputRequiredTaskStatusUpdateEvent
|
|
32
|
+
} from "./a2a_event.js";
|
|
33
|
+
import {
|
|
34
|
+
getA2AEventMetadata,
|
|
35
|
+
getA2AEventMetadataFromActions,
|
|
36
|
+
getA2ASessionMetadata
|
|
37
|
+
} from "./metadata_converter_utils.js";
|
|
38
|
+
import { toA2AParts, toGenAIParts } from "./part_converter_utils.js";
|
|
39
|
+
function getFinalTaskStatusUpdate(adkEvents, context) {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
const finalEventActions = createEventActions();
|
|
42
|
+
for (const adkEvent of adkEvents) {
|
|
43
|
+
if (adkEvent.errorCode || adkEvent.errorMessage) {
|
|
44
|
+
return createTaskFailedEvent({
|
|
45
|
+
taskId: context.requestContext.taskId,
|
|
46
|
+
contextId: context.requestContext.contextId,
|
|
47
|
+
error: new Error(adkEvent.errorMessage || adkEvent.errorCode),
|
|
48
|
+
metadata: __spreadValues(__spreadValues({}, getA2AEventMetadata(adkEvent, context)), getA2AEventMetadataFromActions(finalEventActions))
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
finalEventActions.escalate = finalEventActions.escalate || ((_a = adkEvent.actions) == null ? void 0 : _a.escalate);
|
|
52
|
+
if ((_b = adkEvent.actions) == null ? void 0 : _b.transferToAgent) {
|
|
53
|
+
finalEventActions.transferToAgent = adkEvent.actions.transferToAgent;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const inputRequiredEvent = scanForInputRequiredEvents(adkEvents, context);
|
|
57
|
+
if (inputRequiredEvent) {
|
|
58
|
+
return __spreadProps(__spreadValues({}, inputRequiredEvent), {
|
|
59
|
+
metadata: __spreadValues(__spreadValues({}, inputRequiredEvent.metadata), getA2AEventMetadataFromActions(finalEventActions))
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return createTaskCompletedEvent({
|
|
63
|
+
taskId: context.requestContext.taskId,
|
|
64
|
+
contextId: context.requestContext.contextId,
|
|
65
|
+
metadata: __spreadValues(__spreadValues({}, getA2ASessionMetadata(context)), getA2AEventMetadataFromActions(finalEventActions))
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function scanForInputRequiredEvents(adkEvents, context) {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
const inputRequiredParts = [];
|
|
71
|
+
const inputRequiredFunctionCallIds = /* @__PURE__ */ new Set();
|
|
72
|
+
for (const adkEvent of adkEvents) {
|
|
73
|
+
if (!((_b = (_a = adkEvent.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.length)) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
for (const genAIPart of adkEvent.content.parts) {
|
|
77
|
+
const longRunningFunctionCallId = getLongRunnningFunctionCallId(
|
|
78
|
+
genAIPart,
|
|
79
|
+
adkEvent.longRunningToolIds,
|
|
80
|
+
inputRequiredParts
|
|
81
|
+
);
|
|
82
|
+
if (!longRunningFunctionCallId) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const isAlreadyAdded = inputRequiredFunctionCallIds.has(
|
|
86
|
+
longRunningFunctionCallId
|
|
87
|
+
);
|
|
88
|
+
if (isAlreadyAdded) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
inputRequiredParts.push(genAIPart);
|
|
92
|
+
inputRequiredFunctionCallIds.add(longRunningFunctionCallId);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (inputRequiredParts.length > 0) {
|
|
96
|
+
return createTaskInputRequiredEvent({
|
|
97
|
+
taskId: context.requestContext.taskId,
|
|
98
|
+
contextId: context.requestContext.contextId,
|
|
99
|
+
parts: toA2AParts(inputRequiredParts, [...inputRequiredFunctionCallIds]),
|
|
100
|
+
metadata: getA2ASessionMetadata(context)
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return void 0;
|
|
104
|
+
}
|
|
105
|
+
function getLongRunnningFunctionCallId(genAIPart, longRunningToolIds = [], inputRequiredParts = []) {
|
|
106
|
+
var _a, _b, _c;
|
|
107
|
+
const functionCallId = (_a = genAIPart.functionCall) == null ? void 0 : _a.id;
|
|
108
|
+
const functionResponseId = (_b = genAIPart.functionResponse) == null ? void 0 : _b.id;
|
|
109
|
+
if (!functionCallId && !functionResponseId) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (functionCallId && longRunningToolIds.includes(functionCallId)) {
|
|
113
|
+
return functionCallId;
|
|
114
|
+
}
|
|
115
|
+
if (functionResponseId && longRunningToolIds.includes(functionResponseId)) {
|
|
116
|
+
return functionResponseId;
|
|
117
|
+
}
|
|
118
|
+
for (const part of inputRequiredParts) {
|
|
119
|
+
if (((_c = part.functionCall) == null ? void 0 : _c.id) === functionResponseId) {
|
|
120
|
+
return functionResponseId;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
function getTaskInputRequiredEvent(task, genAIContent) {
|
|
126
|
+
var _a;
|
|
127
|
+
if (!task || !isInputRequiredTaskStatusUpdateEvent(task) || !task.status.message) {
|
|
128
|
+
return void 0;
|
|
129
|
+
}
|
|
130
|
+
const statusMsg = task.status.message;
|
|
131
|
+
const taskParts = toGenAIParts(statusMsg.parts);
|
|
132
|
+
for (const taskPart of taskParts) {
|
|
133
|
+
const functionCallId = (_a = taskPart.functionCall) == null ? void 0 : _a.id;
|
|
134
|
+
if (!functionCallId) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const hasMatchingResponse = ((genAIContent == null ? void 0 : genAIContent.parts) || []).some(
|
|
138
|
+
(p) => {
|
|
139
|
+
var _a2;
|
|
140
|
+
return ((_a2 = p.functionResponse) == null ? void 0 : _a2.id) === functionCallId;
|
|
141
|
+
}
|
|
142
|
+
);
|
|
143
|
+
if (!hasMatchingResponse) {
|
|
144
|
+
return createInputMissingErrorEvent({
|
|
145
|
+
taskId: task.id,
|
|
146
|
+
contextId: task.contextId,
|
|
147
|
+
parts: [
|
|
148
|
+
...statusMsg.parts.filter((p) => {
|
|
149
|
+
var _a2;
|
|
150
|
+
return !((_a2 = p.metadata) == null ? void 0 : _a2.validation_error);
|
|
151
|
+
}),
|
|
152
|
+
{
|
|
153
|
+
kind: "text",
|
|
154
|
+
text: "No input provided for function call id ".concat(functionCallId),
|
|
155
|
+
metadata: {
|
|
156
|
+
validation_error: true
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
]
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return void 0;
|
|
164
|
+
}
|
|
165
|
+
export {
|
|
166
|
+
getFinalTaskStatusUpdate,
|
|
167
|
+
getTaskInputRequiredEvent
|
|
168
|
+
};
|
|
@@ -44,6 +44,7 @@ var A2AMetadataKeys = ((A2AMetadataKeys2) => {
|
|
|
44
44
|
A2AMetadataKeys2[A2AMetadataKeys2["GROUNDING_METADATA"] = "".concat(ADK_METADATA_KEY_PREFIX, "grounding_metadata")] = "GROUNDING_METADATA";
|
|
45
45
|
A2AMetadataKeys2[A2AMetadataKeys2["USAGE_METADATA"] = "".concat(ADK_METADATA_KEY_PREFIX, "usage_metadata")] = "USAGE_METADATA";
|
|
46
46
|
A2AMetadataKeys2[A2AMetadataKeys2["CUSTOM_METADATA"] = "".concat(ADK_METADATA_KEY_PREFIX, "custom_metadata")] = "CUSTOM_METADATA";
|
|
47
|
+
A2AMetadataKeys2[A2AMetadataKeys2["VIDEO_METADATA"] = "".concat(ADK_METADATA_KEY_PREFIX, "video_metadata")] = "VIDEO_METADATA";
|
|
47
48
|
return A2AMetadataKeys2;
|
|
48
49
|
})(A2AMetadataKeys || {});
|
|
49
50
|
var AdkMetadataKeys = ((AdkMetadataKeys2) => {
|
|
@@ -37,6 +37,10 @@ function toA2ATextPart(part) {
|
|
|
37
37
|
return a2aPart;
|
|
38
38
|
}
|
|
39
39
|
function toA2AFilePart(part) {
|
|
40
|
+
const metadata = {};
|
|
41
|
+
if (part.videoMetadata) {
|
|
42
|
+
metadata[A2AMetadataKeys.VIDEO_METADATA] = part.videoMetadata;
|
|
43
|
+
}
|
|
40
44
|
if (part.fileData) {
|
|
41
45
|
return {
|
|
42
46
|
kind: "file",
|
|
@@ -44,7 +48,7 @@ function toA2AFilePart(part) {
|
|
|
44
48
|
uri: part.fileData.fileUri || "",
|
|
45
49
|
mimeType: part.fileData.mimeType
|
|
46
50
|
},
|
|
47
|
-
metadata
|
|
51
|
+
metadata
|
|
48
52
|
};
|
|
49
53
|
}
|
|
50
54
|
if (part.inlineData) {
|
|
@@ -54,7 +58,7 @@ function toA2AFilePart(part) {
|
|
|
54
58
|
bytes: part.inlineData.data || "",
|
|
55
59
|
mimeType: part.inlineData.mimeType
|
|
56
60
|
},
|
|
57
|
-
metadata
|
|
61
|
+
metadata
|
|
58
62
|
};
|
|
59
63
|
}
|
|
60
64
|
throw new Error("Not a file part: ".concat(JSON.stringify(part)));
|
|
@@ -75,7 +79,11 @@ function toA2ADataPart(part, longRunningToolIDs = []) {
|
|
|
75
79
|
dataPartType = "code_execution_result" /* CODE_EXEC_RESULT */;
|
|
76
80
|
data = part.codeExecutionResult;
|
|
77
81
|
} else {
|
|
78
|
-
|
|
82
|
+
return {
|
|
83
|
+
kind: "data",
|
|
84
|
+
data: {},
|
|
85
|
+
metadata: {}
|
|
86
|
+
};
|
|
79
87
|
}
|
|
80
88
|
const metadata = {
|
|
81
89
|
[A2AMetadataKeys.DATA_PART_TYPE]: dataPartType
|
|
@@ -119,21 +127,24 @@ function toGenAIPartText(a2aPart) {
|
|
|
119
127
|
};
|
|
120
128
|
}
|
|
121
129
|
function toGenAIPartFile(a2aPart) {
|
|
130
|
+
var _a;
|
|
131
|
+
const part = {};
|
|
132
|
+
if ((_a = a2aPart.metadata) == null ? void 0 : _a[A2AMetadataKeys.VIDEO_METADATA]) {
|
|
133
|
+
part.videoMetadata = a2aPart.metadata[A2AMetadataKeys.VIDEO_METADATA];
|
|
134
|
+
}
|
|
122
135
|
if ("bytes" in a2aPart.file) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
mimeType: a2aPart.file.mimeType || ""
|
|
127
|
-
}
|
|
136
|
+
part.inlineData = {
|
|
137
|
+
data: a2aPart.file.bytes,
|
|
138
|
+
mimeType: a2aPart.file.mimeType || ""
|
|
128
139
|
};
|
|
140
|
+
return part;
|
|
129
141
|
}
|
|
130
142
|
if ("uri" in a2aPart.file) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
mimeType: a2aPart.file.mimeType || ""
|
|
135
|
-
}
|
|
143
|
+
part.fileData = {
|
|
144
|
+
fileUri: a2aPart.file.uri,
|
|
145
|
+
mimeType: a2aPart.file.mimeType || ""
|
|
136
146
|
};
|
|
147
|
+
return part;
|
|
137
148
|
}
|
|
138
149
|
throw new Error("Not a file part: ".concat(JSON.stringify(a2aPart)));
|
|
139
150
|
}
|
|
@@ -98,6 +98,7 @@ import { AGENT_TRANSFER_LLM_REQUEST_PROCESSOR } from "./processors/agent_transfe
|
|
|
98
98
|
import { BASIC_LLM_REQUEST_PROCESSOR } from "./processors/basic_llm_request_processor.js";
|
|
99
99
|
import { CODE_EXECUTION_REQUEST_PROCESSOR } from "./processors/code_execution_request_processor.js";
|
|
100
100
|
import { CONTENT_REQUEST_PROCESSOR } from "./processors/content_request_processor.js";
|
|
101
|
+
import { ContextCompactorRequestProcessor } from "./processors/context_compactor_request_processor.js";
|
|
101
102
|
import { IDENTITY_LLM_REQUEST_PROCESSOR } from "./processors/identity_llm_request_processor.js";
|
|
102
103
|
import { INSTRUCTIONS_LLM_REQUEST_PROCESSOR } from "./processors/instructions_llm_request_processor.js";
|
|
103
104
|
import { REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR } from "./processors/request_confirmation_llm_request_processor.js";
|
|
@@ -144,6 +145,22 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
144
145
|
CONTENT_REQUEST_PROCESSOR,
|
|
145
146
|
CODE_EXECUTION_REQUEST_PROCESSOR
|
|
146
147
|
];
|
|
148
|
+
if (!config.requestProcessors && config.contextCompactors && config.contextCompactors.length > 0) {
|
|
149
|
+
const contentIndex = this.requestProcessors.indexOf(
|
|
150
|
+
CONTENT_REQUEST_PROCESSOR
|
|
151
|
+
);
|
|
152
|
+
if (contentIndex !== -1) {
|
|
153
|
+
this.requestProcessors.splice(
|
|
154
|
+
contentIndex,
|
|
155
|
+
0,
|
|
156
|
+
new ContextCompactorRequestProcessor(config.contextCompactors)
|
|
157
|
+
);
|
|
158
|
+
} else {
|
|
159
|
+
this.requestProcessors.push(
|
|
160
|
+
new ContextCompactorRequestProcessor(config.contextCompactors)
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
147
164
|
this.responseProcessors = (_h = config.responseProcessors) != null ? _h : [];
|
|
148
165
|
const agentTransferDisabled = this.disallowTransferToParent && this.disallowTransferToPeers && !((_i = this.subAgents) == null ? void 0 : _i.length);
|
|
149
166
|
if (!agentTransferDisabled) {
|
package/dist/web/agents/{content_processor_utils.js → processors/content_processor_utils.js}
RENAMED
|
@@ -3,21 +3,29 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import { createUserContent } from "@google/genai";
|
|
6
7
|
import { cloneDeep } from "lodash-es";
|
|
8
|
+
import {
|
|
9
|
+
isCompactedEvent
|
|
10
|
+
} from "../../events/compacted_event.js";
|
|
7
11
|
import {
|
|
8
12
|
createEvent,
|
|
9
13
|
getFunctionCalls,
|
|
10
14
|
getFunctionResponses
|
|
11
|
-
} from "
|
|
15
|
+
} from "../../events/event.js";
|
|
12
16
|
import {
|
|
13
17
|
removeClientFunctionCallId,
|
|
14
18
|
REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
|
|
15
19
|
REQUEST_EUC_FUNCTION_CALL_NAME
|
|
16
|
-
} from "
|
|
20
|
+
} from "../functions.js";
|
|
17
21
|
function getContents(events, agentName, currentBranch) {
|
|
18
22
|
var _a, _b, _c;
|
|
19
23
|
const filteredEvents = [];
|
|
20
24
|
for (const event of events) {
|
|
25
|
+
if (isCompactedEvent(event)) {
|
|
26
|
+
filteredEvents.push(convertCompactedEvent(event));
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
21
29
|
if (!((_a = event.content) == null ? void 0 : _a.role) || ((_c = (_b = event.content.parts) == null ? void 0 : _b[0]) == null ? void 0 : _c.text) === "") {
|
|
22
30
|
continue;
|
|
23
31
|
}
|
|
@@ -290,6 +298,18 @@ function safeStringify(obj) {
|
|
|
290
298
|
return String(obj);
|
|
291
299
|
}
|
|
292
300
|
}
|
|
301
|
+
function convertCompactedEvent(event) {
|
|
302
|
+
const content = createUserContent(
|
|
303
|
+
"[Previous Context Summary]:\n".concat(event.compactedContent)
|
|
304
|
+
);
|
|
305
|
+
return createEvent({
|
|
306
|
+
invocationId: event.invocationId,
|
|
307
|
+
author: "user",
|
|
308
|
+
content,
|
|
309
|
+
branch: event.branch,
|
|
310
|
+
timestamp: event.timestamp
|
|
311
|
+
});
|
|
312
|
+
}
|
|
293
313
|
export {
|
|
294
314
|
getContents,
|
|
295
315
|
getCurrentTurnContents
|
|
@@ -19,11 +19,12 @@ var __asyncGenerator = (__this, __arguments, generator) => {
|
|
|
19
19
|
* Copyright 2025 Google LLC
|
|
20
20
|
* SPDX-License-Identifier: Apache-2.0
|
|
21
21
|
*/
|
|
22
|
+
import { isCompactedEvent } from "../../events/compacted_event.js";
|
|
23
|
+
import { isLlmAgent } from "../llm_agent.js";
|
|
22
24
|
import {
|
|
23
25
|
getContents,
|
|
24
26
|
getCurrentTurnContents
|
|
25
|
-
} from "
|
|
26
|
-
import { isLlmAgent } from "../llm_agent.js";
|
|
27
|
+
} from "./content_processor_utils.js";
|
|
27
28
|
class ContentRequestProcessor {
|
|
28
29
|
// eslint-disable-next-line require-yield
|
|
29
30
|
runAsync(invocationContext, llmRequest) {
|
|
@@ -32,15 +33,35 @@ class ContentRequestProcessor {
|
|
|
32
33
|
if (!agent || !isLlmAgent(agent)) {
|
|
33
34
|
return;
|
|
34
35
|
}
|
|
36
|
+
let events = invocationContext.session.events;
|
|
37
|
+
const compactedEvents = events.filter(isCompactedEvent);
|
|
38
|
+
const latestCompactedEvent = compactedEvents.length > 0 ? compactedEvents.reduce(
|
|
39
|
+
(latest, current) => current.endTime > latest.endTime ? current : latest
|
|
40
|
+
) : void 0;
|
|
41
|
+
if (latestCompactedEvent) {
|
|
42
|
+
const remainingEvents = events.filter((event) => {
|
|
43
|
+
if (event === latestCompactedEvent) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if (isCompactedEvent(event)) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (event.timestamp <= latestCompactedEvent.endTime) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
});
|
|
54
|
+
events = [latestCompactedEvent, ...remainingEvents];
|
|
55
|
+
}
|
|
35
56
|
if (agent.includeContents === "default") {
|
|
36
57
|
llmRequest.contents = getContents(
|
|
37
|
-
|
|
58
|
+
events,
|
|
38
59
|
agent.name,
|
|
39
60
|
invocationContext.branch
|
|
40
61
|
);
|
|
41
62
|
} else {
|
|
42
63
|
llmRequest.contents = getCurrentTurnContents(
|
|
43
|
-
|
|
64
|
+
events,
|
|
44
65
|
agent.name,
|
|
45
66
|
invocationContext.branch
|
|
46
67
|
);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
2
|
+
var __await = function(promise, isYieldStar) {
|
|
3
|
+
this[0] = promise;
|
|
4
|
+
this[1] = isYieldStar;
|
|
5
|
+
};
|
|
6
|
+
var __asyncGenerator = (__this, __arguments, generator) => {
|
|
7
|
+
var resume = (k, v, yes, no) => {
|
|
8
|
+
try {
|
|
9
|
+
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
10
|
+
Promise.resolve(isAwait ? v[0] : v).then((y) => isAwait ? resume(k === "return" ? k : "next", v[1] ? { done: y.done, value: y.value } : y, yes, no) : yes({ value: y, done })).catch((e) => resume("throw", e, yes, no));
|
|
11
|
+
} catch (e) {
|
|
12
|
+
no(e);
|
|
13
|
+
}
|
|
14
|
+
}, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
|
|
15
|
+
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* @license
|
|
19
|
+
* Copyright 2026 Google LLC
|
|
20
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
21
|
+
*/
|
|
22
|
+
class ContextCompactorRequestProcessor {
|
|
23
|
+
constructor(compactors) {
|
|
24
|
+
this.compactors = compactors;
|
|
25
|
+
}
|
|
26
|
+
runAsync(invocationContext, _llmRequest) {
|
|
27
|
+
return __asyncGenerator(this, null, function* () {
|
|
28
|
+
for (const compactor of this.compactors) {
|
|
29
|
+
const shouldCompact = yield new __await(Promise.resolve(
|
|
30
|
+
compactor.shouldCompact(invocationContext)
|
|
31
|
+
));
|
|
32
|
+
if (shouldCompact) {
|
|
33
|
+
const oldEvents = new Set(invocationContext.session.events);
|
|
34
|
+
yield new __await(Promise.resolve(compactor.compact(invocationContext)));
|
|
35
|
+
const newEvents = invocationContext.session.events.filter(
|
|
36
|
+
(e) => !oldEvents.has(e)
|
|
37
|
+
);
|
|
38
|
+
for (const e of newEvents) {
|
|
39
|
+
yield e;
|
|
40
|
+
}
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
ContextCompactorRequestProcessor
|
|
49
|
+
};
|
|
@@ -32,7 +32,7 @@ class InstructionsLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
|
32
32
|
runAsync(invocationContext, llmRequest) {
|
|
33
33
|
return __asyncGenerator(this, null, function* () {
|
|
34
34
|
const agent = invocationContext.agent;
|
|
35
|
-
if (!isLlmAgent(agent)
|
|
35
|
+
if (!isLlmAgent(agent)) {
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
38
|
const rootAgent = agent.rootAgent;
|
|
@@ -348,8 +348,28 @@ class FileArtifactService {
|
|
|
348
348
|
}
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
|
+
const SAFE_SEGMENT_RE = /^[a-zA-Z0-9_@-][a-zA-Z0-9_.@-]{0,255}$/;
|
|
352
|
+
function assertSafeSegment(value, label) {
|
|
353
|
+
if (!value || !SAFE_SEGMENT_RE.test(value)) {
|
|
354
|
+
throw new Error(
|
|
355
|
+
"[FileArtifactService] Invalid ".concat(label, ": value contains disallowed characters.")
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
function assertInsideRoot(resolvedPath, rootDir, label) {
|
|
360
|
+
const root = path.resolve(rootDir);
|
|
361
|
+
const resolved = path.resolve(resolvedPath);
|
|
362
|
+
if (!resolved.startsWith(root + path.sep) && resolved !== root) {
|
|
363
|
+
throw new Error(
|
|
364
|
+
"[FileArtifactService] ".concat(label, " escapes storage root. Resolved: ").concat(resolved, ", Root: ").concat(root)
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
351
368
|
function getUserRoot(rootDir, userId) {
|
|
352
|
-
|
|
369
|
+
assertSafeSegment(userId, "userId");
|
|
370
|
+
const result = path.join(rootDir, "users", userId);
|
|
371
|
+
assertInsideRoot(result, rootDir, "userRoot");
|
|
372
|
+
return result;
|
|
353
373
|
}
|
|
354
374
|
function isUserScoped(sessionId, filename) {
|
|
355
375
|
return !sessionId || filename.startsWith(USER_NAMESPACE_PREFIX);
|
|
@@ -358,7 +378,10 @@ function getUserArtifactsDir(userRoot) {
|
|
|
358
378
|
return path.join(userRoot, "artifacts");
|
|
359
379
|
}
|
|
360
380
|
function getSessionArtifactsDir(baseRoot, sessionId) {
|
|
361
|
-
|
|
381
|
+
assertSafeSegment(sessionId, "sessionId");
|
|
382
|
+
const result = path.join(baseRoot, "sessions", sessionId, "artifacts");
|
|
383
|
+
assertInsideRoot(result, baseRoot, "sessionArtifactsDir");
|
|
384
|
+
return result;
|
|
362
385
|
}
|
|
363
386
|
function getVersionsDir(artifactDir) {
|
|
364
387
|
return path.join(artifactDir, "versions");
|
|
@@ -502,5 +525,9 @@ function asPosixPath(p) {
|
|
|
502
525
|
return p.split(path.sep).join("/");
|
|
503
526
|
}
|
|
504
527
|
export {
|
|
505
|
-
FileArtifactService
|
|
528
|
+
FileArtifactService,
|
|
529
|
+
assertInsideRoot,
|
|
530
|
+
assertSafeSegment,
|
|
531
|
+
getSessionArtifactsDir,
|
|
532
|
+
getUserRoot
|
|
506
533
|
};
|
package/dist/web/common.js
CHANGED
|
@@ -16,6 +16,11 @@ import {
|
|
|
16
16
|
BaseLlmRequestProcessor,
|
|
17
17
|
BaseLlmResponseProcessor
|
|
18
18
|
} from "./agents/processors/base_llm_processor.js";
|
|
19
|
+
import {
|
|
20
|
+
CONTENT_REQUEST_PROCESSOR,
|
|
21
|
+
ContentRequestProcessor
|
|
22
|
+
} from "./agents/processors/content_request_processor.js";
|
|
23
|
+
import { ContextCompactorRequestProcessor } from "./agents/processors/context_compactor_request_processor.js";
|
|
19
24
|
import { ReadonlyContext } from "./agents/readonly_context.js";
|
|
20
25
|
import { StreamingMode } from "./agents/run_config.js";
|
|
21
26
|
import { SequentialAgent, isSequentialAgent } from "./agents/sequential_agent.js";
|
|
@@ -23,6 +28,10 @@ import { InMemoryArtifactService } from "./artifacts/in_memory_artifact_service.
|
|
|
23
28
|
import { AuthCredentialTypes } from "./auth/auth_credential.js";
|
|
24
29
|
import { BaseCodeExecutor } from "./code_executors/base_code_executor.js";
|
|
25
30
|
import { BuiltInCodeExecutor } from "./code_executors/built_in_code_executor.js";
|
|
31
|
+
import { LlmSummarizer } from "./context/summarizers/llm_summarizer.js";
|
|
32
|
+
import { TokenBasedContextCompactor } from "./context/token_based_context_compactor.js";
|
|
33
|
+
import { TruncatingContextCompactor } from "./context/truncating_context_compactor.js";
|
|
34
|
+
import { isCompactedEvent } from "./events/compacted_event.js";
|
|
26
35
|
import {
|
|
27
36
|
createEvent,
|
|
28
37
|
getFunctionCalls,
|
|
@@ -53,7 +62,7 @@ import {
|
|
|
53
62
|
getAskUserConfirmationFunctionCalls
|
|
54
63
|
} from "./plugins/security_plugin.js";
|
|
55
64
|
import { InMemoryRunner } from "./runner/in_memory_runner.js";
|
|
56
|
-
import { Runner } from "./runner/runner.js";
|
|
65
|
+
import { Runner, isRunner } from "./runner/runner.js";
|
|
57
66
|
import { BaseSessionService } from "./sessions/base_session_service.js";
|
|
58
67
|
import { InMemorySessionService } from "./sessions/in_memory_session_service.js";
|
|
59
68
|
import { createSession } from "./sessions/session.js";
|
|
@@ -64,7 +73,16 @@ import { BaseToolset, isBaseToolset } from "./tools/base_toolset.js";
|
|
|
64
73
|
import { EXIT_LOOP, ExitLoopTool } from "./tools/exit_loop_tool.js";
|
|
65
74
|
import { FunctionTool, isFunctionTool } from "./tools/function_tool.js";
|
|
66
75
|
import { GOOGLE_SEARCH, GoogleSearchTool } from "./tools/google_search_tool.js";
|
|
76
|
+
import {
|
|
77
|
+
LOAD_ARTIFACTS,
|
|
78
|
+
LoadArtifactsTool
|
|
79
|
+
} from "./tools/load_artifacts_tool.js";
|
|
80
|
+
import { LOAD_MEMORY, LoadMemoryTool } from "./tools/load_memory_tool.js";
|
|
67
81
|
import { LongRunningFunctionTool } from "./tools/long_running_tool.js";
|
|
82
|
+
import {
|
|
83
|
+
PRELOAD_MEMORY,
|
|
84
|
+
PreloadMemoryTool
|
|
85
|
+
} from "./tools/preload_memory_tool.js";
|
|
68
86
|
import { ToolConfirmation } from "./tools/tool_confirmation.js";
|
|
69
87
|
import { LogLevel, getLogger, setLogLevel, setLogger } from "./utils/logger.js";
|
|
70
88
|
import { isGemini2OrAbove } from "./utils/model_name.js";
|
|
@@ -91,7 +109,10 @@ export {
|
|
|
91
109
|
BaseTool,
|
|
92
110
|
BaseToolset,
|
|
93
111
|
BuiltInCodeExecutor,
|
|
112
|
+
CONTENT_REQUEST_PROCESSOR,
|
|
113
|
+
ContentRequestProcessor,
|
|
94
114
|
Context,
|
|
115
|
+
ContextCompactorRequestProcessor,
|
|
95
116
|
EXIT_LOOP,
|
|
96
117
|
EventType,
|
|
97
118
|
ExitLoopTool,
|
|
@@ -107,15 +128,22 @@ export {
|
|
|
107
128
|
InMemorySessionService,
|
|
108
129
|
InvocationContext,
|
|
109
130
|
LLMRegistry,
|
|
131
|
+
LOAD_ARTIFACTS,
|
|
132
|
+
LOAD_MEMORY,
|
|
110
133
|
LiveRequestQueue,
|
|
111
134
|
LlmAgent,
|
|
135
|
+
LlmSummarizer,
|
|
136
|
+
LoadArtifactsTool,
|
|
137
|
+
LoadMemoryTool,
|
|
112
138
|
LogLevel,
|
|
113
139
|
LoggingPlugin,
|
|
114
140
|
LongRunningFunctionTool,
|
|
115
141
|
LoopAgent,
|
|
142
|
+
PRELOAD_MEMORY,
|
|
116
143
|
ParallelAgent,
|
|
117
144
|
PluginManager,
|
|
118
145
|
PolicyOutcome,
|
|
146
|
+
PreloadMemoryTool,
|
|
119
147
|
REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
|
|
120
148
|
ReadonlyContext,
|
|
121
149
|
Runner,
|
|
@@ -123,7 +151,9 @@ export {
|
|
|
123
151
|
SequentialAgent,
|
|
124
152
|
State,
|
|
125
153
|
StreamingMode,
|
|
154
|
+
TokenBasedContextCompactor,
|
|
126
155
|
ToolConfirmation,
|
|
156
|
+
TruncatingContextCompactor,
|
|
127
157
|
createEvent,
|
|
128
158
|
createEventActions,
|
|
129
159
|
createSession,
|
|
@@ -140,12 +170,14 @@ export {
|
|
|
140
170
|
isBaseLlm,
|
|
141
171
|
isBaseTool,
|
|
142
172
|
isBaseToolset,
|
|
173
|
+
isCompactedEvent,
|
|
143
174
|
isFinalResponse,
|
|
144
175
|
isFunctionTool,
|
|
145
176
|
isGemini2OrAbove,
|
|
146
177
|
isLlmAgent,
|
|
147
178
|
isLoopAgent,
|
|
148
179
|
isParallelAgent,
|
|
180
|
+
isRunner,
|
|
149
181
|
isSequentialAgent,
|
|
150
182
|
setLogLevel,
|
|
151
183
|
setLogger,
|