Skip to main content

Module streaming

Module streaming 

Source
Expand description

Streaming response state and guardrails (P2 PR4 → zagens-core).

Structs§

ToolUseState

Enums§

ContentBlockKind

Constants§

FAKE_WRAPPER_NOTICE
MAX_CONTEXT_CYCLE_HANDOFFS
Max times an in-flight turn whose context overflows the model budget (and can’t be brought back under it by emergency compaction within MAX_CONTEXT_RECOVERY_ATTEMPTS) may roll a long-horizon cycle handoff instead of hard-failing the turn. A handoff swaps the bloated message buffer for a small <carry_forward> briefing seed plus preserved structured state, so the next step starts with room to spare. Kept tiny: if even a fresh briefing seed can’t fit, the task is genuinely too large and we fall back to the hard failure.
MAX_IN_TURN_CYCLE_ADVANCES
Max clean in-turn cycle advances at a per-step safe boundary. The cycle threshold / long-horizon early-advance band is normally only evaluated between turns; a long-horizon turn that loops many tool steps without returning never reaches that boundary, so a turn crossing ~75% would only get the hard-overflow emergency handoff (MAX_CONTEXT_CYCLE_HANDOFFS), never a clean early refresh. Evaluating the gate after each completed tool step closes that gap. Each clean advance resets context to a small briefing seed (so the gate won’t immediately re-fire); this bound is the safety net against a pathological seed that itself stays over threshold. Generous — a genuinely long turn may legitimately refresh several times.
MAX_LENGTH_CONTINUATIONS
Max consecutive auto-continuations after the model hits the output max_tokens cap (finish_reason=length) with no tool call to carry the turn. Bounds runaway cost / an infinite cut→continue loop while still letting a genuinely huge answer (or reasoning) finish across several rounds. Reset to 0 on any step that does not end in a length truncation.
MAX_LOOP_GUARD_CONTINUATIONS
Max times a long-horizon turn whose LoopGuard halts (a tool failed FAILURE_HALT_THRESHOLD consecutive times) may be granted a “change approach” continuation instead of silently ending the turn as Completed. Kept small — a halt means the model is genuinely stuck, so we reset the failure counters and nudge it to switch strategy at most this many times before accepting the stop.
MAX_STEP_LIMIT_CONTINUATIONS
Max times a long-horizon turn that exhausts its max_steps budget may be granted another full step window to keep pursuing an incomplete task graph, instead of silently ending at the step cap (step-exhaustion early-stop). Each grant extends the budget by the original max_steps; bounded so a runaway task can’t loop forever (e.g. 3 → up to 4× the base step budget).
MAX_STREAM_ERRORS_BEFORE_FAIL
MAX_STREAM_RETRIES
Outer turn-step retries when a stream dies with no actionable content (#103).
MAX_TRANSPARENT_STREAM_RETRIES
STREAM_CHUNK_TIMEOUT_SECS
STREAM_MAX_CONTENT_BYTES
STREAM_MAX_DURATION_SECS
TOOL_CALL_END_MARKERS
TOOL_CALL_START_MARKERS

Functions§

contains_fake_tool_wrapper
filter_tool_call_delta
should_transparently_retry_stream