forked from Blendman974/faceclaw
Hermes integration survives restarts, fix error hadling, increase turn length limit
This commit is contained in:
1 parent
825559aa82
commit
de653f0fbb
6 files changed
+100
-9
No files matched your search
@@ -25,6 +25,13 @@ const MAX_ITERATIONS = 8;
|
||||
/** The on-phone model is slower per step and unreliable on long tool chains. */
|
||||
const MAX_ITERATIONS_LOCAL = 4;
|
||||
const MAX_TURN_MS = 2 * 60 * 1000;
|
||||
/**
|
||||
* Hermes runs whole multi-tool agent tasks in one request, and dropping the
|
||||
* stream interrupts the run on the server, so its cap is only a backstop. A
|
||||
* dead server is caught sooner: Hermes sends keepalives every 10s, and both
|
||||
* transports fail a stream that goes quiet for 180s.
|
||||
*/
|
||||
const MAX_TURN_MS_HERMES = 20 * 60 * 1000;
|
||||
|
||||
export type DirectTurnOptions = {
|
||||
provider: AssistantProvider;
|
||||
@@ -66,13 +73,14 @@ export class DirectAssistantBackend {
|
||||
};
|
||||
|
||||
const maxIterations = options.provider === "local" ? MAX_ITERATIONS_LOCAL : MAX_ITERATIONS;
|
||||
const maxTurnMs = options.provider === "hermes" ? MAX_TURN_MS_HERMES : MAX_TURN_MS;
|
||||
const runIteration = (iteration: number): void => {
|
||||
if (cancelled) return;
|
||||
if (iteration >= maxIterations) {
|
||||
finishError("Assistant stopped: too many tool steps");
|
||||
return;
|
||||
}
|
||||
if (Date.now() - startMs > MAX_TURN_MS) {
|
||||
if (Date.now() - startMs > maxTurnMs) {
|
||||
finishError("Assistant stopped: turn took too long");
|
||||
return;
|
||||
}
|
||||
@@ -142,7 +150,7 @@ export class DirectAssistantBackend {
|
||||
: streamAnthropicMessage(streamOptions);
|
||||
};
|
||||
|
||||
deadline = setTimeout(() => finishError("Assistant stopped: turn took too long"), MAX_TURN_MS);
|
||||
deadline = setTimeout(() => finishError("Assistant stopped: turn took too long"), maxTurnMs);
|
||||
runIteration(0);
|
||||
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user