diff --git a/nanobot/agent/runner.py b/nanobot/agent/runner.py index a898936e..18e93aad 100644 --- a/nanobot/agent/runner.py +++ b/nanobot/agent/runner.py @@ -392,7 +392,6 @@ class AgentRunner: # Per-turn throttle for repeated attempts against the same outside target. workspace_violation_counts: dict[str, int] = {} empty_content_retries = 0 - length_recovery_count = 0 # Segments from one uninterrupted length-recovery chain. Tool work or # injected user input starts a new logical answer and clears the chain. length_recovery_parts: list[str] = [] @@ -520,7 +519,6 @@ class AgentRunner: ) if should_continue: had_injections = True - length_recovery_count = 0 length_recovery_parts.clear() continue break @@ -536,7 +534,6 @@ class AgentRunner: }, ) empty_content_retries = 0 - length_recovery_count = 0 length_recovery_parts.clear() # Checkpoint 1: drain injections after tools, before next LLM call _drained, injection_cycles = await self._try_drain_injections( @@ -590,8 +587,7 @@ class AgentRunner: clean = hook.finalize_content(context, response.content) if response.finish_reason == "length" and not is_blank_text(clean): - length_recovery_count += 1 - if length_recovery_count <= _MAX_LENGTH_RECOVERIES: + if len(length_recovery_parts) < _MAX_LENGTH_RECOVERIES: length_recovery_parts.append( _restore_outer_whitespace(clean, original_content) ) @@ -599,7 +595,7 @@ class AgentRunner: "Output truncated on turn {} for {} ({}/{}); continuing", iteration, spec.session_key or "default", - length_recovery_count, + len(length_recovery_parts), _MAX_LENGTH_RECOVERIES, ) if hook.wants_streaming(): @@ -637,7 +633,6 @@ class AgentRunner: await hook.on_stream_end(context, resuming=should_continue) if should_continue: - length_recovery_count = 0 length_recovery_parts.clear() await hook.after_iteration(context) continue @@ -660,7 +655,6 @@ class AgentRunner: ) if should_continue: had_injections = True - length_recovery_count = 0 length_recovery_parts.clear() continue break @@ -679,7 +673,6 @@ class AgentRunner: ) if should_continue: had_injections = True - length_recovery_count = 0 length_recovery_parts.clear() continue break