@prestyj/agent 5.1.1 → 5.2.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/index.cjs +51 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +52 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -261,6 +261,7 @@ async function* agentLoop(messages, options) {
|
|
|
261
261
|
const toolMap = new Map((options.tools ?? []).map((t) => [t.name, t]));
|
|
262
262
|
const totalUsage = { inputTokens: 0, outputTokens: 0 };
|
|
263
263
|
let turn = 0;
|
|
264
|
+
let hitMaxTurns = false;
|
|
264
265
|
let firstTurn = true;
|
|
265
266
|
let consecutivePauses = 0;
|
|
266
267
|
let toolPairingRepaired = false;
|
|
@@ -271,6 +272,7 @@ async function* agentLoop(messages, options) {
|
|
|
271
272
|
let overflowCompactionAttempts = 0;
|
|
272
273
|
let toolResultTruncationAttempted = false;
|
|
273
274
|
const invalidToolArgumentCounts = /* @__PURE__ */ new Map();
|
|
275
|
+
let toolArgumentAutoContinueUsed = false;
|
|
274
276
|
let useNonStreamingFallback = false;
|
|
275
277
|
const MAX_OVERLOAD_RETRIES = 10;
|
|
276
278
|
const MAX_EMPTY_RESPONSE_RETRIES = 2;
|
|
@@ -843,8 +845,12 @@ async function* agentLoop(messages, options) {
|
|
|
843
845
|
}
|
|
844
846
|
}
|
|
845
847
|
let fatalToolArgumentError = null;
|
|
846
|
-
|
|
848
|
+
let fatalToolArgumentRecoverable = false;
|
|
849
|
+
let fatalToolArgumentToolName = "";
|
|
850
|
+
const markFatalToolArgumentError = (error, recoverable, toolName) => {
|
|
847
851
|
fatalToolArgumentError = error;
|
|
852
|
+
fatalToolArgumentRecoverable = recoverable;
|
|
853
|
+
fatalToolArgumentToolName = toolName;
|
|
848
854
|
};
|
|
849
855
|
const executionOptions = {
|
|
850
856
|
signal: options.signal,
|
|
@@ -860,8 +866,24 @@ async function* agentLoop(messages, options) {
|
|
|
860
866
|
messages.push({ role: "tool", content: executionResult.toolResults });
|
|
861
867
|
const toolsAborted = executionResult.aborted;
|
|
862
868
|
if (fatalToolArgumentError) {
|
|
863
|
-
|
|
864
|
-
|
|
869
|
+
if (fatalToolArgumentRecoverable && !toolArgumentAutoContinueUsed) {
|
|
870
|
+
toolArgumentAutoContinueUsed = true;
|
|
871
|
+
for (const key of invalidToolArgumentCounts.keys()) {
|
|
872
|
+
if (key.startsWith(`${fatalToolArgumentToolName}:`))
|
|
873
|
+
invalidToolArgumentCounts.delete(key);
|
|
874
|
+
}
|
|
875
|
+
yield {
|
|
876
|
+
type: "retry",
|
|
877
|
+
reason: "tool_argument_glitch",
|
|
878
|
+
attempt: 1,
|
|
879
|
+
maxAttempts: 1,
|
|
880
|
+
delayMs: 0,
|
|
881
|
+
silent: false
|
|
882
|
+
};
|
|
883
|
+
} else {
|
|
884
|
+
yield { type: "error", error: fatalToolArgumentError };
|
|
885
|
+
break;
|
|
886
|
+
}
|
|
865
887
|
}
|
|
866
888
|
if (toolsAborted) break;
|
|
867
889
|
if (options.getSteeringMessages) {
|
|
@@ -873,6 +895,9 @@ async function* agentLoop(messages, options) {
|
|
|
873
895
|
}
|
|
874
896
|
}
|
|
875
897
|
}
|
|
898
|
+
if (turn >= maxTurns) {
|
|
899
|
+
hitMaxTurns = true;
|
|
900
|
+
}
|
|
876
901
|
}
|
|
877
902
|
} finally {
|
|
878
903
|
sanitizeOrphanedServerTools(messages);
|
|
@@ -884,6 +909,19 @@ async function* agentLoop(messages, options) {
|
|
|
884
909
|
break;
|
|
885
910
|
}
|
|
886
911
|
}
|
|
912
|
+
if (hitMaxTurns) {
|
|
913
|
+
diag("max_turns_reached", {
|
|
914
|
+
turn,
|
|
915
|
+
maxTurns,
|
|
916
|
+
provider: options.provider,
|
|
917
|
+
model: options.model
|
|
918
|
+
});
|
|
919
|
+
yield {
|
|
920
|
+
type: "max_turns",
|
|
921
|
+
totalTurns: turn,
|
|
922
|
+
maxTurns
|
|
923
|
+
};
|
|
924
|
+
}
|
|
887
925
|
yield {
|
|
888
926
|
type: "agent_done",
|
|
889
927
|
totalTurns: turn,
|
|
@@ -949,10 +987,17 @@ async function executeSingleToolCall(toolCall, options, pushEvent) {
|
|
|
949
987
|
resultContent = `Invalid arguments for tool \`${toolCall.name}\`:
|
|
950
988
|
` + prettyError + "\nRe-issue the call with each field as the correct type.";
|
|
951
989
|
if (failureCount >= 3) {
|
|
990
|
+
const recoverable = Object.keys(toolCall.args ?? {}).length === 0;
|
|
952
991
|
options.markFatalToolArgumentError(
|
|
953
|
-
new
|
|
954
|
-
`The model repeatedly issued invalid arguments for tool \`${toolCall.name}\`. This is usually an upstream model/tool-calling bug
|
|
955
|
-
|
|
992
|
+
new import_ai.EZCoderAIError(
|
|
993
|
+
`The model repeatedly issued invalid arguments for tool \`${toolCall.name}\`. This is usually an upstream model/tool-calling bug` + (recoverable ? " (the provider's stream returned empty tool-call arguments)" : "") + `. Your conversation is preserved; send another message or switch models to continue.`,
|
|
994
|
+
{
|
|
995
|
+
source: "provider",
|
|
996
|
+
hint: "This is the model/provider's fault, not a ezcoder bug. " + (recoverable ? "ezcoder already retried automatically once; if it recurs, send another message or switch models." : "Send another message or switch models to continue.")
|
|
997
|
+
}
|
|
998
|
+
),
|
|
999
|
+
recoverable,
|
|
1000
|
+
toolCall.name
|
|
956
1001
|
);
|
|
957
1002
|
}
|
|
958
1003
|
} else {
|