The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(gateway): give _pinned_channel_inputs explicit inputs
kshitijk4poore3ffee06f209
diff --git a/gateway/run_agent_cache.py b/gateway/run_agent_cache.pyindex 6b3b428a54e..e186721223c 100644--- a/gateway/run_agent_cache.py+++ b/gateway/run_agent_cache.py@@ -641,7 +641,9 @@ class GatewayAgentCacheMixin:self._session_state(session_key).conversation.ephemeral_pin = (_eph_key, text)return text- def _pinned_channel_inputs(self, session_key, event, source):+ def _pinned_channel_inputs(+ self, session_key: Optional[str], channel_prompt: Optional[str], source: SessionSource, *, internal: bool,+ ):"""``(channel_prompt, source)`` for this turn's agent run.The ephemeral system prompt also appends ``channel_prompt`` and the ``channel_overrides``@@ -649,20 +651,17 @@ class GatewayAgentCacheMixin:``channel_prompt=None`` and a source without ``parent_chat_id``, so they dropped both andtoggled the system prompt like the context pin did. Human turns record their inputs;internal turns reuse them."""- channel_prompt = getattr(event, "channel_prompt", None)if not session_key:return channel_prompt, source- if not getattr(event, "internal", False):- self._session_state(session_key).conversation.channel_pin = (- channel_prompt, getattr(source, "parent_chat_id", None),- )+ if not internal:+ self._session_state(session_key).conversation.channel_pin = (channel_prompt, source.parent_chat_id)return channel_prompt, sourcestate = self._peek_session_state(session_key)pin = state.conversation.channel_pin if state else Noneif pin is None:return channel_prompt, sourcepinned_prompt, pinned_parent = pin- if pinned_parent and not getattr(source, "parent_chat_id", None):+ if pinned_parent and not source.parent_chat_id:from gateway.session_identity import replace_sourcesource = replace_source(source, parent_chat_id=pinned_parent)return pinned_prompt, sourcediff --git a/gateway/run_turn.py b/gateway/run_turn.pyindex 405ffe46536..da34ab6b7ae 100644--- a/gateway/run_turn.py+++ b/gateway/run_turn.py@@ -2088,7 +2088,7 @@ class GatewayTurnMixin:# The context prompt render is pinned per session, keyed by a hash of the renderer inputs, so# the system prompt cannot drift turn-over-turn; a miss (thread rename, /sethome) re-renders.context_prompt = self._pinned_session_context_prompt(- context, _redact_pii, session_key, internal=bool(getattr(event, "internal", False)),+ context, _redact_pii, session_key, internal=event.internal,)# Per-turn notes ride the user message via the api_content sidecar, NOT context_prompt@@ -2208,7 +2208,9 @@ class GatewayTurnMixin:# turn preparation gates have passed when the agent runner is entered.event._heartbeat_execution_started = True# Internal events reuse the last human turn's channel inputs (see _pinned_channel_inputs).- _turn_channel_prompt, _turn_source = self._pinned_channel_inputs(session_key, event, source)+ _turn_channel_prompt, _turn_source = self._pinned_channel_inputs(+ session_key, event.channel_prompt, source, internal=event.internal,+ )agent_result = await self._run_agent(message=message_text, context_prompt=prepared.context_prompt, history=history, source=_turn_source,session_id=_run_start_session_id, session_key=session_key,@@ -3877,7 +3879,7 @@ class GatewayTurnMixin:next_message_id = self._reply_anchor_for_event(pending_event)next_inbound_id = str(pending_event.message_id) if getattr(pending_event, "message_id", None) else Nonenext_channel_prompt, next_source = self._pinned_channel_inputs(- next_session_key, pending_event, next_source,+ next_session_key, pending_event.channel_prompt, next_source, internal=pending_event.internal,)next_message_type = getattr(pending_event, "message_type", None)