The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(agent/credits,gemini): tighten docstrings
Teknium46f52ead2821
diff --git a/agent/credits_tracker.py b/agent/credits_tracker.pyindex eab8cf278e6..82e1b05217c 100644--- a/agent/credits_tracker.py+++ b/agent/credits_tracker.py@@ -306,9 +306,7 @@ def _fixture(remaining: str, subscription: str, limit: Optional[str] = None, purif limit is not None:d["denominator_kind"] = "subscription_cap"d["paid_access"] = paid- if reason is not None:- d["disabled_reason"] = reason- return d+ return d if reason is None else {**d, "disabled_reason": reason}_DEV_FIXTURES: dict[str, dict] = {@@ -326,9 +324,8 @@ _DEV_FIXTURES: dict[str, dict] = {def dev_fixture_credits_state() -> Optional[CreditsState]:- """Fixture CreditsState for HERMES_DEV_CREDITS_FIXTURE, or None (unknown name / unset).- Prod-leak guard: applies ONLY when HERMES_DEV_CREDITS is also on, so a stray- fixture env var can never surface fabricated balances on a real account."""+ """Fixture CreditsState for HERMES_DEV_CREDITS_FIXTURE, or None (unknown name / unset). Prod-leak guard:+ applies ONLY when HERMES_DEV_CREDITS is also on, so a stray fixture env var never surfaces fabricated balances."""name = os.environ.get("HERMES_DEV_CREDITS_FIXTURE", "").strip()if not name or not is_truthy_value(os.environ.get("HERMES_DEV_CREDITS")):return None@@ -346,9 +343,8 @@ def dev_fixture_credits_state() -> Optional[CreditsState]:def _credits_state_from_account(info) -> Optional[CreditsState]:- """Map a NousPortalAccountInfo into a header-shaped CreditsState for the seed.- Float account dollars → micros plus a DISPLAY *_usd (formatting account floats- is allowed; parsing a server *_usd is not). Fail-open → None."""+ """Map a NousPortalAccountInfo into a header-shaped CreditsState for the seed. Float account dollars →+ micros plus a DISPLAY *_usd (formatting account floats is allowed; parsing a server *_usd is not). Fail-open → None."""try:acc = getattr(info, "paid_service_access_info", None)sub = getattr(info, "subscription", None)@@ -373,9 +369,8 @@ def _credits_state_from_account(info) -> Optional[CreditsState]:def _hydrate_seed_state(agent, state) -> None:- """Install a seed CreditsState on the agent and fire the notice policy once.- Primes the crossing gate: the cold-start snapshot IS the first observation, so- a session opening in a band warns immediately. Safe from a worker thread."""+ """Install a seed CreditsState on the agent and fire the notice policy once. Primes the crossing gate:+ the cold-start snapshot IS the first observation, so a session opening in a band warns immediately."""agent._credits_state = stateif getattr(agent, "_credits_session_start_micros", None) is None:agent._credits_session_start_micros = state.remaining_micros@@ -387,10 +382,9 @@ def _hydrate_seed_state(agent, state) -> None:def seed_credits_at_session_start(agent) -> bool:- """Hydrate agent._credits_state from the portal account (or a dev fixture) and- fire the notice policy so warnings show at session OPEN (TUI/desktop "ready" and- plain-CLI first-turn setup). Idempotent once a seed or real header populated- _credits_state. Returns True iff it seeded this call. Never raises."""+ """Hydrate agent._credits_state from the portal account (or a dev fixture) and fire the notice policy so+ warnings show at session OPEN (TUI/desktop "ready" and plain-CLI first-turn setup). Idempotent once a seed+ or real header populated _credits_state. Returns True iff it seeded this call. Never raises."""try:if getattr(agent, "provider", "") != "nous" or getattr(agent, "_credits_state", None) is not None:return Falsediff --git a/agent/gemini_native_adapter.py b/agent/gemini_native_adapter.pyindex 0353623b62b..13611ef41ed 100644--- a/agent/gemini_native_adapter.py+++ b/agent/gemini_native_adapter.py@@ -257,13 +257,12 @@ def _has_function_response(content: Dict[str, Any]) -> bool:def _merge_alternating(contents: List[Dict[str, Any]]) -> List[Dict[str, Any]]:- """Alternation contract for generateContent: 1) adjacent same-role contents merge- (else HTTP 400 "multiturn requests [must] alternate"); 2) EXCEPT never fuse a human- user text turn into a preceding user content that only carries functionResponse- parts (or vice versa) — Gemini 3 accepts the fold but reads the text as a- continuation of the tool result and returns an empty candidate (parallel- functionResponse + functionResponse still merge); 3) the split pair stays API-valid- via an interposed placeholder model turn."""+ """Alternation contract for generateContent: 1) adjacent same-role contents merge (else HTTP 400+ "multiturn requests [must] alternate"); 2) EXCEPT never fuse a human user text turn into a preceding+ user content that only carries functionResponse parts (or vice versa) — Gemini 3 accepts the fold but+ reads the text as a continuation of the tool result and returns an empty candidate (parallel+ functionResponse + functionResponse still merge); 3) the split pair stays API-valid via an interposed+ placeholder model turn."""merged: List[Dict[str, Any]] = []for content in contents:prev = merged[-1] if merged else None@@ -350,9 +349,8 @@ def _normalize_thinking_config(config: Any) -> Optional[Dict[str, Any]]:def _thinking_requests_output_headroom(thinking_config: Any) -> bool:- """True when Gemini will spend output tokens on thinking: thought tokens bill against- ``maxOutputTokens``, so a global 4096/16384 cap can be consumed entirely by high- thinking, leaving ``finishReason=MAX_TOKENS`` with no answer."""+ """True when Gemini will spend output tokens on thinking: thought tokens bill against ``maxOutputTokens``,+ so a global 4096/16384 cap can be consumed entirely by high thinking (``finishReason=MAX_TOKENS``, no answer)."""normalized = _normalize_thinking_config(thinking_config) or {}budget, has_level = normalized.get("thinkingBudget"), "thinkingLevel" in normalizedif normalized.get("includeThoughts") is False: