From 551e1c6d6470a0911dabd9e0d1a756ca2f86e8b1 Mon Sep 17 00:00:00 2001 From: kshitijk4poor Date: Tue, 28 Jul 2026 00:29:17 +0500 Subject: [PATCH] refactor(agent): direct flag access in redecoration, matching call-block site The call-block decoration reads agent._use_prompt_caching / _cache_ttl / _use_native_cache_layout directly; the redecoration helper wrapped each in getattr with divergent defaults (e.g. or-'5m' vs verbatim _cache_ttl). The flags are unconditionally initialized on AIAgent, so the defaults served only test fixtures and would mask a real init bug as silent cache-off. Align with the house style. --- agent/conversation_loop.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/agent/conversation_loop.py b/agent/conversation_loop.py index 4ab337238dce..6b5d4d6ad975 100644 --- a/agent/conversation_loop.py +++ b/agent/conversation_loop.py @@ -887,13 +887,16 @@ def _redecorate_prompt_cache_for_provider( strip_anthropic_cache_control(messages) - if getattr(agent, "_use_prompt_caching", False): + # Direct attribute access matches the call-block decoration site — the + # flags are unconditionally initialized on AIAgent, and a getattr + # default here would mask a real init bug as silent cache-off. + if agent._use_prompt_caching: _ensure_cached_system_prompt_static(agent, system_message=system_message) static = getattr(agent, "_cached_system_prompt_static", None) messages = apply_anthropic_cache_control( messages, - cache_ttl=getattr(agent, "_cache_ttl", None) or "5m", - native_anthropic=bool(getattr(agent, "_use_native_cache_layout", False)), + cache_ttl=agent._cache_ttl, + native_anthropic=agent._use_native_cache_layout, static_system_prefix=static if isinstance(static, str) else None, )