fix(gateway): refresh cached agent max_iterations from current config

When a gateway agent is reused from cache, it retains the max_iterations
from its initial creation. If config.yaml agent.max_turns or HERMES_MAX_ITERATIONS
changed between turns, the cached agent's budget becomes stale.

Before reusing a cached agent, refresh agent.max_iterations from the
freshly-resolved value (read from env/config at line 14585).

Fixes partial issue from PR #48127: handles fresh agent creation + cached agent reuse.
This commit is contained in:
infinitycrew39 2026-06-19 10:50:30 +07:00 committed by Teknium
parent dcac719527
commit ca92e9a362

View file

@ -14802,6 +14802,9 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew
except KeyError:
pass
self._init_cached_agent_for_turn(agent, _interrupt_depth)
# Refresh agent max_iterations from current config
# (cached agent may have been created with old config)
agent.max_iterations = max_iterations
logger.debug("Reusing cached agent for session %s", session_key)
if agent is None: