+
    iHàj/  ã                  óÞ   a € 0 t $ R t^ RIHt ^ RIt^ RIHtHtHt ^ RI	H
t
 ]P                  ! ]4      t]! 4       tR]R&   RtR R ltR	 R
 ltR R ltR R ltR R ltRR R lltR R ltR# )uC  Structured-output (``response_format``) capability for auxiliary requests.

Two sources decide whether an aux request may carry a ``response_format`` type up front:

* the provider profile's ``unsupported_response_formats`` (DeepSeek's native API implements only
  ``json_object`` â€” https://api-docs.deepseek.com/guides/json_mode â€” and answers ``json_schema`` with
  HTTP 400 "This response_format type is unavailable now"), also consulted when a ``custom`` route's
  base_url points at a profiled provider's host, and
* a process-level memo of (endpoint, model, type) triples that already rejected the type once; the
  recovery ladder records the triple when its retry without the field succeeded.

Either way the field is dropped before the first request instead of burning a guaranteed-fail
round-trip per call (#83390, #105191, #113064). Dropping â€” not downgrading to ``json_object`` â€” is the
same end state the rejection retry already produces: ``json_object`` needs the prompt to mention JSON
and some relays return empty content under it, so callers already tolerate prompt compliance.

The memo carries the model because capability is per model on aggregators (openrouter.ai, the Nous
Portal, api.openai.com host dozens of models with different structured-output support), and it is
fed only by rejections that name the *capability* â€” not by schema-validation 400s from providers that
do implement ``json_schema`` ("Invalid schema for response_format 'json_schema': additionalProperties
must be false"), which the ladder still retries once but which say nothing about the next schema.
)ÚannotationsN)ÚAnyÚDictÚOptional)Úurlparsezset[tuple[str, str, str]]Ú_REJECTED_ROUTESc               ó$   € V ^8„  d   QhRRRRRR/# )é   ÚproviderúOptional[str]Úbase_urlÚreturnÚstr© )Úformats   "ÚF/home/ubuntu/.hermes/hermes-agent/agent/auxiliary_structured_output.pyÚ__annotate__r   *   s&   € ÷ bñ b˜ð b°-ð bÀCñ bó    c                óâ   € \        T;'       g    R4      P                  ;'       g    RP                  4       ;'       g2    \        T ;'       g    R4      P	                  4       P                  4       # )z‘Endpoint host:port when known (a base_url override turns a named provider into ``custom``; local
servers differ by port), else the provider name.Ú )r   ÚnetlocÚlowerr   Ústrip)r
   r   s   &&r   Ú
_route_keyr   *   sQ   € ô �X—^�^ Ó$×+Ñ+×1Ð1¨r×8Ñ8Ó:×aÐa¼cÀ(Ç.À.ÈbÓ>Q×>WÑ>WÓ>Y×>_Ñ>_Ó>aÐar   c               ó    € V ^8„  d   QhRRRR/# )r	   Úrequest_kwargsúdict[str, Any]r   r   r   )r   s   "r   r   r   0   s   € ÷ Vñ V¨.ð V¸]ñ Vr   c                ó  € V P                  R 4      p\        V\        4      '       d   T;'       g    / P                  R4      MRpVf   V P                  R4      p\        V\        4      '       d   VP                  R4      # R# )Ú
extra_bodyÚresponse_formatNÚtype)ÚgetÚ
isinstanceÚdict)r   r   r   s   &  r   Ú_response_format_typer$   0   su   € Ø×#Ñ# LÓ1€JÜCMÈjÔZ^×C_ÒC_�z×'Ð' R×,Ñ,Ð->Ô?Ðei€OØÒØ(×,Ñ,Ð->Ó?ˆÜ*4°_Äd×*KÒ*Kˆ?×Ñ˜vÓ&ÐUÐQUÐUr   c               ó$   € V ^8„  d   QhRRRRRR/# )r	   r
   r   r   r   Útupler   )r   s   "r   r   r   8   s'   € ÷ lñ l¨=ð lÀMð lÐV[ñ lr   c                óB  €  ^ RI Hp \        T ;'       g    R4      P                  4       P	                  4       pVR8X  d!   V'       d   ^ RIHp V! V4      ;'       g    TpV! V4      pTe!   \        \        TRR4      ;'       g    R4      # R#   \         d    Ru # i ; i)z«The provider profile's declared unsupported types; a ``custom`` route whose base_url is a profiled
