refactor(agent): module-level _refund_api_call import; int verdict count (#77305)
turn_context_compaction imports neither conversation_loop nor turn_empty_response, so the function-local import is not guarding a cycle. The helper's docstring now also covers the provider-switch fallback hop that reached the provider.
This commit is contained in:
@@ -101,7 +101,8 @@ def _apply_grown_window(agent: Any, compressor: Any, grown: int) -> None:
|
||||
|
||||
|
||||
def _refund_api_call(agent: Any, api_call_count: int) -> int:
|
||||
"""A pass that never reached the provider refunds the call count and budget."""
|
||||
"""Refund the call count and iteration budget for a pass that should not consume it:
|
||||
one that never reached the provider (preflight) or a provider-switch fallback hop."""
|
||||
# Host progress-aware timeout (#98722, salvaged from #98741): this preflight iteration never reached the
|
||||
# provider. Refund its provisional call/budget exactly like a successful pre-API compaction, then stop
|
||||
# before the unchanged oversized request reaches the provider — its overflow error would only invoke
|
||||
|
||||
@@ -16,6 +16,7 @@ from typing import Any, Dict, List, Optional
|
||||
|
||||
from agent import empty_response_guard as _empty_guard
|
||||
from agent.message_metadata import append_message
|
||||
from agent.turn_context_compaction import _refund_api_call
|
||||
from agent.turn_failure_copy import site_copy
|
||||
from agent.turn_recovery import interruptible_backoff_sleep
|
||||
|
||||
@@ -283,7 +284,6 @@ def recover_empty_response(
|
||||
_preflight_compression_blocked = False
|
||||
# The fallback hop is a provider switch, not a model turn: refund the empty
|
||||
# call so a mid-turn fallback doesn't eat the iteration budget (#77305).
|
||||
from agent.turn_context_compaction import _refund_api_call
|
||||
api_call_count = _refund_api_call(agent, api_call_count)
|
||||
return _verdict("continue")
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class FinalResponseVerdict:
|
||||
length_continue_retries: Any
|
||||
_pending_verification_response: Any
|
||||
_pending_verification_response_previewed: Any
|
||||
api_call_count: Any
|
||||
api_call_count: int
|
||||
result: Optional[Dict[str, Any]] = None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user