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.
This commit is contained in:
kshitijk4poor 2026-07-28 00:29:17 +05:00 committed by kshitij
parent 708390f47d
commit 551e1c6d64

View file

@ -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,
)