@sema-agent/core 1.442.0 → 1.443.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.
|
@@ -2,7 +2,7 @@ import { type AgentCoreStreamRuntimeDeps } from "./runtime-deps.js";
|
|
|
2
2
|
import type { AgentContext, AgentEvent, AgentLoopConfig, AgentMessage, StreamFn } from "./types.js";
|
|
3
3
|
export type AgentEventSink = (event: AgentEvent) => Promise<void> | void;
|
|
4
4
|
export type LoopContinueReason = "next_turn" | "steer_injected" | "follow_up_injected" | "reactive_compact_retry" | "max_output_tokens_recovery" | "malformed_tool_use_retry" | "thinking_only_retry" | "midstream_partial_recovery" | "degenerate_output_recovery" | "walltime_cutoff_recovery";
|
|
5
|
-
export type LoopTerminalReason = "completed" | "aborted_before_stream" | "assistant_error" | "stop_requested";
|
|
5
|
+
export type LoopTerminalReason = "completed" | "aborted_before_stream" | "assistant_error" | "stop_requested" | "malformed_tool_use_exhausted";
|
|
6
6
|
export type LoopStep = {
|
|
7
7
|
kind: "continue";
|
|
8
8
|
reason: LoopContinueReason;
|
|
@@ -402,14 +402,14 @@ async function runSingleTurn(state, signal, emit, streamFn, runtime, trace) {
|
|
|
402
402
|
state.midstreamPartialContinues = 0;
|
|
403
403
|
}
|
|
404
404
|
const malformed = state.config.recovery?.malformedToolUse;
|
|
405
|
-
if (malformed &&
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
state.
|
|
412
|
-
return { kind: "
|
|
405
|
+
if (malformed && message.stopReason === "toolUse" && toolCalls.length === 0 && state.pendingMessages.length === 0) {
|
|
406
|
+
if (state.malformedToolUseRetries < (malformed.maxRetries ?? 1)) {
|
|
407
|
+
state.malformedToolUseRetries++;
|
|
408
|
+
state.pendingMessages = [createMalformedToolUseNudge()];
|
|
409
|
+
return { kind: "ran", recovered: "malformed_tool_use_retry" };
|
|
410
|
+
}
|
|
411
|
+
await emit({ type: "agent_end", messages: state.newMessages });
|
|
412
|
+
return { kind: "terminal", reason: "malformed_tool_use_exhausted" };
|
|
413
413
|
}
|
|
414
414
|
const thinkingOnly = state.config.recovery?.thinkingOnly;
|
|
415
415
|
if (thinkingOnly &&
|