Ë
    áß²j=  ã                  óä   — U d Z ddlmZ ddlZddlmZmZmZ ddlm	Z	  ej                  e«      ZdZ e«       Zded<   h d	£Zdd
„Zdd„Zdd„Zdd„Z	 	 	 	 	 	 	 	 	 	 dd„Z	 d	 	 	 	 	 	 	 	 	 	 	 dd„Zy)uÏ  Reasoning floor for auxiliary requests: when a route refuses to switch reasoning OFF, step it UP.

Aux lanes that want speed over thought (title generation: ``max_tokens=64``, JSON body) send the
provider's thinking-off encoding â€” top-level ``reasoning_effort: "none"`` on the custom profile,
``extra_body.reasoning: {"enabled": false}`` on OpenRouter-shaped relays, ``_reasoning_config`` on the
Anthropic Messages adapters. Some endpoints understand the field but refuse the disable ("Reasoning is
mandatory for this endpoint and cannot be disabled" â€” the Nous Portal on gpt-6-astra); before this
module every title call there 400'd and the session stayed untitled.

The recovery is a *step up*, not a strip: the same request goes out again at the lowest effort every
reasoning wire accepts (``low``; ``minimal`` is rejected by o-series and Claude), and the (route, model)
pair is memoised so the next disabled-reasoning aux call on it starts at the floor instead of burning
the guaranteed 400 first. Dropping the field would also succeed once, but it says nothing about the
next call and hands the effort choice back to the provider default (often ``medium`` or higher, the
opposite of what a thinking-off caller asked for).
é    )ÚannotationsN)ÚAnyÚDictÚOptional)ÚurlparseÚlowzset[tuple[str, str]]Ú_FLOORED_ROUTES>   Ú0ÚoffÚnoneÚfalseÚdisabledc                ó²   — t        |xs d«      j                  xs dj                  «       xs+ t        | xs d«      j	                  «       j                  «       S )u³   Endpoint host:port when known (a base_url override turns a named provider into ``custom``), else
    the provider name â€” the same key shape ``auxiliary_structured_output`` uses.Ú )r   ÚnetlocÚlowerÚstrÚstrip)ÚproviderÚbase_urls     úD/home/ubuntu/.hermes/hermes-agent/agent/auxiliary_reasoning_floor.pyÚ
_route_keyr   !   sG   € ô �X’^ Ó$×+Ñ+Ò1¨r×8Ñ8Ó:Òa¼cÀ(Â.ÈbÓ>Q×>WÑ>WÓ>Y×>_Ñ>_Ó>aÐaó    c                óL   — t        | t        «      xr | j                  d«      du S )NÚenabledF)Ú
isinstanceÚdictÚget©Úreasoning_configs    r   Ú_is_disabledr!   '   s'   € ÜÐ&¬Ó-ÒZÐ2B×2FÑ2FÀyÓ2QÐUZÐ2ZÐZr   c                ó.   — t        | «      r	dt        dœS | S )z]The caller's disabled ``reasoning_config`` lifted to the floor; anything else returned as-is.T©r   Úeffort)r!   ÚREASONING_FLOOR_EFFORTr   s    r   Úfloor_reasoning_configr&   +   s   € äÐ$Ô%ØÔ+AÑBÐBØÐr   c                óN  — d}t        | «      }t        |j                  dd«      «      j                  «       j	                  «       t
        v rt        |d<   d}t        |j                  d«      «      rt        |d   «      |d<   d}|j                  d«      }t        |t         «      r}|j                  d«      }t        |«      sMt        |t         «      rQt        |j                  dd«      «      j                  «       j	                  «       t
        v ri |¥ddt        d	œi¥|d<   d}|r|S d
S )a7  Copy of *kwargs* with every thinking-OFF encoding lifted to ``REASONING_FLOOR_EFFORT``:
    top-level ``reasoning_effort``, ``extra_body.reasoning`` (OpenRouter shape) and the adapter's private
    ``_reasoning_config``. ``None`` when nothing was disabled, so the ladder never re-sends an unchanged
    request.FÚreasoning_effortr   TÚ_reasoning_configÚ
extra_bodyÚ	reasoningr$   r#   N)
r   r   r   r   r   Ú_DISABLED_EFFORTSr%   r!   r&   r   )ÚkwargsÚchangedÚretryr*   r+   s        r   Úwith_reasoning_floorr0   2   s  € ð
 €GÜ�‹L€EÜ
ˆ5�9‰9Ð'¨Ó,Ó-×3Ñ3Ó5×;Ñ;Ó=ÔARÑRÜ$:ˆÐ Ñ!ØˆÜ�E—I‘IÐ1Ó2Ô3Ü%;¸EÐBUÑ<VÓ%WˆÐ!Ñ"ØˆØ—‘˜<Ó(€JÜ�*œdÔ#Ø—N‘N ;Ó/ˆ	Ü˜	Ô"Ü�y¤$Ô'¬C°	·±¸hÈÓ0KÓ,L×,RÑ,RÓ,T×,ZÑ,ZÓ,\Ô`qÑ,qà"r ZÐ"r°È$ÔZpÑ>qÑ"rˆE�,ÑØˆGÙˆ5Ð% Ð%r   c                ó~   — t         j                  t        | |«      t        |j	                  d«      xs d«      f«       y)z”Record that this route's ``rejected_kwargs["model"]`` refuses to disable reasoning (the ladder
    calls this after the stepped-up retry succeeded).Úmodelr   N)r	   Úaddr   r   r   )r   r   Úrejected_kwargsÚerrors       r   Úremember_reasoning_floorr6   J   s5   € ô
 ×Ñœ H¨hÓ7¼¸_×=PÑ=PÐQXÓ=YÒ=_Ð]_Ó9`ÐaÕbr   c                óÞ   — t        | «      s| S t        ||«      t        |xs d«      ft        vr| S t        j                  d|xs dt        ||«      xs d|xs dt        «       t        | «      S )z¿*reasoning_config* lifted to the floor when this route+model is known to refuse a disable; unchanged
    otherwise. Runs before the profile projection so every wire shape starts at the floor.r   zJAuxiliary %s: %s (%s) cannot disable reasoning; sending effort=%s up frontÚcallr   r2   )r!   r   r   r	   ÚloggerÚinfor%   r&   )r    r   r   r2   Útasks        r   Úknown_reasoning_floorr<   R   sr   € ô Ð(Ô)ØÐÜ�8˜XÓ&¬¨EªK°RÓ(8Ð9ÄÑPØÐÜ
‡K�KØTØŠ�œ
 8¨XÓ6ÒD¸*ÀeÒFVÈwÔXnôô "Ð"2Ó3Ð3r   )r   úOptional[str]r   r=   Úreturnr   )r    r   r>   Úbool)r    r   r>   úDict[str, Any])r-   r@   r>   zOptional[Dict[str, Any]])
r   r=   r   r=   r4   r@   r5   ÚBaseExceptionr>   ÚNone)N)r    r   r   r=   r   r=   r2   r=   r;   r=   r>   r   )Ú__doc__Ú
__future__r   ÚloggingÚtypingr   r   r   Úurllib.parser   Ú	getLoggerÚ__name__r9   r%   Úsetr	   Ú__annotations__r,   r   r!   r&   r0   r6   r<   © r   r   ú<module>rM      sÍ   ðòõ  #ã ß &Ñ &Ý !à	ˆ×	Ñ	˜8Ó	$€àÐ ñ ),«€Ð%Ó -â=Ð óbó[óó&ð0cØðcØ'4ðcØGUðcØ^kðcà	ócð ð4Øð4Ø%2ð4Ø>Kð4ØTað4à
ð4ð 	ô4r   