The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(agent/thinking_timeout_guidance,reactions,reasoning_summaries): compact docstrings, merged guards
Tekniume27609e18efd
diff --git a/agent/reactions.py b/agent/reactions.pyindex e6c565db7f5..d1a97194bbb 100644--- a/agent/reactions.py+++ b/agent/reactions.py@@ -1,12 +1,10 @@-"""Token-free detection of user *reactions* to the agent.+"""Token-free (regex) detection of user *reactions* to the agent.-The only reaction today is ``vibe`` — affection/gratitude aimed at the agent-(``ily``, ``<3``, ``good bot``, a heart emoji). Detection is a curated regex:-no model call. Single source of truth for the CLI pet, TUI heart and desktop-hearts via ``AIAgent.reaction_callback``. :func:`detect_reaction` returns a-*kind* string so new kinds can be added without touching callers. Matches-affection specifically, not general positive sentiment ("this is great" does-NOT fire).+The only kind today is ``vibe`` — affection/gratitude aimed at the agent (``ily``, ``<3``,+``good bot``, a heart emoji), NOT general positive sentiment ("this is great" does not fire).+Single source of truth for the CLI pet, TUI heart and desktop hearts via+``AIAgent.reaction_callback``; :func:`detect_reaction` returns a *kind* string so new kinds+can be added without touching callers."""from __future__ import annotationsdiff --git a/agent/reasoning_summaries.py b/agent/reasoning_summaries.pyindex eeeaae12890..5003d4bded2 100644--- a/agent/reasoning_summaries.py+++ b/agent/reasoning_summaries.py@@ -1,13 +1,11 @@"""Boundary repair for providers that stream reasoning as discrete summary parts.-Reasoning-summary models (OpenAI gpt-5.x and anything relaying the Responses-API onto the OpenAI chat wire) emit one ``reasoning_content`` delta per-*completed* summary part, each opening with a bold heading. The Responses API-delimits parts by ``summary_index``; the chat wire carries no such field-(verified live on Nous Portal ``openai/gpt-5.6-sol``), so concatenating deltas-glues ``**One****Two**`` into one half-bold paragraph. We re-derive the-boundary from the one signal the wire keeps — a delta opening a bold heading —-matching the blank-line join Hermes' own Responses adapter already does.+Reasoning-summary models (OpenAI gpt-5.x and Responses-API relays onto the chat wire) emit one+``reasoning_content`` delta per *completed* summary part, each opening with a bold heading.+The chat wire lacks the Responses API's ``summary_index`` delimiter (verified live on Nous+Portal ``openai/gpt-5.6-sol``), so plain concatenation glues ``**One****Two**`` into one+half-bold paragraph. The boundary is re-derived from a delta opening a bold heading, matching+the blank-line join Hermes' own Responses adapter does."""from __future__ import annotations@@ -18,20 +16,13 @@ __all__ = ["separate_glued_reasoning_blocks"]def separate_glued_reasoning_blocks(previous: str, delta: str) -> str:"""Return *delta*, prefixed with a paragraph break when it glues onto *previous*.- A break is inserted when *delta* opens a *closed* bold heading and- *previous* (the accumulated reasoning; only its tail matters) is mid-line.- Covers a heading butting a heading (``**One****Two**``) and prose butting a- heading (``...interaction!**Next**``). Token-streamed reasoning is left- alone: its deltas carry their own whitespace, and a fragment that merely- opens emphasis (``**`` alone) is not a part boundary — summary parts always- carry the whole heading in one delta.+ A break is inserted when *delta* opens a *closed* bold heading and *previous* is mid-line+ (heading butting heading, or prose butting heading). Token-streamed reasoning is left+ alone: its deltas carry their own whitespace, and a fragment that merely opens emphasis+ (``**`` alone) is not a part boundary — summary parts carry the whole heading in one delta."""- if not previous or not delta:+ if not previous or not delta or previous[-1].isspace():return delta- if not delta.startswith("**"):- return delta- if previous[-1].isspace():- return delta- if "**" not in delta[2:]:+ if not delta.startswith("**") or "**" not in delta[2:]:return deltareturn f"\n\n{delta}"diff --git a/agent/thinking_timeout_guidance.py b/agent/thinking_timeout_guidance.pyindex 0801014ff9a..1bc28e12aae 100644--- a/agent/thinking_timeout_guidance.py+++ b/agent/thinking_timeout_guidance.py@@ -1,11 +1,8 @@"""Thinking-timeout detection and user-facing guidance for reasoning models.-When a known reasoning model hits a transport-layer error before the first-content token, the upstream proxy has almost certainly idle-killed a long-thinking stream — not a context overflow or configuration error. The generic-stream-drop guidance in conversation_loop ("use execute_code for large files")-is wrong for that case, so detection and message live here as standalone,-unit-testable helpers.+A known reasoning model hitting a transport-layer error before the first content token was+almost certainly idle-killed mid-think by the upstream proxy — not a context overflow — so+the generic stream-drop guidance in conversation_loop is wrong for that case."""from __future__ import annotations@@ -13,29 +10,21 @@ from __future__ import annotationsfrom typing import Optional-# Transport-layer failure signatures on the response stream — the classifier's-# server-disconnect set plus the OS-level ``broken pipe`` / ``errno 32`` the-# upstream kill surfaces through the OpenAI SDK wrapper.+# Transport-layer failure signatures: the classifier's server-disconnect set plus the OS-level+# ``broken pipe`` / ``errno 32`` the upstream kill surfaces through the OpenAI SDK wrapper._THINKING_TIMEOUT_SUBSTRINGS: tuple[str, ...] = (- "broken pipe",- "errno 32",- "remote protocol",- "connection reset",- "connection lost",- "peer closed",- "server disconnected",+ "broken pipe", "errno 32", "remote protocol", "connection reset", "connection lost",+ "peer closed", "server disconnected",)def is_thinking_timeout(classified: object, model: str, error_msg: str) -> bool:"""True when a reasoning model's thinking phase hit a transport kill.- All must hold: ``classified.reason`` is the ``timeout`` FailoverReason- (duck-typed via ``.value`` to avoid importing error_classifier), ``model``- is in the reasoning allowlist (``reasoning_timeouts``), and ``error_msg``- carries a transport-kill substring. The caller gates on the error having no- HTTP ``status_code`` before calling. Non-reasoning models and non-transport- errors (billing / rate_limit / auth / context_overflow) return False.+ All must hold: ``classified.reason`` is the ``timeout`` FailoverReason (duck-typed via+ ``.value`` to avoid importing error_classifier), ``model`` is in the reasoning allowlist,+ and ``error_msg`` carries a transport-kill substring. The caller gates on the error having+ no HTTP ``status_code``."""from agent.reasoning_timeouts import get_reasoning_stale_timeout_floor@@ -51,12 +40,8 @@ def is_thinking_timeout(classified: object, model: str, error_msg: str) -> bool:def build_thinking_timeout_guidance(provider: str, model: str, model_label: Optional[str] = None,) -> str:- """User-facing guidance appended to the final response.-- ``model`` is used verbatim in the config snippet so it is copy-pasteable- (bare slug for direct providers, ``vendor/slug`` through aggregators);- ``model_label`` is the optional prose name, defaulting to the slug.- """+ """User-facing guidance appended to the final response. ``model`` is used verbatim in+ the config snippet so it is copy-pasteable; ``model_label`` is the optional prose name."""label = model_label or modelreturn ("\n\nThe model's thinking phase exceeded the upstream proxy's "