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