provider's own host (``api.deepseek.com``) gets that provider's profile.)Úget_provider_profiler   Úcustom)Ú_infer_provider_from_urlÚunsupported_response_formatsr   )
Ú	providersr(   r   r   r   Úagent.model_metadatar*   Ú	Exceptionr&   Úgetattr)r
   r   r(   Únamer*   Úprofiles   &&    r   Ú_profile_unsupported_formatsr2   8   s—   € ðÝ2Ü�8—>�>˜rÓ"×(Ñ(Ó*×0Ñ0Ó2ˆØ�8Ô§ÝEÙ+¨HÓ5×=Ð=¸ˆDÙ& tÓ,ˆð QXÒPcŒ5”˜Ð"@À"ÓE×KÐKÈÓLÐkÐikÐkøô ô ØŠ	ðús"   ‚B –1B ÁB ÁB ÂBÂBc               ó    € V ^8„  d   QhRRRR/# )r	   ÚerrorzOptional[BaseException]r   Úboolr   )r   s   "r   r   r   G   s   € ÷ Pñ PÐ#:ð P¸tñ Pr   c                óà   a€ \        T ;'       g    R4      P                  4       oRS9   d   R# \        ;QJ d#    V3R l\         4       F  '       g   K   R# 	  R# ! V3R l\         4       4      # )zžWhether a structured-output rejection speaks to the route/model's capability (memoisable) rather
than to this request's schema (retry once, remember nothing).r   zinvalid schemaFc              3  ó,   <"  € T F	  qS9   x € K  	  R # 5i©Nr   )Ú.0ÚmarkerÚ	err_lowers   & €r   Ú	<genexpr>Ú*is_capability_rejection.<locals>.<genexpr>M   s   øé € ÐOÑ1N v˜Ö"Ó1Nùs   ƒT)r   r   ÚanyÚ_CAPABILITY_REJECTION_MARKERS)r4   r;   s   &@r   Úis_capability_rejectionr@   G   sT   ø€ ô �E—K�K˜RÓ ×&Ñ&Ó(€IØ˜9Ô$Ùß‹3ÔOÕ1NÓO�3Œ3ÐOŠ3ÐOˆ3ÔOÕ1NÓOÓOÐOr   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR	/# )
r	   r
   r   r   Úrejected_kwargsr   r4   ÚBaseExceptionr   ÚNoner   )r   s   "r   r   r   P   s;   € ÷ uñ uØðuØ'4ðuØGUðuØ^kðuà	ñur   c                óÜ   € \        V4      pV'       dY   \        V4      '       dF   \        P                  \	        W4      \        VP                  R4      ;'       g    R4      V34       R# R# R# )uÇ   Record that this route's ``rejected_kwargs["model"]`` rejected the ``response_format`` type carried
by *rejected_kwargs* â€” only when *error* names the capability, never for a schema-validation 400.Úmodelr   N)r$   r@   r   Úaddr   r   r!   )r
   r   rB   r4   Úformat_types   &&&& r   Ú$remember_structured_output_rejectionrI   P   sX   € ô
 (¨Ó8€KßÔ.¨u×5Ò5Ü×Ñœj¨Ó<¼cÀ/×BUÑBUÐV]ÓB^×BdÐBdÐbdÓ>eÐgrÐsÖtñ 6�{r   c               ó0   € V ^8„  d   QhRRRRRRRRRRRR/# )	r	   r   r   r
   r   r   rF   Útaskr   r   )r   s   "r   r   r   Z   sF   € ÷ Kñ KØðKØ*7ðKØCPðKØYfðKà
