Hermes integration survives restarts, fix error hadling, increase turn length limit

This commit is contained in:
James Babcock committed 2026-10-17 13:52:43 -07:00
1 parent 825559aa82
commit de653f0fbb
6 files changed
+100 -9

No files matched your search

+10 -2
View File
@@ -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 {
+9 -3
View File
@@ -22,6 +22,8 @@ export type AssistantSessionHistory = {
transcript: AssistantTranscriptEntry[];
/** Model identity for safe replay after Auto resolves differently on restart. */
engine?: string;
/** The Hermes server-side session for this conversation (Hermes keeps the history). */
hermesSessionId?: string;
};
/** Which engine answers utterances, plus what it needs to do so. */
@@ -48,14 +50,18 @@ export class AssistantSession {
// API-safe tool name -> canonical registry name. Provider APIs restrict tool
// names, so dotted registry names are sanitized and mapped back on calls.
private readonly toolNameMap = new Map<string, string>();
// The Hermes server-side session for this conversation (Hermes keeps the history).
private readonly hermesSessionId = `faceclaw-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
// Saved with the history: Faceclaw only sends Hermes the latest message, so a
// restored conversation must keep addressing the same server-side session.
private readonly hermesSessionId: string;
constructor(
private config: AssistantBackendConfig,
private readonly registry: ToolRegistry = toolRegistry,
history?: AssistantSessionHistory,
) {
this.hermesSessionId = typeof history?.hermesSessionId === "string" && history.hermesSessionId
? history.hermesSessionId
: `faceclaw-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
if (history) {
this.messages.push(...history.messages);
this.transcript.push(...history.transcript);
@@ -75,7 +81,7 @@ export class AssistantSession {
}
history(): AssistantSessionHistory {
return { messages: this.messages, transcript: this.transcript, engine: this.engine() };
return { messages: this.messages, transcript: this.transcript, engine: this.engine(), hermesSessionId: this.hermesSessionId };
}
configure(config: AssistantBackendConfig): void {