@paean-ai/adk 0.2.23 → 0.2.25
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/agents/functions.js +12 -1
- package/dist/cjs/agents/llm_agent.js +32 -5
- package/dist/cjs/events/event.js +2 -1
- package/dist/cjs/index.js +11 -11
- package/dist/cjs/index.js.map +3 -3
- package/dist/cjs/models/google_llm.js +36 -8
- package/dist/esm/agents/functions.js +12 -1
- package/dist/esm/agents/llm_agent.js +32 -5
- package/dist/esm/events/event.js +2 -1
- package/dist/esm/index.js +11 -11
- package/dist/esm/index.js.map +3 -3
- package/dist/esm/models/google_llm.js +36 -8
- package/dist/web/agents/functions.js +12 -1
- package/dist/web/agents/llm_agent.js +32 -5
- package/dist/web/events/event.js +2 -1
- package/dist/web/index.js +1 -1
- package/dist/web/index.js.map +3 -3
- package/dist/web/models/google_llm.js +39 -11
- package/package.json +1 -1
|
@@ -106,7 +106,7 @@ class Gemini extends BaseLlm {
|
|
|
106
106
|
* @yields LlmResponse: The model response.
|
|
107
107
|
*/
|
|
108
108
|
async *generateContentAsync(llmRequest, stream = false) {
|
|
109
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
109
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
110
110
|
this.preprocessRequest(llmRequest);
|
|
111
111
|
this.maybeAppendUserContent(llmRequest);
|
|
112
112
|
logger.info(
|
|
@@ -129,6 +129,7 @@ class Gemini extends BaseLlm {
|
|
|
129
129
|
let text = "";
|
|
130
130
|
let usageMetadata;
|
|
131
131
|
let lastResponse;
|
|
132
|
+
let pendingFCResponse = null;
|
|
132
133
|
for await (const response of streamResult) {
|
|
133
134
|
lastResponse = response;
|
|
134
135
|
const llmResponse = createLlmResponse(response);
|
|
@@ -157,7 +158,9 @@ class Gemini extends BaseLlm {
|
|
|
157
158
|
} else {
|
|
158
159
|
text += firstPart.text;
|
|
159
160
|
}
|
|
160
|
-
|
|
161
|
+
if (!hasFunctionCalls) {
|
|
162
|
+
llmResponse.partial = true;
|
|
163
|
+
}
|
|
161
164
|
if (this.isGemini3Preview && hasFunctionCalls) {
|
|
162
165
|
thoughtText = "";
|
|
163
166
|
thoughtSignature = void 0;
|
|
@@ -227,18 +230,43 @@ class Gemini extends BaseLlm {
|
|
|
227
230
|
}
|
|
228
231
|
}
|
|
229
232
|
}
|
|
230
|
-
|
|
233
|
+
}
|
|
234
|
+
if (hasFunctionCalls) {
|
|
235
|
+
if (pendingFCResponse && ((_i = pendingFCResponse.content) == null ? void 0 : _i.parts)) {
|
|
236
|
+
const newFCParts = (((_j = llmResponse.content) == null ? void 0 : _j.parts) || []).filter(
|
|
237
|
+
(p) => p.functionCall
|
|
238
|
+
);
|
|
239
|
+
pendingFCResponse.content.parts.push(...newFCParts);
|
|
240
|
+
pendingFCResponse.usageMetadata = llmResponse.usageMetadata;
|
|
241
|
+
} else {
|
|
242
|
+
pendingFCResponse = llmResponse;
|
|
243
|
+
}
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
if (pendingFCResponse) {
|
|
247
|
+
if (!((_l = (_k = llmResponse.content) == null ? void 0 : _k.parts) == null ? void 0 : _l.length)) {
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
yield pendingFCResponse;
|
|
251
|
+
pendingFCResponse = null;
|
|
252
|
+
}
|
|
253
|
+
yield llmResponse;
|
|
254
|
+
}
|
|
255
|
+
if (pendingFCResponse) {
|
|
256
|
+
if (this.isGemini3Preview && ((_m = pendingFCResponse.content) == null ? void 0 : _m.parts)) {
|
|
257
|
+
const partsWithSig = pendingFCResponse.content.parts.filter(
|
|
231
258
|
(p) => p.thoughtSignature
|
|
232
259
|
).length;
|
|
233
260
|
if (partsWithSig === 0) {
|
|
234
261
|
logger.warn(
|
|
235
|
-
`[Gemini3] No thoughtSignature on function call parts \u2014 may cause 400 on next request`
|
|
262
|
+
`[Gemini3] No thoughtSignature on merged function call parts \u2014 may cause 400 on next request`
|
|
236
263
|
);
|
|
237
264
|
}
|
|
238
265
|
}
|
|
239
|
-
yield
|
|
266
|
+
yield pendingFCResponse;
|
|
267
|
+
pendingFCResponse = null;
|
|
240
268
|
}
|
|
241
|
-
if ((text || thoughtText) && ((
|
|
269
|
+
if ((text || thoughtText) && ((_o = (_n = lastResponse == null ? void 0 : lastResponse.candidates) == null ? void 0 : _n[0]) == null ? void 0 : _o.finishReason) === FinishReason.STOP) {
|
|
242
270
|
const parts = [];
|
|
243
271
|
if (thoughtText) {
|
|
244
272
|
const thoughtPart = { text: thoughtText, thought: true };
|
|
@@ -260,12 +288,12 @@ class Gemini extends BaseLlm {
|
|
|
260
288
|
}
|
|
261
289
|
} else {
|
|
262
290
|
const response = await this.apiClient.models.generateContent({
|
|
263
|
-
model: (
|
|
291
|
+
model: (_p = llmRequest.model) != null ? _p : this.model,
|
|
264
292
|
contents: llmRequest.contents,
|
|
265
293
|
config: llmRequest.config
|
|
266
294
|
});
|
|
267
295
|
const llmResponse = createLlmResponse(response);
|
|
268
|
-
if (this.isGemini3Preview && ((
|
|
296
|
+
if (this.isGemini3Preview && ((_q = llmResponse.content) == null ? void 0 : _q.parts)) {
|
|
269
297
|
let thoughtSig;
|
|
270
298
|
let hasThoughtPartWithSignature = false;
|
|
271
299
|
for (const part of llmResponse.content.parts) {
|
|
@@ -89,6 +89,9 @@ function generateAuthEvent(invocationContext, functionResponseEvent) {
|
|
|
89
89
|
longRunningToolIds.add(requestEucFunctionCall.id);
|
|
90
90
|
parts.push({ functionCall: requestEucFunctionCall });
|
|
91
91
|
}
|
|
92
|
+
if (parts.length === 0) {
|
|
93
|
+
return void 0;
|
|
94
|
+
}
|
|
92
95
|
return createEvent({
|
|
93
96
|
invocationId: invocationContext.invocationId,
|
|
94
97
|
author: invocationContext.agent.name,
|
|
@@ -130,6 +133,9 @@ function generateRequestConfirmationEvent({
|
|
|
130
133
|
longRunningToolIds.add(requestConfirmationFunctionCall.id);
|
|
131
134
|
parts.push({ functionCall: requestConfirmationFunctionCall });
|
|
132
135
|
}
|
|
136
|
+
if (parts.length === 0) {
|
|
137
|
+
return void 0;
|
|
138
|
+
}
|
|
133
139
|
return createEvent({
|
|
134
140
|
invocationId: invocationContext.invocationId,
|
|
135
141
|
author: invocationContext.agent.name,
|
|
@@ -193,8 +199,9 @@ async function handleFunctionCallList({
|
|
|
193
199
|
}
|
|
194
200
|
);
|
|
195
201
|
if (!toolAndContext) {
|
|
202
|
+
const argsPreview = functionCall.args ? JSON.stringify(functionCall.args).substring(0, 300) : "(none)";
|
|
196
203
|
logger.warn(
|
|
197
|
-
'Function "'.concat(functionCall.name, '" not found in toolsDict ') + "(".concat(Object.keys(toolsDict).length, " tools registered).")
|
|
204
|
+
'Function "'.concat(functionCall.name, '" not found in toolsDict ') + "(".concat(Object.keys(toolsDict).length, " tools registered). ") + "Args: ".concat(argsPreview)
|
|
198
205
|
);
|
|
199
206
|
const errorResponseEvent = createEvent({
|
|
200
207
|
invocationId: invocationContext.invocationId,
|
|
@@ -243,6 +250,10 @@ async function handleFunctionCallList({
|
|
|
243
250
|
toolContext
|
|
244
251
|
);
|
|
245
252
|
} catch (e) {
|
|
253
|
+
const argsPreview = JSON.stringify(functionArgs).substring(0, 500);
|
|
254
|
+
logger.error(
|
|
255
|
+
'Tool execution error: "'.concat(tool.name, '" threw ').concat(e instanceof Error ? e.message : String(e), ". Args: ").concat(argsPreview)
|
|
256
|
+
);
|
|
246
257
|
if (e instanceof Error) {
|
|
247
258
|
const onToolErrorResponse = await invocationContext.pluginManager.runOnToolErrorCallback(
|
|
248
259
|
{
|
|
@@ -923,12 +923,12 @@ const _LlmAgent = class _LlmAgent extends BaseAgent {
|
|
|
923
923
|
consecutiveErrors++;
|
|
924
924
|
if (consecutiveErrors <= _LlmAgent.MAX_AGENT_LOOP_ERROR_RETRIES) {
|
|
925
925
|
logger.warn(
|
|
926
|
-
"[runAsyncImpl] Error event (".concat(lastEvent.errorCode, "), ") + "retrying agent loop (".concat(consecutiveErrors, "/").concat(_LlmAgent.MAX_AGENT_LOOP_ERROR_RETRIES, ")")
|
|
926
|
+
"[runAsyncImpl] Error event (".concat(lastEvent.errorCode, ": ").concat(lastEvent.errorMessage || "no message", "), ") + "retrying agent loop (".concat(consecutiveErrors, "/").concat(_LlmAgent.MAX_AGENT_LOOP_ERROR_RETRIES, ")")
|
|
927
927
|
);
|
|
928
928
|
continue;
|
|
929
929
|
}
|
|
930
930
|
logger.error(
|
|
931
|
-
"[runAsyncImpl] Max agent-loop error retries exhausted for ".concat(lastEvent.errorCode)
|
|
931
|
+
"[runAsyncImpl] Max agent-loop error retries exhausted for " + "".concat(lastEvent.errorCode, ": ").concat(lastEvent.errorMessage || "no message")
|
|
932
932
|
);
|
|
933
933
|
break;
|
|
934
934
|
}
|
|
@@ -1073,7 +1073,7 @@ const _LlmAgent = class _LlmAgent extends BaseAgent {
|
|
|
1073
1073
|
}
|
|
1074
1074
|
postprocess(invocationContext, llmRequest, llmResponse, modelResponseEvent) {
|
|
1075
1075
|
return __asyncGenerator(this, null, function* () {
|
|
1076
|
-
var _a, _b;
|
|
1076
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1077
1077
|
for (const processor of this.responseProcessors) {
|
|
1078
1078
|
try {
|
|
1079
1079
|
for (var iter = __forAwait(processor.runAsync(invocationContext, llmResponse)), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
@@ -1094,6 +1094,27 @@ const _LlmAgent = class _LlmAgent extends BaseAgent {
|
|
|
1094
1094
|
if (!llmResponse.content && !llmResponse.errorCode && !llmResponse.interrupted) {
|
|
1095
1095
|
return;
|
|
1096
1096
|
}
|
|
1097
|
+
if (llmResponse.content && !llmResponse.errorCode) {
|
|
1098
|
+
if (!llmResponse.content.parts || llmResponse.content.parts.length === 0) {
|
|
1099
|
+
logger.debug(
|
|
1100
|
+
"[postprocess] Skipping LLM response with no parts (role=".concat(llmResponse.content.role, ")")
|
|
1101
|
+
);
|
|
1102
|
+
return;
|
|
1103
|
+
}
|
|
1104
|
+
const allEmpty = llmResponse.content.parts.every(
|
|
1105
|
+
(p) => {
|
|
1106
|
+
if (p.functionCall || p.functionResponse || p.executableCode || p.codeExecutionResult) return false;
|
|
1107
|
+
if ("text" in p && typeof p.text === "string" && p.text.length > 0) return false;
|
|
1108
|
+
return true;
|
|
1109
|
+
}
|
|
1110
|
+
);
|
|
1111
|
+
if (allEmpty) {
|
|
1112
|
+
logger.debug(
|
|
1113
|
+
"[postprocess] Skipping empty-content LLM response (".concat(llmResponse.content.parts.length, " empty parts)")
|
|
1114
|
+
);
|
|
1115
|
+
return;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1097
1118
|
const mergedEvent = createEvent(__spreadValues(__spreadValues({}, modelResponseEvent), llmResponse));
|
|
1098
1119
|
if (mergedEvent.content) {
|
|
1099
1120
|
const functionCalls = getFunctionCalls(mergedEvent);
|
|
@@ -1112,8 +1133,11 @@ const _LlmAgent = class _LlmAgent extends BaseAgent {
|
|
|
1112
1133
|
}
|
|
1113
1134
|
}
|
|
1114
1135
|
}
|
|
1136
|
+
logger.debug(
|
|
1137
|
+
"[postprocess] Yielding mergedEvent: role=".concat((_b = mergedEvent.content) == null ? void 0 : _b.role, ", parts=").concat((_d = (_c = mergedEvent.content) == null ? void 0 : _c.parts) == null ? void 0 : _d.length, ", ") + "hasFCs=".concat(((_e = getFunctionCalls(mergedEvent)) == null ? void 0 : _e.length) || 0, ", partial=").concat(mergedEvent.partial)
|
|
1138
|
+
);
|
|
1115
1139
|
yield mergedEvent;
|
|
1116
|
-
if (!((
|
|
1140
|
+
if (!((_f = getFunctionCalls(mergedEvent)) == null ? void 0 : _f.length)) {
|
|
1117
1141
|
return;
|
|
1118
1142
|
}
|
|
1119
1143
|
const functionResponseEvent = yield new __await(handleFunctionCallsAsync({
|
|
@@ -1138,6 +1162,9 @@ const _LlmAgent = class _LlmAgent extends BaseAgent {
|
|
|
1138
1162
|
if (toolConfirmationEvent) {
|
|
1139
1163
|
yield toolConfirmationEvent;
|
|
1140
1164
|
}
|
|
1165
|
+
logger.debug(
|
|
1166
|
+
"[postprocess] Yielding functionResponseEvent: role=".concat((_g = functionResponseEvent.content) == null ? void 0 : _g.role, ", parts=").concat((_i = (_h = functionResponseEvent.content) == null ? void 0 : _h.parts) == null ? void 0 : _i.length)
|
|
1167
|
+
);
|
|
1141
1168
|
yield functionResponseEvent;
|
|
1142
1169
|
const nextAgentName = functionResponseEvent.actions.transferToAgent;
|
|
1143
1170
|
if (nextAgentName) {
|
|
@@ -1235,7 +1262,7 @@ const _LlmAgent = class _LlmAgent extends BaseAgent {
|
|
|
1235
1262
|
if (llmResponse.errorCode && _LlmAgent.LLM_RETRYABLE_ERROR_CODES.has(llmResponse.errorCode) && !contentYielded && attempt < maxRetries) {
|
|
1236
1263
|
shouldRetry = true;
|
|
1237
1264
|
logger.warn(
|
|
1238
|
-
"[callLlmAsync] Transient LLM error: ".concat(llmResponse.errorCode, ", ") + "usage: ".concat(JSON.stringify(llmResponse.usageMetadata))
|
|
1265
|
+
"[callLlmAsync] Transient LLM error: ".concat(llmResponse.errorCode) + "".concat(llmResponse.errorMessage ? ": " + llmResponse.errorMessage : "", ", ") + "finishReason: ".concat(llmResponse.finishReason || "none", ", ") + "usage: ".concat(JSON.stringify(llmResponse.usageMetadata))
|
|
1239
1266
|
);
|
|
1240
1267
|
break;
|
|
1241
1268
|
}
|
package/dist/web/events/event.js
CHANGED
|
@@ -24,7 +24,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
24
24
|
*/
|
|
25
25
|
import { createEventActions } from "./event_actions.js";
|
|
26
26
|
function createEvent(params = {}) {
|
|
27
|
-
|
|
27
|
+
const event = __spreadProps(__spreadValues({}, params), {
|
|
28
28
|
id: params.id || createNewEventId(),
|
|
29
29
|
invocationId: params.invocationId || "",
|
|
30
30
|
author: params.author,
|
|
@@ -33,6 +33,7 @@ function createEvent(params = {}) {
|
|
|
33
33
|
branch: params.branch,
|
|
34
34
|
timestamp: params.timestamp || Date.now()
|
|
35
35
|
});
|
|
36
|
+
return event;
|
|
36
37
|
}
|
|
37
38
|
function isFinalResponse(event) {
|
|
38
39
|
if (event.actions.skipSummarization || event.longRunningToolIds && event.longRunningToolIds.length > 0) {
|