ðKð ñKr   c                ó   € V P                  R4      p\        V\        4      '       d   VP                  R4      MRpV'       g   V # V\        W4      9   ;'       g)    \	        W4      \        T;'       g    R4      V3\        9   pV'       g   V # \        P                  RT;'       g    R\	        W4      ;'       g    RT;'       g    RV4       V P                  4        UU	u/ uF  w  r‰VR8w  g   K  W‰bK  	  up	p# u up	pi )	zm*extra_body* minus a ``response_format`` whose type this route+model is known to reject; unchanged
otherwise.r   r    Nr   zAuxiliary %s: %s (%s) does not accept response_format %s; sending without it (schema enforcement degrades to prompt compliance)Úcallr
   rF   )
r!   r"   r#   r2   r   r   r   ÚloggerÚinfoÚitems)
r   r
   r   rF   rK   r   rH   Úknown_unsupportedÚkÚvs
   &&&&&     r   Ú#without_unsupported_response_formatrT   Z   sî   € ð !—n‘nÐ%6Ó7€OÜ1;¸OÌT×1RÒ1R�/×%Ñ% fÔ-ÐX\€KßØÐàÔ3°HÓGÑG÷ 	_ð 	_Ü�xÓ*¬C°·°¸Ó,<¸kÐJÔN^Ñ^ð ÷ ØÐÜ
‡K�Kð	=à�ˆ�œ
 8Ó6×DÐD¸*Àe×FVÐFVÈwÐXcôð
 (×-Ñ-Ô/ÔJÑ/‘T�Q°1Ð8IÑ3IŒDˆAŠDÑ/ÒJÐJùÓJs   Ã C:Ã0C:c               ó    € V ^8„  d   QhRRRR/# )r	   Úkwargsr#   r   zOptional[dict]r   )r   s   "r   r   r   r   s   € ÷ -ñ -¨dð -°~ñ -r   c                óZ  € \        V 4      pVP                  RR4      RJpVP                  R4      p\        V\         4      '       dU   RV9   dN   VP	                  4        UUu/ uF  w  rEVR8w  g   K  WEbK  	  pppV'       d   WaR&   MVP                  RR4       RpV'       d   V# R# u uppi )z˜Copy *kwargs* without ``response_format`` (top-level and ``extra_body``); None when nothing was
removed, so call sites don't retry an unchanged request.r   Nr   T)r#   Úpopr!   r"   rP   )rV   Úretry_kwargsÚchangedr   rR   rS   Ú	remainings   &      r   Ú!_without_structured_output_formatr\   r   sª   € ô ˜“<€LØ×ÑÐ0°$Ó7¸tÐC€GØ×!Ñ! ,Ó/€JÜ�*œd×#Ò#Ð(9¸ZÔ(GØ&0×&6Ñ&6Ô&8ÔSÑ&8™d˜a¸AÐARÑ<R”T�Q’TÑ&8ˆ	ÑSßØ)2˜Ò&à×Ñ˜\¨4Ô0Øˆß"ˆ<Ð,¨Ð,ùó Ts   Á!B'Á1B')
Úunavailablezdoes not supportzdoesn't supportznot supportedzunsupported parameterÚunsupported_parameterzunknown parameterzunrecognized request argumentzunrecognized parameterzextra inputs are not permittedr8   )Ú__conditional_annotations__Ú__doc__Ú
__future__r   ÚloggingÚtypingr   r   r   Úurllib.parser   Ú	getLoggerÚ__name__rN   Úsetr   Ú__annotations__r?   r   r$   r2   r@   rI   rT   r\   )r_   s   @r   Ú<module>ri      sm   øðôõ, #ã ß &Ñ &Ý !à	×	Ò	˜8Ó	$€ñ /2«eÐ Ð+Ó 3ð!Ð õbõVõlõPõu÷K÷0-r   