diff --git a/agent/conversation_loop.py b/agent/conversation_loop.py index e34631377e4..1361d6ed6e6 100644 --- a/agent/conversation_loop.py +++ b/agent/conversation_loop.py @@ -484,7 +484,8 @@ def run_conversation( tools=agent.tools or None, ) - if _preflight_tokens >= agent.context_compressor.threshold_tokens: + if _preflight_tokens >= agent.context_compressor.threshold_tokens \ + and agent.context_compressor.should_compress(_preflight_tokens): logger.info( "Preflight compression: ~%s tokens >= %s threshold (model %s, ctx %s)", f"{_preflight_tokens:,}", @@ -4180,6 +4181,7 @@ def run_conversation( "estimated_cost_usd": agent.session_estimated_cost_usd, "cost_status": agent.session_cost_status, "cost_source": agent.session_cost_source, + "session_id": agent.session_id, } if agent._tool_guardrail_halt_decision is not None: result["guardrail"] = agent._tool_guardrail_halt_decision.to_metadata() diff --git a/gateway/run.py b/gateway/run.py index cb8b60e556d..675774022e3 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -8692,6 +8692,7 @@ class GatewayRunner: # session_entry so transcript writes below go to the right session. if agent_result.get("session_id") and agent_result["session_id"] != session_entry.session_id: session_entry.session_id = agent_result["session_id"] + self.session_store._save() # Prepend reasoning/thinking if display is enabled (per-platform) try: