ó
    ±"³j¢>  ã                  óœ  • % S r SSKJr  SSKJrJrJr  SSKJr  SSK	J
r
  SSKJrJrJrJrJr  SSKJrJrJr  SSKJrJr  SS	KJrJr  SS
KJr  SSKJrJrJ r   SSK!J"r"J#r#  SSK$J%r%  SSK&J'r'  SSK(J)r)  SSK*J+r+  \(       a  SSK,J-r-  S/r.Sr/ Sr0 " S S\5      r1S"S jr2 S#   S$S jjr3 " S S5      r4\" SSS9r5S\6S'   S%S jr7S&S  jr8S'S! jr9g)(zFAgent specification for constructing agents from YAML/JSON/dict specs.é    )Úannotations)ÚCallableÚMappingÚSequence)Ú
ContextVar)ÚPath)ÚTYPE_CHECKINGÚAnyÚLiteralÚUnionÚcast)Ú	BaseModelÚFieldÚmodel_serializer)Ú	from_jsonÚto_json)ÚSerializationInfoÚSerializerFunctionWrapHandler)ÚEndStrategy)ÚCapabilitySpecÚbuild_registryÚbuild_schema_types)Úget_function_type_hintsÚis_str_dict)ÚAgentRetries)Ú	UserError)ÚModelSettings)ÚTemplateStr©ÚAbstractCapabilityr   z./{stem}_schema.jsonz # yaml-language-server: $schema=c                  ó¼  • \ rS rSr% Sr\" SSS9rS\S'   SrS\S'   Sr	S\S	'   Sr
S
\S'   SrS\S'   SrS\S'   SrS\S'   SrS\S'   SrS\S'   SrS\S'   SrS\S'   SrS\S'   / rS\S'   \ S&     S'S jj5       r\ S(     S)S jj5       r\S*S j5       rS\S4         S+S  jjr\" S!S"9S,S# j5       r\ S-   S.S$ jj5       r\ S-     S/S% jj5       rSrg)0Ú	AgentSpecé!   z>Specification for constructing an Agent from a dict/YAML/JSON.Nú$schema)ÚdefaultÚaliasú
str | NoneÚjson_schema_pathÚmodelÚnamezTemplateStr[Any] | str | NoneÚdescriptionz<TemplateStr[Any] | str | list[TemplateStr[Any] | str] | NoneÚinstructionsúdict[str, Any] | NoneÚdeps_schemaÚoutput_schemaÚmodel_settingsúint | AgentRetries | NoneÚretriesÚgracefulr   Úend_strategyúfloat | NoneÚtool_timeoutÚmetadatazlist[CapabilitySpec]Úcapabilitiesc                ój   • [        U5      n[        X5      nUR                  SS9nU R                  X2S9$ )zÄLoad an agent spec from a YAML or JSON file.

Args:
    path: Path to the file to load.
    fmt: Format of the file. If None, inferred from file extension.

Returns:
    A new AgentSpec instance.
úutf-8©Úencoding)Úfmt)r   Ú
_infer_fmtÚ	read_textÚ	from_text)ÚclsÚpathr=   Úcontents       ÚS/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pydantic_ai/agent/spec.pyÚ	from_fileÚAgentSpec.from_file3   s8   € ô �D‹zˆÜ˜Ó#ˆØ—.‘.¨'�.Ð2ˆØ�}‰}˜Wˆ}Ð.Ð.ó    c                ó
  • US:X  a  [        U5      nO SSKnUR                  U5      n[	        U5      (       d!  [        S[        U5      R                   35      eU R                  U5      $ ! [         a    [        S5      Sef = f)zÂParse YAML or JSON text into an AgentSpec.

Args:
    text: The string content to parse.
    fmt: Format of the content. Must be either 'yaml' or 'json'.

Returns:
    A new AgentSpec instance.
Újsonr   NzbPyYAML is required to load YAML agent specs. Install it with: pip install "pydantic-ai-slim[spec]"z(Agent spec must parse to an object, got )	r   ÚyamlÚImportErrorÚ	safe_loadr   r   ÚtypeÚ__name__Ú	from_dict)rA   Útextr=   ÚdatarJ   s        rD   r@   ÚAgentSpec.from_textG   sˆ   € ð �&‹=Ü˜T“?‰DðÛð —>‘> $Ó'ˆDÜ˜4× Ñ ÜÐFÄtÈDÃz×GZÑGZÐF[Ð\Ó]Ð]Ø�}‰}˜TÓ"Ð"øô ó ä!Øxóàððús   ”A+ Á+Bc                ó$   • U R                  U5      $ )z�Validate a dictionary into an AgentSpec.

Args:
    data: Dictionary representation of the agent spec.

Returns:
    A new AgentSpec instance.
)Úmodel_validate)rA   rQ   s     rD   rO   ÚAgentSpec.from_dicte   s   € ð ×!Ñ! $Ó'Ð'rG   © c                óþ  • [        U5      n[        X5      nSnUbÈ  [        U[        5      (       a"  [        UR	                  UR
                  S95      nUR                  5       (       d  [        U5      nUR                  U-  nOPUR                  UR                  5      (       a%  [        UR                  UR                  5      5      nO[        U5      nU R                  X45        SS0nUS:X  aM   SSKnU R                  SSUSS	9nUR                  US
SS9n	U(       a  [         U SU	 3n	UR!                  U	SS9  gXVS'   U R#                  SSUSS9n
UR!                  U
S-   SS9  g! [         a    [        S5      Sef = f)aœ  Save the agent spec to a YAML or JSON file.

Args:
    path: Path to save the spec to.
    fmt: Format to use. If None, inferred from file extension.
    schema_path: Path to save the JSON schema to. If None, no schema will be saved.
        Can be a string template with {stem} which will be replaced with the spec filename stem.
    custom_capability_types: Custom capability classes to include in the schema.
N)ÚstemÚuse_short_formTrJ   r   zbPyYAML is required to save YAML agent specs. Install it with: pip install "pydantic-ai-slim[spec]"rI   )ÚmodeÚby_aliasÚcontextÚexclude_defaultsF)Ú	sort_keysÚallow_unicodeÚ
r:   r;   r$   é   )Úindentr[   r\   r]   )r   r>   Ú
isinstanceÚstrÚformatrX   Úis_absoluteÚparentÚis_relative_toÚrelative_toÚ_save_schemarJ   rK   Ú
model_dumpÚdumpÚ_YAML_SCHEMA_LINE_PREFIXÚ
write_textÚmodel_dump_json)ÚselfrB   r=   Úschema_pathÚcustom_capability_typesÚ
schema_refr\   rJ   Údumped_datarC   Ú	json_datas              rD   Úto_fileÚAgentSpec.to_fileq   s�  € ô  �D‹zˆÜ˜Ó#ˆà!%ˆ
ØÑ"Ü˜+¤s×+Ñ+Ü" ;×#5Ñ#5¸4¿9¹9Ð#5Ð#EÓF�à×*Ñ*×,Ñ,Ü  Ó-�
Ø"Ÿk™k¨KÑ7‘Ø×+Ñ+¨D¯K©K×8Ñ8Ü  ×!8Ñ!8¸¿¹Ó!EÓF‘
ä  Ó-�
Ø×Ñ˜kÔCà#3°TÐ":ˆØ�&‹=ðÛð Ÿ/™/¨vÀÈgÐhl˜/ÐmˆKØ—i‘i °uÈD�iÐQˆGÞÜ5Ð6°z°lÀ"ÀWÀIÐN�Ø�O‰O˜G¨gˆOÒ6à!+�IÑØ×,Ñ,°AÀÈgÐhlÐ,ÐmˆIØ�O‰O˜I¨Ñ,°wˆOÒ?øô ó ä!Øxóàððús   Ã/E% Å%E<Úwrap)rZ   c                óÚ   • [        [        [        [        4   S-  UR                  5      n[        U[        5      (       a%  UR                  S5      =n(       a  SU0U" U 5      -  $ U" U 5      $ )zLAdd the JSON schema path to the serialized output when provided via context.Nr$   )r   Údictrd   r
   r\   rc   Úget)rp   ÚnxtÚinfor\   Úschemas        rD   Ú_add_json_schemaÚAgentSpec._add_json_schema¥   s_   € ô ”tœC¤˜H‘~¨Ñ,¨d¯l©lÓ;ˆÜ�gœt×$Ñ$°G·K±KÀ	Ó4JÐ*J¨&Õ*JØ˜vÐ&©¨T«Ñ2Ð2Ù�4‹yÐrG   c                ó&  ^• [        [        U5      5      m " U4S jS[        SSS9nUR                  5       nSUS'   SS	0US
   S'   UR	                  S0 5      R	                  S0 5      nUR                  SS5        US
   S   S   n[        X55        U$ )aC  Generate a JSON schema for this agent spec type, including capability details.

This is useful for generating a schema that can be used to validate YAML-format agent spec files.

Args:
    custom_capability_types: Custom capability classes to include in the schema.

Returns:
    A dictionary representing the JSON schema.
c                  óÖ   >• \ rS rSr% SrS\S'   SrS\S'   SrS\S'   SrS\S'   Sr	S	\S
'   Sr
S	\S'   SrS\S'   SrS\S'   SrS\S'   SrS\S'   SrS	\S'    Y (       a
  / rS\S'   SrgSrg)ÚGAgentSpec.model_json_schema_with_capabilities.<locals>._AgentSpecSchemaéÅ   Nr'   r)   r*   r+   zstr | list[str] | Noner,   r-   r.   r/   zModelSettings | Noner0   r1   r2   r3   r   r4   r5   r6   r7   z+list[Union[tuple(capability_schema_types)]]r8   rV   )rN   Ú
__module__Ú__qualname__Ú__firstlineno__r)   Ú__annotations__r*   r+   r,   r.   r/   r0   r2   r4   r6   r7   r8   Ú__static_attributes__)Úcapability_schema_typess   €rD   Ú_AgentSpecSchemarƒ   Å   sŠ   ø‡ Ø $ˆE�:Ó$Ø#ˆD�*Ó#Ø&*ˆK˜Ó*Ø37ˆLÐ0Ó7Ø15ˆKÐ.Ó5Ø37ˆMÐ0Ó7Ø37ˆNÐ0Ó7Ø15ˆGÐ.Ó5Ø(2ˆL˜+Ó2Ø)-ˆL˜,Ó-Ø.2ˆHÐ+Ó2ß&ØLN�ÐIÖNò 'rG   r‹   ÚforbidT)ÚextraÚarbitrary_types_allowedr"   ÚtitlerM   ÚstringÚ
propertiesr$   ú$defsr   ÚadditionalPropertiesNr8   Úitems)Ú_build_capability_schema_typesÚget_capability_registryr   Úmodel_json_schemar{   ÚpopÚ_replace_capability_spec_refs)rA   rr   r‹   Újson_schemaÚmodel_settings_defÚcap_items_schemarŠ   s         @rD   Ú#model_json_schema_with_capabilitiesÚ-AgentSpec.model_json_schema_with_capabilities­   s°   ø€ ô #AÔAXÐYpÓAqÓ"rÐ÷	Oœy°ÐRVò 	Oð '×8Ñ8Ó:ˆØ*ˆ�GÑØ06¸Ð/Aˆ�LÑ! )Ñ,ð
 .9¯_©_¸WÀbÓ-I×-MÑ-MÈoÐ_aÓ-bÐØ×ÑÐ5°tÔ<ð
 ' |Ñ4°^ÑDÀWÑMÐÜ% kÔDàÐrG   c                óä   • [        U5      nU R                  U5      n[        USS9R                  5       S-   nUR	                  5       (       a  UR                  SS9U:w  a  UR                  USS9  gg)z·Save the JSON schema for this agent spec type to a file.

Args:
    path: Path to save the schema to.
    custom_capability_types: Custom capability classes to include in the schema.
ra   )rb   r`   r:   r;   N)r   r�   r   ÚdecodeÚexistsr?   rn   )rA   rB   rr   rš   Úschema_contents        rD   rj   ÚAgentSpec._save_schemaæ   sk   € ô �D‹zˆØ×=Ñ=Ð>UÓVˆÜ  °QÑ7×>Ñ>Ó@À4ÑGˆØ�{‰{�}‰} §¡¸ Ð @ÀNÓ RØ�O‰O˜N°WˆOÒ=ð !SrG   ©N)rB   ú
Path | strr=   úLiteral['yaml', 'json'] | NoneÚreturnr"   )rJ   )rP   rd   r=   úLiteral['yaml', 'json']r§   r"   )rQ   údict[str, Any]r§   r"   )
rB   r¥   r=   r¦   rq   zPath | str | Nonerr   ú'Sequence[type[AbstractCapability[Any]]]r§   ÚNone)r|   r   r}   r   r§   r©   ©rV   )rr   rª   r§   r©   )rB   r¥   rr   rª   r§   r«   )rN   r…   r†   r‡   Ú__doc__r   r(   rˆ   r)   r*   r+   r,   r.   r/   r0   r2   r4   r6   r7   r8   ÚclassmethodrE   r@   rO   ÚDEFAULT_SCHEMA_PATH_TEMPLATErv   r   r   r�   rj   r‰   rV   rG   rD   r"   r"   !   sÜ  ‡ ÙHñ $)°¸YÑ#GÐ�jÓGØ€Eˆ:ÓØ€Dˆ*ÓØ15€KÐ.Ó5ØQU€LÐNÓUØ)-€KÐ&Ó-Ø+/€MÐ(Ó/Ø,0€NÐ)Ó0Ø)-€GÐ&Ó-Ø *€L�+Ó*Ø!%€L�,Ó%Ø&*€HÐ#Ó*Ø)+€LÐ&Ó+àð /3ð/àð/ð ,ð/ð 
ô	/ó ð/ð& ð (.ð#àð#ð %ð#ð 
ô	#ó ð#ð: ó	(ó ð	(ð /3Ø)EØKMð2@àð2@ð ,ð2@ð 'ð	2@ð
 "Ið2@ð 
õ2@ñh ˜6Ñ"óó #ðð ð LNð6à!Hð6ð 
ô6ó ð6ðp ð LNð>àð>ð "Ið>ð 
ô	>ó ó>rG   r"   c                ó�   • Ub  U$ U R                   R                  5       nUS;   a  gUS:X  a  g[        SU R                  < S35      e)z:Infer the format to use for a file based on its extension.>   ú.ymlú.yamlrJ   z.jsonrI   z$Could not infer format for filename z/. Use the `fmt` argument to specify the format.)ÚsuffixÚlowerÚ
ValueErrorr*   )rB   r=   r³   s      rD   r>   r>   ù   sS   € à
�Øˆ
Ø�[‰[×ÑÓ €FØÐ"Ó"ØØ	�7Ó	ØÜ
Ø
.¨t¯y©y©mÐ;jÐkóð rG   c                óv   ^• SSK Jn  SSKJm  SU4S jjn[	        U [        UR                  5       5      S SUS9$ )	zDCreate a registry of capability types from default and custom types.r   )ÚCAPABILITY_TYPESr   c                ó„   >• [        U T5      (       d  [        SU  S35      eSU R                  ;  a  [        SU  S35      eg )NzLAll custom capability classes must be subclasses of AbstractCapability, but z is notÚ__dataclass_fields__zGAll custom capability classes must be decorated with `@dataclass`, but )Ú
issubclassrµ   Ú__dict__)rA   r    s    €rD   Ú_validate_capabilityÚ5get_capability_registry.<locals>._validate_capability  sX   ø€ Ü˜#Ð1×2Ñ2ÜØ^Ð_bÐ^cÐcjÐkóð ð "¨¯©Ó5ÜÐfÐgjÐfkÐkrÐsÓtÐtð 6rG   c                ó"   • U R                  5       $ r¤   )Úget_serialization_name©rA   s    rD   Ú<lambda>Ú)get_capability_registry.<locals>.<lambda>  s   € ˜S×7Ñ7Ô9rG   Ú
capability)Úcustom_typesÚdefaultsÚget_nameÚlabelÚvalidate)rA   ztype[AbstractCapability[Any]]r§   r«   )Úpydantic_ai.capabilitiesr·   Ú!pydantic_ai.capabilities.abstractr    r   ÚtupleÚvalues)rÄ   r·   r¼   r    s      @rD   r–   r–     s>   ø€ õ :ÝD÷uô Ø!ÜÐ'×.Ñ.Ó0Ó1Ù9ØØ%ñð rG   c                  ó2   • \ rS rSrSrSr      SS jrSrg)ÚCapabilitySpecContexti  zQHolds the registry and instantiation callback for the current spec-loading scope.©ÚregistryÚinstantiatec                ó   • Xl         X l        g r¤   rÏ   )rp   rÐ   rÑ   s      rD   Ú__init__ÚCapabilitySpecContext.__init__$  s   € ð !ŒØ&ÕrG   )rÑ   rÐ   N)rÐ   ú+Mapping[str, type[AbstractCapability[Any]]]rÑ   zcCallable[[type[AbstractCapability[Any]], tuple[Any, ...], dict[str, Any]], AbstractCapability[Any]]r§   r«   )rN   r…   r†   r‡   r­   Ú	__slots__rÓ   r‰   rV   rG   rD   rÎ   rÎ     s+   † Ù[à+€Ið'à=ð'ð
ð'ð 
÷'rG   rÎ   Úcapability_spec_contextN)r%   z(ContextVar[CapabilitySpecContext | None]c                óø   • SSK Jn  [        U [        5      (       a  U O[        R                  " U 5      n[
        R                  5       nUb  U" UR                  USSUR                  S9$ U" [        5       USSS S9$ )a  Load a capability from a nested spec, reusing the current spec-loading context.

When called inside `Agent.from_spec()` or `Agent._resolve_spec()`, this uses the same
registry (including custom capability types) and template context as the outer loading.
When called outside a spec-loading context, falls back to the default registry.

This is intended for use in `from_spec()` methods of wrapper capabilities like
[`PrefixTools`][pydantic_ai.capabilities.PrefixTools] that need to instantiate
a nested capability from a spec argument.
r   )Úload_from_registryrÃ   rr   )rÇ   Úcustom_types_paramrÑ   c                ó&   • U R                   " U0 UD6$ r¤   )Ú	from_spec)Úcap_clsÚargsÚkwargss      rD   rÁ   Ú2load_capability_from_nested_spec.<locals>.<lambda>O  s   € °g×6GÒ6GÈÐ6XÐQWÒ6XrG   )
Úpydantic_ai._specrÙ   rc   r   rT   r×   r{   rÐ   rÑ   r–   )ÚspecrÙ   Úcap_specÚctxs       rD   Ú load_capability_from_nested_specrå   2  s~   € õ 5ä! $¬×7Ñ7‰t¼^×=ZÒ=ZÐ[_Ó=`€HÜ
!×
%Ñ
%Ó
'€CØ
�Ù!Ø�L‰LØØØ8ØŸ™ñ
ð 	
ñ "Ü#Ó%ØØØ8ÙXñ
ð 	
rG   c                ó    • SS jn[        U US9$ )z>Build a list of schema types for capabilities from a registry.c                óÊ   • SU R                   ;  a"   [        U R                  5        U R                  $ U R                  $ ! [        [        [
        4 a     U R                  $ f = f)NrÜ   )r»   r   rÓ   Ú	NameErrorÚ	TypeErrorÚAttributeErrorrÜ   rÀ   s    rD   Ú_get_schema_targetÚ:_build_capability_schema_types.<locals>._get_schema_targetV  s\   € ð ˜cŸl™lÓ*ðÜ'¨¯©Ô5Ø—|‘|Ð#ð �}‰}Ðøô œy¬.Ð9ó ØØ�}‰}Ððús   ’ ? ¿A"Á!A")Úget_schema_target)rA   z	type[Any]r§   r
   )r   )rÐ   rë   s     rD   r•   r•   S  s   € ô
ô ØØ,ñð rG   c           	     ó$  • SnU R                  S5      U:X  a"  U R                  5         U R                  U5        gU R                  5        HŸ  n[	        U[
        5      (       a)  [        [        [
        [        [        4   U5      U5        MA  [	        U[        5      (       d  MX  U HA  n[	        U[
        5      (       d  M  [        [        [
        [        [        4   U5      U5        MC     M¡     U R                  S0 5      nUR                  SS5        g)zWWalk the schema and replace any $ref to CapabilitySpec with the capability items Union.z#/$defs/CapabilitySpecz$refNr’   r   )r{   ÚclearÚupdaterÌ   rc   rz   r™   r   rd   r
   Úlistr˜   )r~   rœ   Úcap_refÚvalueÚitemÚdefss         rD   r™   r™   h  sÇ   € à&€Gà‡z�z�&Ó˜WÓ$Ø�‰ŒØ�‰Ð&Ô'ØØ—‘–ˆÜ�eœT×"Ñ"Ü)¬$¬t´C¼°H©~¸uÓ*EÐGWÖXÜ˜œt×$Ó$Û�Ü˜d¤D×)Ó)Ü1´$´t¼CÄ¸H±~ÀtÓ2LÐN^Ö_ó ñ	 !ð "Ÿ:™: g¨rÓ2€DØ‡H�HÐ˜tÕ$rG   )rB   r   r=   r¦   r§   r¨   r¬   )rÄ   rª   r§   rÕ   )râ   z%CapabilitySpec | dict[str, Any] | strr§   zAbstractCapability[Any])rÐ   zMapping[str, type[Any]]r§   z	list[Any])r~   r©   rœ   r©   r§   r«   ):r­   Ú
__future__r   Úcollections.abcr   r   r   Úcontextvarsr   Úpathlibr   Útypingr	   r
   r   r   r   Úpydanticr   r   r   Úpydantic_corer   r   Úpydantic_core.core_schemar   r   Úpydantic_ai._agent_graphr   rá   r   r   r   Úpydantic_ai._utilsr   r   Úpydantic_ai.agent.abstractr   Úpydantic_ai.exceptionsr   Úpydantic_ai.settingsr   Úpydantic_ai.templater   rÊ   r    Ú__all__r¯   rm   r"   r>   r–   rÎ   r×   rˆ   rå   r•   r™   rV   rG   rD   Ú<module>r     s¿   ðÚ Lå "ç 7Ñ 7Ý "Ý ß ;Õ ;ç 7Ñ 7ß ,ß Vå 0ß PÑ Pß CÝ 3Ý ,Ý .Ý ,æÝDàÐ
€à5Ð Ø cà=Ð ôU>�	ô U>ôpð =?ðØ9ðà0õ÷0'ñ 'ñ  EOÐOhÐrvÑDwÐ ÐAÓ wô
ôBõ*%rG   