Skip to content

The agent that grows with you

refactor(agent): module-level _refund_api_call import; int verdict count (#77305)

kshitijk4poor3ac22a309baf
diff --git a/agent/turn_context_compaction.py b/agent/turn_context_compaction.py
index 939ecaa92df..54678deb4f7 100644
--- a/agent/turn_context_compaction.py
+++ b/agent/turn_context_compaction.py
@@ -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
diff --git a/agent/turn_empty_response.py b/agent/turn_empty_response.py
index 17ba5da230a..92339b18d4b 100644
--- a/agent/turn_empty_response.py
+++ b/agent/turn_empty_response.py
@@ -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")
diff --git a/agent/turn_final_response.py b/agent/turn_final_response.py
index 421a1bc5b9b..84fba083dec 100644
--- a/agent/turn_final_response.py
+++ b/agent/turn_final_response.py
@@ -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