The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): report the conversation category even when it is empty
jackulau9f5440e23d23
diff --git a/agent/context_breakdown.py b/agent/context_breakdown.pyindex 36bb21eee5c..1eacaa75b2f 100644--- a/agent/context_breakdown.py+++ b/agent/context_breakdown.py@@ -14,6 +14,23 @@ from typing import Any, Dict, List, Optional, Sequence, Tuple_SKILLS_BLOCK_RE = re.compile(r"<available_skills>.*?</available_skills>", re.DOTALL)_SUBAGENT_TOOL_NAMES = frozenset({"delegate_task"})+# A category at zero tokens is dropped from the payload, which reads as "not+# configured" - true for MCP, memory and skills, and false for the+# conversation. Every session has one, so hiding the row at zero makes an empty+# transcript indistinguishable from a breakdown that never measured it (#87903).+#+# The membership rule, stated so a later addition argues from the same+# principle rather than from "this one felt important": a category belongs+# here when zero is a MEASUREMENT of something every session has, not the+# ABSENCE of something optional. "conversation" qualifies because a session+# cannot not have a transcript, so zero means "nothing said yet" and is worth+# showing. "mcp", "memory", "skills" and "subagent_definitions" do not: zero+# there means the user configured none, which is what dropping the row already+# communicates, and a permanent 0-token row would be noise on most hosts.+# "system_prompt" and "tool_definitions" are always present too but are never+# zero in practice, so adding them would buy nothing.+_ALWAYS_REPORTED = frozenset({"conversation"})+# id -> (label, dashboard color, /context glyph); declaration order is display order._CATEGORIES = {"system_prompt": ("System prompt", "var(--context-usage-system)", "■"),@@ -172,7 +189,7 @@ def compute_session_context_breakdown(agent: Any, messages: Optional[List[dict]]"categories": [{"color": color, "id": category_id, "label": label, "tokens": tokens_by_id[category_id]}for category_id, (label, color, _glyph_) in _CATEGORIES.items()- if tokens_by_id[category_id] > 0+ if tokens_by_id[category_id] > 0 or category_id in _ALWAYS_REPORTED],"context_max": context_max,"context_percent": max(0, min(100, round(context_used / context_max * 100))) if context_max else 0,diff --git a/tests/agent/test_context_breakdown.py b/tests/agent/test_context_breakdown.pyindex 7f37b8e3b27..b00fc6df1ce 100644--- a/tests/agent/test_context_breakdown.py+++ b/tests/agent/test_context_breakdown.py@@ -69,6 +69,30 @@ def test_context_used_never_exceeds_model_window():last_real_prompt_tokens=150_000))assert seeded["context_used"] <= seeded["context_max"]+def test_empty_transcript_still_reports_the_conversation_category():+ """Zero conversation tokens is a measurement, not an absence (#87903).++ A fresh session (or one whose first turn never completed) estimates the+ conversation at zero. Dropping the row there made "the transcript is empty"+ render identically to "the breakdown never measured it" — the Desktop+ Context usage panel hid Conversation until a turn completed. Structurally+ absent categories (mcp/memory/skills with nothing configured) stay dropped.+ """+ agent, parts = _make_agent(+ tools=[{"type": "function", "function": {"name": "terminal", "description": "run"}}]+ )+ history = [] # nothing said yet++ with patch("agent.system_prompt.build_system_prompt_parts", return_value=parts):+ data = compute_session_context_breakdown(agent, history)++ categories = {item["id"]: item["tokens"] for item in data["categories"]}+ assert categories["conversation"] == 0+ # Optional surfaces with nothing configured are still omitted at zero —+ # "not configured" is exactly what their absence communicates.+ assert "mcp" not in categories+ assert "skills" not in categories+# ── /context renderers (pure functions over the payload) ────────────────────from agent.context_breakdown import ( # noqa: E402