ó
    °"³jÍ  ã                  óv  • S SK J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Jr  S SKJ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  \\   \-  \-  \\   -  r \\   \\\      -  S-  rSS jrSS jr\" SSS9 " S S\	\   5      5       r       SS jr!      SS jr"    SS jr#    SS jr$g)é    )Úannotations)ÚSequence)ÚKW_ONLYÚ	dataclassÚreplace)ÚGeneric)Ú
AgentDepsTÚ
RunContext)Údataclasses_no_defaults_repr©Ú	UserError)ÚInstructionIdÚInstructionPartÚInstructionSource)ÚTemplateStré   )Ú_system_prompt)ÚSystemPromptFuncNc               ó4   • SU ;   a  [        U SU < S35      eg)zLReject values that cannot be represented unambiguously in an instruction id.Ú:Ú zO cannot contain a colon because `:` is reserved as an instruction ID delimiter.Nr   )ÚidÚkinds     ÚV/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pydantic_ai/_instructions.pyÚvalidate_instruction_id_segmentr      s'   € à
ˆbƒyÜ˜4˜&  "¡Ð'vÐwÓxÐxð ó    c                ó:   • [        U SS9  U S:X  a  [        S5      eg)a	  Reject names an author cannot declare on an instruction part.

A name is one segment of the id built around it, so it must not be able to spell a key by itself.
`'agent'` is the only one it could reach: every other key is namespaced, and a colon is rejected
above.
zInstruction name)r   Úagentz_Instruction name 'agent' is reserved for the agent's own instructions; choose a different name.N)r   r   ©Únames    r   Úvalidate_instruction_namer!      s+   € ô $ DÐ/AÒBØˆwƒÜØmó
ð 	
ð r   TF)ÚfrozenÚreprc                  ó\   • \ rS rSr% SrS\S'   S\S'   SrS\S	'   SrS
\S'   SrS\S'   \	r
Srg)ÚSourcedInstructioné-   zSA lazy instruction recipe with the name and key its content should be addressed by.úAgentInstruction[AgentDepsT]Úinstructionr   Ú_Nz
str | Noner    zInstructionId | Noner   FÚboolÚdynamic© )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__r    r   r+   r   Ú__repr__Ú__static_attributes__r,   r   r   r%   r%   -   s4   ‡ á]à-Ó-àƒJà€Dˆ*ÓØ#€BÐÓ#Ø€GˆTÓà+ƒHr   r%   c           
     óÆ   • [        U [        5      (       a  U R                  OSnUb  [        U5        [	        U UUb	  [        XS9OS[        U [        [        45      (       + S9$ )a(  Attribute one instruction recipe to the source that authored it.

The single place a declared name meets its source, so every author applies the same rule: with a
source the name is qualified into an [`InstructionId`][pydantic_ai.messages.InstructionId] beneath
it, and without one there is no key to qualify against, so the name stays a name and the part
stays unaddressable.

A caller passes `None` for a recipe its source does not speak for -- a callable the agent was
built with, or instructions belonging to a single run rather than to the agent.
Nr   )r    r   r+   )Ú
isinstancer   r    r!   r%   r   Ústr)r(   Úsourcer    s      r   Úsourced_instructionr9   <   s_   € ô  *¨+´×GÑGˆ;×ÒÈT€DØÑÜ! $Ô'ÜØØØ/5Ñ/AŒ=˜Ò+ÀtÜ˜{¬S´/Ð,BÓCÔCñ	ð r   c           	   ƒ  óz  ^^	^
#   • / m	/ m/ m
SnSUU	U
4S jjnU  GH‘  nUR                   n[        U[        5      (       aQ  UR                  R	                  5       =n(       d  MH  U" 5         SnT	R                  [        XVUR                  S95        Mv  [        U[        5      (       as  UR	                  5       =n(       d  M¤  T(       a#  UR                  b  X$R                  :w  a  U" 5         UR                  nTR                  [        XdR                  S95        Mþ  [        R                  [           " U5      R                  U5      I Sh  v•N =n(       d  GM<  [        XdR                  UR                  UR                  S9nT(       a  T
R                  U5        GM€  T	R                  U5        GM”     U" 5         T	$  Nq7f)ad  Resolve authored instructions into the parts sent to the model.

Literal strings with the same source key form one addressable part. An
[`InstructionPart`][pydantic_ai.messages.InstructionPart] always remains independent so its
cache treatment applies only to its own text, while callable instructions are resolved lazily
against the current `RunContext`.
Nc                 óî   >• [         R                  " T5      =n (       a&  TR                  [        U TS   R                  S95        TR	                  5         TR                  T5        TR	                  5         g )Nr   ©Úcontentr   )r   ÚjoinÚappendr   ÚclearÚextend)r=   ÚgroupÚpartsÚpending_partss    €€€r   Úflush_groupÚ1resolve_sourced_instructions.<locals>.flush_groupc   sU   ø€ Ü%×*Ò*¨5Ó1Ð1ˆ7Õ1Ø�L‰Lœ°¸UÀ1¹X¿[¹[ÑIÔJØ�‰ŒØ�‰�]Ô#Ø×ÑÕr   r<   )r=   r    r   r+   )ÚreturnÚNone)r(   r6   r   r=   Ústripr?   r   r   r7   r   ÚSystemPromptRunnerr	   Úrunr    r+   )ÚinstructionsÚrun_contextÚ	group_keyrE   Úsourcedr(   r=   ÚpartrB   rC   rD   s           @@@r   Úresolve_sourced_instructionsrQ   T   s]  úé € ð $&€EØ#%€EØ+-€MØ&*€I÷ñ ô  ˆØ×)Ñ)ˆÜ�k¤?×3Ñ3Ø*×2Ñ2×8Ñ8Ó:Ð:�GÕ:ÙÙŒMØˆIØ�L‰Lœ À'Ç*Á*ÑMÖNÜ˜¤S×)Ñ)Ø*×0Ñ0Ó2Ð2�GÕ2ÙÞ˜'Ÿ*™*Ñ,°	¿Z¹ZÓ0GÙ”ØŸ
™
ˆIØ�L‰Lœ°¿Z¹ZÑHÖIä .× AÑ AÄ*Ò MÈkÓ Z× ^Ñ ^Ð_jÓ k×kÐkˆw×kÐkÜ&¨w¿\¹\ÈgÏjÉjÐbi×bqÑbqÑr�ÞØ!×(Ñ(¨×.à—L‘L ×&ñ+  ñ, „MØ€Lñ lùs   …EF;ÅF9Å	F;ÅA$F;c                ó~   • U c  / $ [        U [        [        45      (       d  [        U 5      (       a  U /$ [	        U 5      $ )N)r6   r7   r   ÚcallableÚlist)rL   s    r   Únormalize_instructionsrU   „   s>   € ð ÑØˆ	ä�,¤¤oÐ 6×7Ñ7¼8ÀL×;QÑ;QØˆ~ÐÜ�ÓÐr   c                ó  • U (       d  / $ [        U [        [        45      (       a  U /OU n/ nU HV  n[        U[        5      (       a  UO	[        USS9nUR                  R	                  5       (       d  ME  UR                  U5        MX     U$ )aµ  Normalize a toolset `get_instructions` result into non-empty parts, ids untouched.

A toolset may return a single `str` or `InstructionPart`, a sequence of either, or `None`. Plain
strings are treated as dynamic (they come from an external/changeable source) and whitespace-only
content is dropped. Ids are left exactly as the author wrote them, so whoever interprets them can
still tell a key issued below from a segment declared here.
T)r=   r+   )r6   r7   r   r=   rI   r?   )ÚresultÚitemsrC   ÚitemrP   s        r   Ú#normalize_toolset_instruction_partsrZ   �   sw   € ö Øˆ	Ü" 6¬C´Ð+A×BÑBˆV‰HÈ€EØ#%€EÛˆÜ! $¬×8Ñ8‰t¼oÐVZÐdhÑ>iˆØ�<‰<×Ñ×ÓØ�L‰L˜Öñ ð €Lr   )r   r7   r   r7   rG   rH   )r    r7   rG   rH   )r(   r'   r8   zInstructionSource | NonerG   zSourcedInstruction[AgentDepsT])rL   z(Sequence[SourcedInstruction[AgentDepsT]]rM   zRunContext[AgentDepsT]rG   úlist[InstructionPart])rL   zAgentInstructions[AgentDepsT]rG   z"list[AgentInstruction[AgentDepsT]])rW   z>str | InstructionPart | Sequence[str | InstructionPart] | NonerG   r[   )%Ú
__future__r   Úcollections.abcr   Údataclassesr   r   r   Útypingr   Úpydantic_ai._run_contextr	   r
   Úpydantic_ai._utilsr   Úpydantic_ai.exceptionsr   Úpydantic_ai.messagesr   r   r   Úpydantic_ai.templater   Ú r   Útoolsr   r7   ÚAgentInstructionÚAgentInstructionsr   r!   r%   r9   rQ   rU   rZ   r,   r   r   Ú<module>ri      s  ðÝ "å $ß 3Ñ 3Ý ç ;Ý ;Ý ,ß RÑ RÝ ,å Ý #à˜zÑ*¨SÑ0°?ÑBÐEUÐV`ÑEaÑaÐ ðQð
 % ZÑ0°8Ð<LÈZÑ<XÑ3YÑYÐ\`Ñ`Ð ôyô
ñ �$˜UÑ#ô,˜ Ñ,ó ,ó $ð,ðØ-ðØ7Oðà#ôð0-Ø:ð-ØI_ð-àô-ð`Ø/ðà'ôðØJðàõr   