ó
    ±"³j'è ã            	      ó|  • % S SK Jr  S SKrS SKrS SKJrJr  S SKJ	r	J
r
JrJrJrJr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JrJrJrJ r J!r!  S SK"r"S S
K#J$r$  S SK%J&r&  S SK'J(r(J)r)J*r*J+r+  S SK,J-r-  SSK.J/r/J0r0J1r1J2r2J3r4J5r5J6r6J7r7J8r9  SSK:J;r;J<r<J=r=  SSK>J?r?  SSK@JArA  SSKBJCrC  SSK2JDrD  SSKEJFrFJGrG  SSK6JHrHJIrIJJrJ  SSKKJLrLJMrMJNrN  SSKOJPrP  SSKQJRrR  SSK7JSrS  SSKTJUrUJVrVJWrWJXrXJYrYJZrZ  SSK[J\r\  \(       a(  S SK]J^r^  S SK_J`r`  S SKaJbrb  S S KcJdrdJereJfrfJgrgJhrhJiriJjrjJkrkJlrl  \+" S!5      rm\+" S"5      rn\o" S5      rp\+" S#5      rq \\X\U   S$/\S   4   rrS%\sS&'    \\X\U   S$/S'4   rtS%\sS('    \u\v\4   \\X\U   /\u\v\4   4   -  rw\0Rð                  rx \xry \P\\X\U   /\P4   -  rz  " S) S*\)S+S,9r{\\r\   /\\M\F      4   r|S%\sS-'     " S. S/\\F   \\4Rú                  \N\F   -     5      r~ " S0 S1\\F   \\~\F      5      r " S2 S3\\U\F4   \5      r€\ " S4 S55      5       r�\ " S6 S7\\U   5      5       r‚ " S8 S9\\U   5      rƒg):é    )ÚannotationsN)ÚABCÚabstractmethod)ÚAsyncGeneratorÚAsyncIterableÚAsyncIteratorÚ	AwaitableÚCallableÚ	GeneratorÚSequence)ÚExecutor)ÚAbstractAsyncContextManagerÚasynccontextmanagerÚcontextmanager)Ú	dataclass)Ú	FrameTypeÚTracebackType)ÚTYPE_CHECKINGÚAnyÚGenericÚ	TypeAliasÚcastÚoverload)ÚMemoryObjectReceiveStream)ÚTypeAdapter)ÚSelfÚ	TypedDictÚTypeIsÚTypeVar)ÚEndé   )	Ú_agent_graphÚ_instructionsÚ_utilsÚ
exceptionsÚmessagesÚmodelsÚresultÚtool_managerÚusage)ÚCancellationTokenÚ
RunBindingÚprovide_run_binding)Ú
JsonSchema)Útypes_from_output_spec)ÚAgentCapability)ÚRunCancelled)ÚOutputDataTÚ
OutputSpec)ÚAgentStreamÚFinalResultÚStreamedRunResult)ÚAgentRunÚAgentRunResultÚAgentRunResultEvent)ÚModelSettings)ÚTemplateStr)ÚToolManager)Ú
AgentDepsTÚAgentNativeToolÚDeferredToolResultsÚ
RunContextÚToolÚToolFuncEither)ÚAbstractToolset)Ú	AgentSpec)ÚCombinedCapability)ÚInstrumentationSettings)	ÚAudioRetentionÚKnownRealtimeModelNameÚRealtimeClientSecretÚRealtimeModelÚRealtimeModelProfileÚRealtimeModelSettingsÚRealtimeProviderSessionÚRealtimeSessionÚWebRTCAnswerÚTÚSÚRunOutputDataTú)AsyncIterable[_messages.AgentStreamEvent]r   ÚEventStreamHandlerú)AsyncIterator[_messages.AgentStreamEvent]ÚEventStreamProcessorc                  ó.   • \ rS rSr% SrS\S'   S\S'   Srg)ÚAgentRetriesém   u¿  Per-category retry budgets for an [`Agent`][pydantic_ai.agent.Agent].

Pass to `Agent(retries=...)` as a dict to set different budgets per category.

A bare `int` is shorthand for setting both `tools` and `output` to that value â€” the same at
every call site (`Agent(retries=N)`, `run()`, `iter()`, `override()`, and a run-time `spec`).
To set only one budget, pass a dict, e.g. `retries={'tools': ...}` or `retries={'output': ...}`.

Keys:
    tools: Default number of retries for tool calls before raising an error. Applies to function
        tools, output tools, and MCP tools, unless a more specific per-tool or per-toolset limit
        is set.
    output: Maximum number of retries for output validation. On the text path
        this is a global per-run budget; on the tool path it is the default
        per-tool `max_retries` for each output tool, overridable via
        [`ToolOutput(max_retries=...)`][pydantic_ai.output.ToolOutput.max_retries].
ÚintÚtoolsÚoutput© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__Ú__static_attributes__r]   ó    ÚW/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pydantic_ai/agent/abstract.pyrX   rX   m   s   ‡ ñð$ ƒJØ†Kre   rX   F)ÚtotalÚ_RunStreamEventsRunnerc                  ó¤   • \ rS rSrSrSS jrSS jrSS jrSS jrSS jr	SS jr
\SS	 j5       r\SS
 j5       rSS jrSS jrSS jrSS jrSrg)ÚAgentRunEventséˆ   aM  The event iterator returned by [`run_stream_events()`][pydantic_ai.agent.AbstractAgent.run_stream_events].

Lazily starts a background `run()` task on the first `__anext__()` and forwards its events over a memory
object stream, ending with a single trailing `AgentRunResultEvent` that carries the run's result. Entering
the context manager without iterating therefore never starts a run (https://github.com/pydantic/pydantic-ai/issues/6162).

This is a hand-written iterator class rather than an `async def` generator on purpose: generator cleanup
runs by throwing `GeneratorExit` into the suspended frame during finalization, which on Python 3.10/3.11
can resume the frame under a different `Context` and raise the `pydantic_ai.current_run_context` token
error (https://github.com/pydantic/pydantic-ai/issues/5132). Driving cleanup explicitly through `aclose()` keeps teardown in the caller's task and
context.

The handle can cancel the whole run and exposes its live messages and usage after iteration has
started. After successful completion, `result` contains the final run result.

`cancel()` and the state accessors (`all_messages()`, `new_messages()`, `usage`) require the run
to be driven through the standard [`Agent.iter()`][pydantic_ai.agent.Agent.iter] path, which binds
the run to this handle. The built-in `Agent` and the durable wrapper agents do this; a custom
[`AbstractAgent`][pydantic_ai.agent.AbstractAgent] subclass whose `run()`/`iter()` chain doesn't
consume that binding gets a `cancel()` that silently no-ops and state accessors that raise
`UserError`, even after iteration has started.
c                óf   • Xl         [        5       U l        S U l        S U l        SU l        SU l        g )NF)Ú
_run_agentr,   Ú_bindingÚ_receive_streamÚ_taskÚ_result_yieldedÚ_closed©ÚselfÚ	run_agents     rf   Ú__init__ÚAgentRunEvents.__init__¢   s7   € Ø#ŒÜ"›ˆŒð ð 	Ôð HLˆŒ
à$ˆÔØˆ�re   c                ó   • U $ ©Nr]   ©rt   s    rf   Ú	__aiter__ÚAgentRunEvents.__aiter__­   s   € Øˆre   c              ƒ  óV  #   • U R                   (       d  U R                  (       a  [        eU R                  c0  U R                  R
                  R                  (       a  [        S5      eU R                  5       I S h  v•N   U R                  c   eU R                  c   e U R                  R                  5       I S h  v•N $  NE N! [        R                   aM    U R                  R                  5       I S h  v•N    SU l        U R                  I S h  v•N  n[        U5      s $ f = f7f)NzThe agent run was cancelled.T)rr   rq   ÚStopAsyncIterationrp   rn   ÚcancellationÚcancel_requestedr1   Ú_ensure_startedro   ÚreceiveÚanyioÚEndOfStreamÚacloser9   )rt   r(   s     rf   Ú	__anext__ÚAgentRunEvents.__anext__°   sí   é € Ø�<�<˜4×/×/Ü$Ð$à�:‰:Ñ $§-¡-×"<Ñ"<×"M×"MÜÐ=Ó>Ð>à×"Ñ"Ó$×$Ð$Ø×#Ñ#Ñ/Ð/Ð/Ø�z‰zÑ%Ð%Ð%ð	/Ø×-Ñ-×5Ñ5Ó7×7Ð7ñ 	%ñ
 8øÜ× Ñ ó 	/ð ×&Ñ&×-Ñ-Ó/×/Ñ/Ø#'ˆDÔ ØŸ:™:×%Ð%ˆFÜ& vÓ.Ò.ð	/üs`   ‚A9D)Á;CÁ<"D)ÂC Â<CÂ=C Ã D)ÃC Ã1D&Ã6C9Ã7D&ÄDÄD&Ä#D)Ä%D&Ä&D)c                óL   • U R                   R                  R                  5         g)u¨  Request cancellation of the whole run.

This method is idempotent, is a no-op after completion, and is safe to call from another
task (e.g. a TUI's key handler) or thread â€” the underlying controller marshals onto the
run's event loop, just like [`CancellationToken.cancel()`][pydantic_ai.CancellationToken.cancel].
It does not affect external cancellation of the consumer task. If iteration continues, cancellation surfaces as
[`RunCancelled`][pydantic_ai.exceptions.RunCancelled]; leaving the context instead performs
quiet teardown. Cancelling before the first iteration prevents the run from starting at
all; iterating afterwards raises `RunCancelled` with empty `messages`.
N)rn   r   Úcancelrz   s    rf   r‰   ÚAgentRunEvents.cancelÅ   s   € ð 	�‰×"Ñ"×)Ñ)Õ+re   c                ó>   • U R                  5       R                  5       $ )zšReturn all messages from the run, including messages supplied as history.

Raises `UserError` if accessed before the first iteration has started the run.
)Ú
_agent_runÚall_messagesrz   s    rf   r�   ÚAgentRunEvents.all_messagesÒ   ó   € ð
 �‰Ó ×-Ñ-Ó/Ð/re   c                ó>   • U R                  5       R                  5       $ )zyReturn only messages created by the run.

Raises `UserError` if accessed before the first iteration has started the run.
)rŒ   Únew_messagesrz   s    rf   r‘   ÚAgentRunEvents.new_messagesÙ   r�   re   c                ó6   • U R                  5       R                  $ )zpReturn the run's current usage.

Raises `UserError` if accessed before the first iteration has started the run.
)rŒ   r*   rz   s    rf   r*   ÚAgentRunEvents.usageà   s   € ð �‰Ó ×&Ñ&Ð&re   c                ó¸   • U R                   nUbK  UR                  5       (       a6  UR                  5       (       d!  UR                  5       c  UR	                  5       $ g)zAReturn the successful run result once complete, otherwise `None`.N)rp   ÚdoneÚ	cancelledÚ	exceptionr(   )rt   Útasks     rf   r(   ÚAgentRunEvents.resultè   sD   € ð �z‰zˆØÑ §	¡	§¡°D·N±N×4DÑ4DÈÏÉÓIYÑIaØ—;‘;“=Ð Øre   c                ód   • U R                   R                  nUc  [        R                  " S5      eU$ )Nz2The run has not started; iterate the events first.)rn   Ú	agent_runr%   Ú	UserError)rt   rœ   s     rf   rŒ   ÚAgentRunEvents._agent_runð   s/   € Ø—M‘M×+Ñ+ˆ	ØÑÜ×&Ò&Ð'[Ó\Ð\ØÐre   c                óÖ   • U R                   R                  nUc  g[        R                  " SUR                  R
                  UR                  R                  5      R                  U5        g)av  Attach the run's state to an external cancellation of the consumer task.

The background run's own `CancelledError` (carrying the state attached by the translation
funnel) is consumed by `aclose()`'s drain, so the state is rebuilt from the live run and
attached to the consumer's propagating exception for `RunCancelled.from_cancellation()`.
No-op if the run never started.
Nz@The agent run was cancelled by an external asyncio cancellation.)rn   rœ   r"   Úrun_cancelled_snapshotÚctxÚstateÚdepsÚ
_attach_to)rt   Úexcrœ   s      rf   Ú_attach_run_stateÚ AgentRunEvents._attach_run_stateö   sR   € ð —M‘M×+Ñ+ˆ	ØÑØÜ×+Ò+ØNØ�M‰M×ÑØ�M‰M×Ñó	
÷ ‰*�S�/re   c              ƒ  ó^  #   • U R                   (       a  gSU l         U R                  b  U R                  R                  5         U R                  b"  U R                  R	                  5       I Sh  v•N   U R                  b)  [
        R                  " U R                  5      I Sh  v•N   gg N; N7f)zRCancel the background run (if started) and close the receive stream, idempotently.NT)rr   rp   r‰   ro   r…   r$   Úcancel_and_drainrz   s    rf   r…   ÚAgentRunEvents.aclose  s…   é € à�<�<ØàˆŒð �:‰:Ñ!Ø�J‰J×ÑÔØ×ÑÑ+Ø×&Ñ&×-Ñ-Ó/×/Ð/Ø�:‰:Ñ!Ü×)Ò)¨$¯*©*Ó5×5Ñ5ð "ñ 0á5ùs$   ‚A+B-Á-B)Á.4B-Â"B+Â#B-Â+B-c              ƒ  ó  ^ ^^#   • T R                   b  g [        R                  [        R                  [
        [           -     " 5       u  mnUT l        SU4S jjmSUU U4S jjn[        R                  " U" 5       5      T l         g 7f)Nc              “  ód   >#   • U  S h  v•N nTR                  U5      I S h  v•N   M$   N N
 g 7fry   )Úsend)Ú_ÚeventsÚeventÚsend_streams      €rf   Úevent_stream_handlerÚ<AgentRunEvents._ensure_started.<locals>.event_stream_handler%  s1   øé € Ù%÷ .�eØ!×&Ñ& uÓ-×-Ò-ñ.Ù-ñ  &ùs(   ƒ0†.Š*‹.Ž0£,¤0ª.¬0®0c               “  óB  >#   • T IS h  v•N   [        TR                  5         TR                  T5      I S h  v•N n S S S 5        [        R                  " 5         W sS S S 5      IS h  v•N   $  Nc N6! , (       d  f       N:= f N! , IS h  v•N  (       d  f       g = f7fry   )r-   rn   rm   r$   Úraise_if_cancelling)r(   r²   rt   r±   s    €€€rf   ru   Ú1AgentRunEvents._ensure_started.<locals>.run_agent)  s_   øé € ç"’{Ü(¨¯©Õ7Ø#'§?¡?Ð3GÓ#H×H�F÷ 8ô
 ×*Ò*Ô,Ø÷ #—{“{áH÷ 8Õ7ú÷ #—{—{�{üsj   ƒBŠA.‹BŽB¤A2¹A0ºA2¾BÁBÁ(BÁ)BÁ0A2Á2
B 	Á<BÂBÂBÂBÂBÂB)r®   zRunContext[Any]r¯   rS   ÚreturnÚNone)r·   úAgentRunResult[OutputDataT])
rp   rƒ   Úcreate_memory_object_streamÚ	_messagesÚAgentStreamEventr9   r2   ro   ÚasyncioÚcreate_task)rt   Úreceive_streamru   r²   r±   s   `  @@rf   r�   ÚAgentRunEvents._ensure_started  sr   úé € Ø�:‰:Ñ!Øô ',×&GÑ&GÜ×&Ñ&Ô)<¼[Ñ)IÑIò'
ó 'Ñ#ˆ�^ð  .ˆÔ÷	.÷		ñ 		ô ×(Ò(©«Ó5ˆ�
ùs   …B B)rn   rr   ro   rq   rm   rp   N©ru   z#_RunStreamEventsRunner[OutputDataT]r·   r¸   )r·   zLAsyncIterator[_messages.AgentStreamEvent | AgentRunResultEvent[OutputDataT]])r·   z=_messages.AgentStreamEvent | AgentRunResultEvent[OutputDataT]©r·   r¸   )r·   úlist[_messages.ModelMessage])r·   z_usage.RunUsage)r·   z"AgentRunResult[OutputDataT] | None)r·   zAgentRun[Any, OutputDataT])r¥   ÚBaseExceptionr·   r¸   )r^   r_   r`   ra   rb   rv   r{   r†   r‰   r�   r‘   Úpropertyr*   r(   rŒ   r¦   r…   r�   rd   r]   re   rf   rj   rj   ˆ   sa   † ñô.	ôô/ô*,ô0ô0ð ó'ó ð'ð óó ðôôô"6÷&6re   rj   c                  óF   • \ rS rSrSrSS jrS	S jr        S
S jrSrg)Ú_RunStreamEventsContexti7  a  The async context manager returned by [`run_stream_events()`][pydantic_ai.agent.AbstractAgent.run_stream_events].

Hands out a single `AgentRunEvents` on entry and closes it on exit, so an early `break` out of
the event loop still cancels and drains the background run.
c                ó   • Xl         S U l        g ry   )rm   Ú	_iteratorrs   s     rf   rv   Ú _RunStreamEventsContext.__init__>  s   € Ø#ŒØ=Aˆ�re   c              ƒ  ó†   #   • U R                   b  [        S5      e[        U R                  5      U l         U R                   $ 7f)NzF`run_stream_events()` context manager cannot be entered more than once)rÉ   ÚRuntimeErrorrj   rm   rz   s    rf   Ú
__aenter__Ú"_RunStreamEventsContext.__aenter__B  s7   é € ð �>‰>Ñ%ÜÐgÓhÐhÜ'¨¯©Ó8ˆŒØ�~‰~Ðùs   ‚?Ac              ƒ  óæ   #   • U R                   b^  U R                   R                  5       I S h  v•N   [        U[        R                  5      (       a  U R                   R                  U5        g g g  NA7fry   )rÉ   r…   Ú
isinstancer½   ÚCancelledErrorr¦   )rt   Úexc_typeÚ	exc_valueÚ	tracebacks       rf   Ú	__aexit__Ú!_RunStreamEventsContext.__aexit__K  s[   é € ð �>‰>Ñ%Ø—.‘.×'Ñ'Ó)×)Ð)ô ˜)¤W×%;Ñ%;×<Ñ<Ø—‘×0Ñ0°Õ;ð =ð &Ù)ùs   ‚+A1­A/®AA1)rÉ   rm   NrÁ   )r·   zAgentRunEvents[OutputDataT])rÒ   ztype[BaseException] | NonerÓ   zBaseException | NonerÔ   zTracebackType | Noner·   r¸   )	r^   r_   r`   ra   rb   rv   rÍ   rÕ   rd   r]   re   rf   rÇ   rÇ   7  s=   † ñôBôð<à,ð<ð (ð<ð (ð	<ð
 
÷<re   rÇ   c                  óà  • \ rS rSrSr\\SDS j5       5       r\\SES j5       5       r\R                  \SFS j5       5       r\\SES j5       5       r
\
R                  \SGS j5       5       r
\\SHS j5       5       r\\SIS	 j5       5       r\\SJS
 j5       5       r\SKS j5       rSLS jr\\SMS j5       5       rSSSSSSS.             SNS jjrSOSPS jjr\ SOSSSSSSSSSSSSSSSSSSSS.                                         SQS jjj5       r\ SOSSSSSSSSSSSSSSSSSSS.                                         SRS jjj5       r SOSSSSSSSSSSSSSSSSSSSS.                                         SSS jjjr\ SOSSSSSSSSSSSSSSSSSSSS.                                         SQS jjj5       r\ SOSSSSSSSSSSSSSSSSSSS.                                         SRS jjj5       r SOSSSSSSSSSSSSSSSSSSSS.                                         SSS jjjr\ SOSSSSSSSSSSSSSSSSSSSS.                                         STS jjj5       r\ SOSSSSSSSSSSSSSSSSSSS.                                         SUS jjj5       r\ SOSSSSSSSSSSSSSSSSSSSS.                                         SVS jjj5       r\ SOSSSSSSSSSSSSSSSSSSS.                                       SWS jjj5       r\ SOSSSSSSSSSSSSSSSSSS .                                       SXS! jjj5       r SOSSSSSSSSSSSSSSSSSSS.                                       SYS" jjjr\ SOSSSSSSSSSSSSSSSSSSS#.                                       SZS$ jjj5       r\ SOSSSSSSSSSSSSSSSSSS%.                                       S[S& jjj5       r SOSSSSSSSSSSSSSSSSSSS#.                                       S\S' jjjr\ SOSSSSSSSSSSSSSSSSSSS#.                                       S]S( jjj5       r\ SOSSSSSSSSSSSSSSSSSS%.                                       S^S) jjj5       r\\ SOSSSSSSSSSSSSSSSSSSS#.                                       S_S* jjj5       5       r\\\R:                  \R:                  \R:                  \R:                  \R:                  \R:                  \R:                  \R:                  \R:                  \R:                  SS+.                       S`S, jj5       5       rSSSSSSSSSSSS-.                         SaS. jjr\SSSSSSSSSSSS/S0.                           SbS1 jj5       r \SSSSSSSSSSSS2S/S3S4SS5.                                   ScS6 jj5       r!SdS7 jr"\#\SeSfS8 jj5       5       r$\#\SgS9 j5       5       r%\#\ShS: j5       5       r&\#    SiS; j5       r'\#    SjS< j5       r(\#    SkS= j5       r)\#    SlS> j5       r*\SmS? j5       r+\SnS@ j5       r,      So               SpSA jjr-      So               SpSB jjr.SCr/g)qÚAbstractAgentiZ  z˜Abstract superclass for [`Agent`][pydantic_ai.agent.Agent], [`WrapperAgent`][pydantic_ai.agent.WrapperAgent], and your own custom agent implementations.c                ó   • [         e)z,The default model configured for this agent.©ÚNotImplementedErrorrz   s    rf   ÚmodelÚAbstractAgent.model]  ó
   € ô "Ð!re   c                ó   • [         e)z…The name of the agent, used for logging.

If `None`, we try to infer the agent name from the call frame when the agent is first run.
rÚ   rz   s    rf   ÚnameÚAbstractAgent.namec  ó
   € ô "Ð!re   c                ó   • [         e)z,Set the name of the agent, used for logging.rÚ   ©rt   Úvalues     rf   rà   rá   l  rÞ   re   c                ó   • [         e)z*A human-readable description of the agent.rÚ   rz   s    rf   ÚdescriptionÚAbstractAgent.descriptionr  rÞ   re   c                ó   • [         e)z!Set the description of the agent.rÚ   rä   s     rf   rç   rè   x  rÞ   re   c                ó   • [         e)z+The type of dependencies used by the agent.rÚ   rz   s    rf   Ú	deps_typeÚAbstractAgent.deps_type~  rÞ   re   c                ó   • [         e)zjThe type of data output by agent runs, used to validate the data returned by the model, defaults to `str`.rÚ   rz   s    rf   Úoutput_typeÚAbstractAgent.output_type„  rÞ   re   c                ó   • [         e)zcOptional handler for events from the model's streaming response and the agent's execution of tools.rÚ   rz   s    rf   r²   Ú"AbstractAgent.event_stream_handlerŠ  rÞ   re   c                ó   • [         e)zIThe root capability of the agent, containing all registered capabilities.rÚ   rz   s    rf   Úroot_capabilityÚAbstractAgent.root_capability�  s
   € ô "Ð!re   c                ó   • g)z<Return the agent's private validation-context specification.Nr]   rz   s    rf   Ú_get_validation_contextÚ%AbstractAgent._get_validation_context•  s   € àre   c                ó   • [         e)zFAll toolsets registered on the agent.

Output tools are not included.
rÚ   rz   s    rf   ÚtoolsetsÚAbstractAgent.toolsets™  râ   re   N)r£   rÜ   Úmessage_historyÚpromptr*   Úmodel_settingsc             ƒ  ó   #   • / $ 7f)up  Resolve the agent's configured system prompts into `SystemPromptPart`s.

Returns a list suitable for prepending to a `ModelRequest`. Static strings and
runners decorated with [`@agent.system_prompt`][pydantic_ai.agent.Agent.system_prompt]
are evaluated using a minimal `RunContext` built from the provided kwargs â€” useful
when reconstructing a `message_history` that should carry the agent's configured
system prompt (e.g. in UI adapters or after history compaction).

Dynamic runners produce parts with `dynamic_ref` set so they can continue to be
re-evaluated by the standard agent graph path on subsequent turns.

Args:
    deps: Optional dependencies for dynamic system prompt functions.
    model: Optional model to use for `RunContext.model`. Falls back to the
        agent's configured model; required only if the agent has no model set.
    message_history: Optional message history to expose as `RunContext.messages`.
    prompt: Optional user prompt to expose as `RunContext.prompt`.
    usage: Optional usage to expose as `RunContext.usage`.
    model_settings: Optional settings to expose as `RunContext.model_settings`.
r]   )rt   r£   rÜ   rû   rü   r*   rý   s          rf   Úsystem_prompt_partsÚ!AbstractAgent.system_prompt_parts¢  s   é € ð> ˆ	ùs   ‚c                ó"  • Uc  U R                   n[        US9n/ nU H3  n[        U5      R                  SS9nXS;  d  M"  UR	                  U5        M5     [        U5      S:X  a  US   $ [        R                  " U5      u  p6SU0nU(       a  XeS'   U$ )zThe output return JSON schema.)Úoutput_specÚserialization©Úmodeé   r   ÚanyOfz$defs)rî   r/   r   Újson_schemaÚappendÚlenr$   Úmerge_json_schema_defs)rt   rî   Úreturn_typesÚjson_schemasÚreturn_typer  Úall_defss          rf   Úoutput_json_schemaÚ AbstractAgent.output_json_schemaÃ  sŸ   € àÑØ×*Ñ*ˆKä-¸+ÑFˆà)+ˆÛ'ˆKÜ% kÓ2×>Ñ>ÀOÐ>ÐTˆKØÕ.Ø×#Ñ# KÖ0ñ (ô
 ˆ|Ó Ó!Ø ‘?Ð"ä%+×%BÒ%BÀ<Ó%PÑ"ˆLØ'.°Ð&=ˆKÞØ'/˜GÑ$ØÐre   T©rî   rû   Údeferred_tool_resultsÚconversation_idÚrun_idrÜ   Úinstructionsr£   rý   Úusage_limitsÚcancellation_tokenr*   ÚmetadataÚretriesÚ
infer_namerù   r²   ÚcapabilitiesÚspecc             ƒ  ó   #   • g 7fry   r]   ©rt   Úuser_promptrî   rû   r  r  r  rÜ   r  r£   rý   r  r  r*   r  r  r  rù   r²   r  r  s                        rf   ÚrunÚAbstractAgent.runÙ  s
   é € ð0 '*ùó   ‚)rû   r  r  r  rÜ   r  r£   rý   r  r  r*   r  r  r  rù   r²   r  r  c             ƒ  ó   #   • g 7fry   r]   r  s                        rf   r!  r"  ó  s
   é € ð0 *-ùr#  c             ƒ  óÈ  ^ ^^#   • U(       a1  T R                   c$  T R                  [        R                  " 5       5        U=(       d    T R                  nT R                  UUUUUUUUU	U
UUUUUUUUS9 ISh  v•N mSnU=mb      SUUU 4S jjnUnTR                  n[        U[        5      (       d\  TR                  b  ONUb  TR                  UU5      I Sh  v•N nOTR                  U5      I Sh  v•N n[        U[        5      (       d  M\  SSS5      ISh  v•N   TR                  c   S5       eTR                  $  NÈ Ng NO N*! , ISh  v•N  (       d  f       N?= f7f)aÒ  Run the agent with a user prompt in async mode.

This method builds an internal agent graph (using system prompts, tools and output schemas) and then
runs the graph to completion. The result of the run is returned.

Example:
```python
from pydantic_ai import Agent

agent = Agent('openai:gpt-5.2')

async def main():
    agent_run = await agent.run('What is the capital of France?')
    print(agent_run.output)
    #> The capital of France is Paris.
```

Args:
    user_prompt: User input to start/continue the conversation.
    output_type: Custom output type to use for this run, `output_type` may only be used if the agent has no
        output validators since output validators would expect an argument that matches the agent's output type.
    message_history: History of the conversation so far.
    deferred_tool_results: Optional results for deferred tool calls in the message history.
    conversation_id: ID of the conversation this run belongs to. Pass `'new'` to start a fresh conversation, ignoring any `conversation_id` already on `message_history`. If omitted, falls back to the most recent `conversation_id` on `message_history` or a freshly generated UUID7.
    run_id: Optional ID for this agent run. Unlike `conversation_id`, never inherited from `message_history`. Passing an empty string, or a value that already appears on `message_history`, raises `UserError` because both break `new_messages()`; use `conversation_id` to correlate across turns or deferred-tool resume. If omitted, a fresh UUID7 is generated.
    model: Optional model to use for this run, required if `model` was not set when creating the agent.
    instructions: Optional additional instructions to use for this run.
    deps: Optional dependencies to use for this run.
    model_settings: Optional settings to use for this model's request, or a callable
        that receives [`RunContext`][pydantic_ai.tools.RunContext] and returns settings.
        Callables are called before each model request, allowing dynamic per-step settings.
    usage_limits: Optional limits on model request count or token usage.
    cancellation_token: Token used to cancel this run from another task or thread. Single-use:
        mint a fresh token per run, as a reused (already-cancelled) token prevents the run from starting.
    usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
    metadata: Optional metadata to attach to this run. Accepts a dictionary or a callable taking
        [`RunContext`][pydantic_ai.tools.RunContext]; merged with the agent's configured metadata.
    retries: Override the agent-level retry budgets for this run. Pass an `int` to override both
        the tool-retry and output budgets, or an [`AgentRetries`][pydantic_ai.AgentRetries] dict to
        override just one (e.g. `retries={'tools': 3}`). See
        [`Agent.__init__`][pydantic_ai.agent.Agent.__init__] for semantics of the two enforcement paths.
    infer_name: Whether to try to infer the agent name from the call frame if it's not set.
    toolsets: Optional additional toolsets for this run.
    event_stream_handler: Optional handler for events from the model's streaming response and the agent's execution of tools to use for this run. Under a durability capability, this per-run handler runs workflow-side; model events are replayed after each model request completes. For handler I/O inside the durable boundary, pass `event_stream_handler=` to the durability capability.
    capabilities: Optional additional [capabilities](https://pydantic.dev/docs/ai/capabilities/overview/) for this run, merged with the agent's configured capabilities.
    spec: Optional agent spec to apply for this run. At run time, spec values are additive.

Returns:
    The result of the run.
N)r   rî   rû   r  r  r  rÜ   r  r£   rý   r  r  r*   r  r  rù   r  r  c              “  óÄ  >#   • TR                  U 5      (       d  TR                  U 5      (       aa  U R                  TR                  5       IS h  v•N n[        R
                  " TR                  5      nT" X!5      I S h  v•N   U  S h  v•N nM  TR                  U 5      I S h  v•N $  NZ N, N#
 S S S 5      IS h  v•N    M3  ! , IS h  v•N  (       d  f       NJ= f N87fry   )Úis_model_request_nodeÚis_call_tools_nodeÚstreamr¡   r"   Úbuild_run_contextÚ_advance_graph)Únr)  Úrun_ctxr®   Ú_handlerrœ   rt   s       €€€rf   Ú_stream_and_advanceÚ.AbstractAgent.run.<locals>._stream_and_advance~  s¯   øé € ð ×1Ñ1°!×4Ñ4¸×8OÑ8OÐPQ×8RÑ8Rð $%§8¡8¨I¯M©M×#:Ô#:¸fÜ&2×&DÒ&DÀYÇ]Á]Ó&S˜GÙ"*¨7Ó";×;Ð;ñ ,2÷ % aÙ $Ø!*×!9Ñ!9¸!Ó!<×<Ð<ñ $;á;ñ%¨6÷ $;×#:×#:×#:×#:Ñ#:úñ =ùsŠ   ƒAC ÁB*ÁC Á,CÁ?B,Â CÂB0Â
B.ÂB0ÂCÂC Â%CÂ&C Â,CÂ.B0Â0CÂ1C Â<B?Â=C ÃCÃ
CÃCÃC z%The graph run did not finish properly)r,  z'_agent_graph.AgentNode[AgentDepsT, Any]r·   z?_agent_graph.AgentNode[AgentDepsT, Any] | End[FinalResult[Any]])rà   Ú_infer_nameÚinspectÚcurrentframer²   ÚiterÚ	next_noderÐ   r    r(   Ú_run_node_with_hooksÚnext)rt   r   rî   rû   r  r  r  rÜ   r  r£   rý   r  r  r*   r  r  r  rù   r²   r  r  Ú_stream_stepr/  Únoder.  rœ   s   `                       @@rf   r!  r"    s  úé € öT ˜$Ÿ)™)Ñ+Ø×ÑœW×1Ò1Ó3Ô4à3×P°t×7PÑ7PÐà—9‘9Ø#Ø#Ø+Ø"7Ø+ØØØ%ØØ)Ø%Ø1ØØØØØ%Øð% ÷ 
ñ 
ð& ð ð ð 1Ð0�Ñ=ð=Ø>ð=àT÷=ñ =ð   3�à×&Ñ&ˆDÜ  ¤s×+Ñ+à×#Ñ#Ñ/ØØÑ+Ø!*×!?Ñ!?ÀÀlÓ!S×S‘Dà!*§¡°Ó!5×5�Dô ! ¤s×+Ó+÷k
÷ 
ð| ×ÑÑ+ÐTÐ-TÓTÐ+Ø×ÑÐñ
ñt Tá5÷y
÷ 
÷ 
ð 
üsm   …A2E"Á7E Á8E"Á;AEÃEÃEÃ4EÃ5EÄE"ÄEÄ%E"ÅEÅEÅE"ÅEÅEÅEÅE"c               ó   • g ry   r]   r  s                        rf   Úrun_syncÚAbstractAgent.run_sync�  s   € ð0 '*re   c               ó   • g ry   r]   r  s                        rf   r;  r<  ·  s   € ð0 *-re   c               ó  • [         R                  " 5         U(       a1  U R                  c$  U R                  [        R
                  " 5       5        [         R                  " U R                  UUUUUUUUU	U
UUUUUSUUUUS95      $ )a)  Synchronously run the agent with a user prompt.

This is a convenience method that wraps [`self.run`][pydantic_ai.agent.AbstractAgent.run] with `loop.run_until_complete(...)`.
You therefore can't use this method inside async code or if there's an active event loop.

This method cannot be used inside a synchronous tool, output function, or other function called
during an agent run. To delegate to another agent, make the function `async def` and
`await` [`self.run`][pydantic_ai.agent.AbstractAgent.run] instead. See
[Agent delegation](../multi-agent-applications.md#agent-delegation).

Example:
```python
from pydantic_ai import Agent

agent = Agent('openai:gpt-5.2')

result_sync = agent.run_sync('What is the capital of Italy?')
print(result_sync.output)
#> The capital of Italy is Rome.
```

Args:
    user_prompt: User input to start/continue the conversation.
    output_type: Custom output type to use for this run, `output_type` may only be used if the agent has no
        output validators since output validators would expect an argument that matches the agent's output type.
    message_history: History of the conversation so far.
    deferred_tool_results: Optional results for deferred tool calls in the message history.
    conversation_id: ID of the conversation this run belongs to. Pass `'new'` to start a fresh conversation, ignoring any `conversation_id` already on `message_history`. If omitted, falls back to the most recent `conversation_id` on `message_history` or a freshly generated UUID7.
    run_id: Optional ID for this agent run. Unlike `conversation_id`, never inherited from `message_history`. Passing an empty string, or a value that already appears on `message_history`, raises `UserError` because both break `new_messages()`; use `conversation_id` to correlate across turns or deferred-tool resume. If omitted, a fresh UUID7 is generated.
    model: Optional model to use for this run, required if `model` was not set when creating the agent.
    instructions: Optional additional instructions to use for this run.
    deps: Optional dependencies to use for this run.
    model_settings: Optional settings to use for this model's request, or a callable
        that receives [`RunContext`][pydantic_ai.tools.RunContext] and returns settings.
        Callables are called before each model request, allowing dynamic per-step settings.
    usage_limits: Optional limits on model request count or token usage.
    cancellation_token: Token used to cancel this run from another task or thread. Single-use:
        mint a fresh token per run, as a reused (already-cancelled) token prevents the run from starting.
    usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
    metadata: Optional metadata to attach to this run. Accepts a dictionary or a callable taking
        [`RunContext`][pydantic_ai.tools.RunContext]; merged with the agent's configured metadata.
    retries: Override the agent-level retry budgets for this run. Pass an `int` to override both
        the tool-retry and output budgets, or an [`AgentRetries`][pydantic_ai.AgentRetries] dict to
        override just one (e.g. `retries={'tools': 3}`). See
        [`Agent.__init__`][pydantic_ai.agent.Agent.__init__] for semantics of the two enforcement paths.
    infer_name: Whether to try to infer the agent name from the call frame if it's not set.
    toolsets: Optional additional toolsets for this run.
    event_stream_handler: Optional handler for events from the model's streaming response and the agent's execution of tools to use for this run. Under a durability capability, this per-run handler runs workflow-side; model events are replayed after each model request completes. For handler I/O inside the durable boundary, pass `event_stream_handler=` to the durability capability.
    capabilities: Optional additional [capabilities](https://pydantic.dev/docs/ai/capabilities/overview/) for this run, merged with the agent's configured capabilities.
    spec: Optional agent spec to apply for this run. At run time, spec values are additive.

Returns:
    The result of the run.
Fr  )r$   Úcheck_no_nested_sync_runrà   r1  r2  r3  Úrun_until_completer!  r  s                        rf   r;  r<  Ñ  s”   € ô\ 	×'Ò'Ô)æ˜$Ÿ)™)Ñ+Ø×ÑœW×1Ò1Ó3Ô4ä×(Ò(Ø�H‰HØØ'Ø /Ø&;Ø /ØØØ)ØØ-Ø)Ø#5ØØ!ØØ Ø!Ø%9Ø)Øð) ð ó
ð 	
re   c               ó   • g ry   r]   r  s                        rf   Ú
run_streamÚAbstractAgent.run_stream=  s	   € ð0 Z]re   c               ó   • g ry   r]   r  s                        rf   rB  rC  W  s	   € ð0 ]`re   c              ó.	  ^ ^!^"^#^$^%#   • U(       aD  U R                   c7  [        R                  " 5       =n(       a  U R                  UR                  5        U=(       d    U R
                  nSnU R                  UUUUUUUU	UU
UUUUUSUUUS9 ISh  v•N m T R                  bN  T R                  m#[        T#R                  R                  T#R                  R                  T R                  S97v •  SnT R                  n[        U[         R"                  5      (       d   eUnU(       Gd  T R                  m#[         R$                  " T#5      nT#R                  R&                  nUR)                  UUS9I Sh  v•N nU R+                  U5      (       aQ  UR-                  T#5       ISh  v•N m%Sm"    SU"4S jjnU" T%5      nUb  U" UU5      I Sh  v•N   U  Sh  v•N nM  U R7                  U5      (       aE  UR-                  T R                  5       ISh  v•N m%Ub  U" UT%5      I Sh  v•N   T%  Sh  v•N nM  [         R$                  " T#5      nT R9                  UUT R:                  5      I Sh  v•N n[        U[<        5      (       aP  T R                  bC  [        T#R                  R                  T#R                  R                  T R                  S97v •  SnOf[        U[         R>                  5      (       d  [@        RB                  " S	5      e[E        [         R>                  [F        [F        4   U5      nU(       d  GM  SSS5      ISh  v•N   U(       d  [@        RB                  " S
5      eg GNÝ GNþ GNÑ GNª GN¢
 T"bŒ  [/        ST"R0                  T"R2                  5      m!SnT#R                  R                  R5                  5       m$SU U!U#U$U%4S jjn[        T$T#R                  R                  T%U5      7v •   SSS5      ISh  v•N    MÍ  SSS5      ISh  v•N    GMç  ! , ISh  v•N  (       d  f       GNÿ= f GN( GN GN
 SSS5      ISh  v•N    GM   ! , ISh  v•N  (       d  f       GN8= f GN GN-! , ISh  v•N  (       d  f       GNC= f7f)a½  Run the agent with a user prompt in async streaming mode.

This method builds an internal agent graph (using system prompts, tools and output schemas) and then
runs the graph until the model produces output matching the `output_type`, for example text or structured data.
At this point, a streaming run result object is yielded from which you can stream the output as it comes in,
and -- once this output has completed streaming -- get the complete output, message history, and usage.

As this method will consider the first output matching the `output_type` to be the final output,
it will stop running the agent graph and will not execute any tool calls made by the model after this "final" output.
If you want to always run the agent graph to completion and stream events and output at the same time,
use [`agent.run()`][pydantic_ai.agent.AbstractAgent.run] with an `event_stream_handler` or [`agent.iter()`][pydantic_ai.agent.AbstractAgent.iter] instead.

Example:
```python
from pydantic_ai import Agent

agent = Agent('openai:gpt-5.2')

async def main():
    async with agent.run_stream('What is the capital of the UK?') as response:
        print(await response.get_output())
        #> The capital of the UK is London.
```

Args:
    user_prompt: User input to start/continue the conversation.
    output_type: Custom output type to use for this run, `output_type` may only be used if the agent has no
        output validators since output validators would expect an argument that matches the agent's output type.
    message_history: History of the conversation so far.
    deferred_tool_results: Optional results for deferred tool calls in the message history.
    conversation_id: ID of the conversation this run belongs to. Pass `'new'` to start a fresh conversation, ignoring any `conversation_id` already on `message_history`. If omitted, falls back to the most recent `conversation_id` on `message_history` or a freshly generated UUID7.
    run_id: Optional ID for this agent run. Unlike `conversation_id`, never inherited from `message_history`. Passing an empty string, or a value that already appears on `message_history`, raises `UserError` because both break `new_messages()`; use `conversation_id` to correlate across turns or deferred-tool resume. If omitted, a fresh UUID7 is generated.
    model: Optional model to use for this run, required if `model` was not set when creating the agent.
    instructions: Optional additional instructions to use for this run.
    deps: Optional dependencies to use for this run.
    model_settings: Optional settings to use for this model's request, or a callable
        that receives [`RunContext`][pydantic_ai.tools.RunContext] and returns settings.
        Callables are called before each model request, allowing dynamic per-step settings.
    usage_limits: Optional limits on model request count or token usage.
    cancellation_token: Token used to cancel this run from another task or thread. Single-use:
        mint a fresh token per run, as a reused (already-cancelled) token prevents the run from starting.
    usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
    metadata: Optional metadata to attach to this run. Accepts a dictionary or a callable taking
        [`RunContext`][pydantic_ai.tools.RunContext]; merged with the agent's configured metadata.
    retries: Override the agent-level retry budgets for this run. Pass an `int` to override both
        the tool-retry and output budgets, or an [`AgentRetries`][pydantic_ai.AgentRetries] dict to
        override just one (e.g. `retries={'tools': 3}`). See
        [`Agent.__init__`][pydantic_ai.agent.Agent.__init__] for semantics of the two enforcement paths.
    infer_name: Whether to try to infer the agent name from the call frame if it's not set.
    toolsets: Optional additional toolsets for this run.
    event_stream_handler: Optional handler for events from the model's streaming response and the agent's execution of tools to use for this run. Under a durability capability, this per-run handler runs workflow-side; model events are replayed after each model request completes. For handler I/O inside the durable boundary, pass `event_stream_handler=` to the durability capability.
        It will receive all the events up until the final result is found, which you can then read or stream from inside the context manager.
        Note that it does _not_ receive any events after the final result is found.
    capabilities: Optional additional [capabilities](https://pydantic.dev/docs/ai/capabilities/overview/) for this run, merged with the agent's configured capabilities.
    spec: Optional agent spec to apply for this run. At run time, spec values are additive.

Returns:
    The result of the run.
NF)rî   rû   r  r  r  rÜ   r£   r  rý   r  r  r*   r  r  r  rù   r  r  )Ú
run_resultT©r9  c               ó~   >#   • U   S h  v•N nU7v •  [        U[        R                  5      (       d  M/  Um  g  N.
 g 7fry   )rÐ   r»   ÚFinalResultEvent)r)  r°   Úfinal_result_events     €rf   Ústream_to_finalÚ1AbstractAgent.run_stream.<locals>.stream_to_finalû  s:   øé € ñ 06÷ * eØ&+£Ü#-¨e´Y×5OÑ5O×#PÓ#PØ9>Ð$6Ù$)ñ	*©vùs    ƒ=†;Š9‹;Ž#=µ=¹;»=c            
   “  óP  >#   • [        TR                  5       I Sh  v•N TR                  TR                  5      m/ n [        R
                  " TR                  R                  TR                  R                  SSTTU S9  Sh  v•N nM   Nm N
 U (       aa  TR                  [        R                  " U TR                  R                  TR                  R                  [         R"                  " 5       S95        TR%                  [        R&                  " T5      5      I Sh  v•N    g7f)zŒCalled when the stream has completed.

The model response will have been added to messages by now
by `StreamedRunResult._marked_completed`.
N)r)   Ú
tool_callsÚtool_call_resultsÚtool_call_metadataÚfinal_resultr¡   Úoutput_parts)r  r  Ú	timestamp)r5   Ú
get_outputÚ	tool_nameÚtool_call_idr"   Úprocess_tool_callsr£   r)   ÚresponserN  r	  r»   ÚModelRequestr¢   r  r  r$   Únow_utcr7  ÚSetFinalResult)ÚpartsÚ_eventrœ   rQ  Ú	graph_ctxr&   r)  s     €€€€€rf   Úon_completeÚ-AbstractAgent.run_stream.<locals>.on_complete  só   øé € ô 0;Ø*0×*;Ñ*;Ó*=×$=¸|×?UÑ?UÐWc×WpÑWpó0" ð KM Ü4@×4SÒ4SØ1:·±×1LÑ1LØ/5¯©×/IÑ/IØ6:Ø7;Ø1=Ø(1Ø16ò5"÷ 	!)¨&ñ %)ñ+ %>ñ	!)ð 5"ö $)Ø$,§O¡OÜ(1×(>Ò(>Ø,1Ø3<·?±?×3IÑ3IØ<E¿O¹O×<[Ñ<[Ü6<·n²nÓ6Fñ	)*ô%&ð '0§n¡n´\×5PÒ5PÐQ]Ó5^Ó&_× _Ò _ùsA   ƒD&œB
�A"D&Á?BÂBÂBÂD&ÂBÂBD&ÄD"Ä D&z<Should have produced a StreamedRunResult before getting herez3Agent run finished without producing a final result)r)  r4   r·   rU   rÂ   )$rà   r2  r3  r1  Úf_backr²   r4  r(   r¡   r6   r¢   rû   r£   Únew_message_indexr5  rÐ   r"   ÚUserPromptNoder*  ró   Úbefore_node_runr'  r)  r5   rU  rV  Úcopyr(  Ú_wrap_and_advancer+  r    Ú	AgentNoder%   ÚAgentRunErrorr   r   )&rt   r   rî   rû   r  r  r  rÜ   r  r£   rý   r  r  r*   r  r  r  rù   r²   r  r  ÚframeÚyieldedÚ
first_noder9  r-  ÚcaprK  Ú	truncatedr®   r_  r5  rœ   rQ  rJ  r^  r&   r)  s&                                   @@@@@@rf   rB  rC  q  s  ýé € öh ˜$Ÿ)™)Ñ+ä×,Ò,Ó.Ð.ˆuÕ.Ø× Ñ  §¡Ô.à3×P°t×7PÑ7PÐàˆØ—9‘9ØØ#Ø+Ø"7Ø+ØØØØ%Ø)Ø%Ø1ØØØØØØ%Øð' ÷ 
ñ 
ð( à×ÑÑ+Ø%ŸM™M�	Ü'Ø—O‘O×3Ñ3Ø—N‘N×4Ñ4Ø(×/Ñ/ñó ð
 �à"×,Ñ,ˆJÜ˜j¬,×*EÑ*E×FÑFÐFÐFØ5?ˆDßØ%ŸM™M�	ô '×8Ò8¸ÓC�Ø—n‘n×4Ñ4�Ø ×0Ñ0°¸tÐ0ÐD×D�à×-Ñ-¨d×3Ñ3Ø#Ÿ{™{¨9×5Ô5¸Ø-1Ð*ð*Ø$/ð*àF÷*ñ %4°FÓ$;˜	Ø/Ñ;Ù"6°wÀ	Ó"J×JÐJñ (1÷ ! !Ù ðD ×,Ñ,¨T×2Ñ2Ø#Ÿ{™{¨9¯=©=×9Ô9¸VØ/Ñ;Ù"6°wÀÓ"G×GÐGñ (.÷ ! !Ù ô '×8Ò8¸ÓC�Ø"+×"=Ñ"=¸gÀtÈY×MeÑMeÓ"f×f�	Ü˜i¬×-Ñ-°)×2BÑ2BÑ2Nô ,Ø!Ÿ™×7Ñ7Ø!Ÿ™×8Ñ8Ø#,×#3Ñ#3ñó ð
 #�GØÜ! )¬\×-CÑ-C×DÑDÜ$×2Ò2ØVóð ô œL×2Ñ2´3¼°8Ñ<¸iÓH�÷{ ‘g÷E
÷ 
öB Ü×*Ò*Ð+`ÓaÐað òC
òP Eò  6ò$ Kò! yð .Ñ9Ü+6Ø $Ð&8×&BÑ&BÐDV×DcÑDcó,˜Lð '+˜Gà'0§¡×'FÑ'F×'KÑ'KÓ'M˜H÷+`ó +`ôZ #4Ø (Ø )§¡× @Ñ @Ø &Ø +ó	#ó ð "÷o  6×5×5×5×5×5×5Ö5úòr  :âGò! v÷  :×9×9×9×9Ó9úò g÷_
÷ 
÷ 
ò 
üsk  ˆBRÂM-ÂRÂCQ:Å2M0Å3/Q:Æ"M3Æ#Q:Æ&&P ÇM6ÇP ÇM<ÇM9
ÇM<ÇP Ç5Q:ÈP;ÈQ:ÈQÈ'P>È(QÈ.QÈ2Q
È3QÈ6QÈ96Q:É/Q4É0CQ:Ì?RÍ
Q7Í#RÍ0Q:Í3Q:Í6P Í9M<Í<A=P Ï9Q:ÐPÐQ:ÐPÐQ:Ð P8	Ð&P)Ð'P8	Ð3	Q:Ð>QÑQÑQÑQ:ÑQÑQ:ÑQ1	ÑQ"Ñ Q1	Ñ,	Q:Ñ7RÑ:RÒ RÒRÒR©rî   rû   r  r  r  rÜ   r£   rý   r  r  r*   r  r  r  rù   r²   r  r  c               ó   • g ry   r]   ©rt   r   rî   rû   r  r  r  rÜ   r£   rý   r  r  r*   r  r  r  rù   r²   r  r  s                       rf   Úrun_stream_syncÚAbstractAgent.run_stream_syncq  s	   € ð. ADre   )rû   r  r  r  rÜ   r£   rý   r  r  r*   r  r  r  rù   r²   r  r  c               ó   • g ry   r]   rp  s                       rf   rq  rr  Š  ó	   € ð. DGre   c               ó  • [         R                  " 5         U(       a1  U R                  c$  U R                  [        R
                  " 5       5        [        R                  " U R                  UUUUUUUUU	U
UUUUSUUUUS95      $ )a¤  Run the agent with a user prompt in sync streaming mode.

This is a convenience method that wraps [`run_stream()`][pydantic_ai.agent.AbstractAgent.run_stream],
running all of the agent's async work on the caller's event loop while keeping context-manager and
iterator lifecycles in stable tasks.
You therefore can't use this method inside async code or if there's an active event loop.

Like [`run_sync()`][pydantic_ai.agent.AbstractAgent.run_sync], this method cannot be used inside a
synchronous tool, output function, or other function called during an agent run. See
[Agent delegation](../multi-agent-applications.md#agent-delegation).

The returned [`StreamedRunResultSync`][pydantic_ai.result.StreamedRunResultSync] is a synchronous
context manager and should be used and closed on the thread where it was created. Use a `with` block
so the stream is cleaned up when you're done.

This method builds an internal agent graph (using system prompts, tools and output schemas) and then
runs the graph until the model produces output matching the `output_type`, for example text or structured data.
At this point, a streaming run result object is yielded from which you can stream the output as it comes in,
and -- once this output has completed streaming -- get the complete output, message history, and usage.

As this method will consider the first output matching the `output_type` to be the final output,
it will stop running the agent graph and will not execute any tool calls made by the model after this "final" output.
If you want to always run the agent graph to completion and stream events and output at the same time,
use [`agent.run()`][pydantic_ai.agent.AbstractAgent.run] with an `event_stream_handler` or [`agent.iter()`][pydantic_ai.agent.AbstractAgent.iter] instead.

Example:
```python
from pydantic_ai import Agent

agent = Agent('openai:gpt-5.2')

def main():
    with agent.run_stream_sync('What is the capital of the UK?') as response:
        print(response.get_output())
        #> The capital of the UK is London.
```

Args:
    user_prompt: User input to start/continue the conversation.
    output_type: Custom output type to use for this run, `output_type` may only be used if the agent has no
        output validators since output validators would expect an argument that matches the agent's output type.
    message_history: History of the conversation so far.
    deferred_tool_results: Optional results for deferred tool calls in the message history.
    conversation_id: ID of the conversation this run belongs to. Pass `'new'` to start a fresh conversation, ignoring any `conversation_id` already on `message_history`. If omitted, falls back to the most recent `conversation_id` on `message_history` or a freshly generated UUID7.
    run_id: Optional ID for this agent run. Unlike `conversation_id`, never inherited from `message_history`. Passing an empty string, or a value that already appears on `message_history`, raises `UserError` because both break `new_messages()`; use `conversation_id` to correlate across turns or deferred-tool resume. If omitted, a fresh UUID7 is generated.
    model: Optional model to use for this run, required if `model` was not set when creating the agent.
    deps: Optional dependencies to use for this run.
    model_settings: Optional settings to use for this model's request, or a callable
        that receives [`RunContext`][pydantic_ai.tools.RunContext] and returns settings.
        Callables are called before each model request, allowing dynamic per-step settings.
    usage_limits: Optional limits on model request count or token usage.
    cancellation_token: Token used to cancel this run from another task or thread. Single-use:
        mint a fresh token per run, as a reused (already-cancelled) token prevents the run from starting.
    usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
    metadata: Optional metadata to attach to this run. Accepts a dictionary or a callable taking
        [`RunContext`][pydantic_ai.tools.RunContext]; merged with the agent's configured metadata.
    retries: Override the agent-level retry budgets for this run. Pass an `int` to override both
        the tool-retry and output budgets, or an [`AgentRetries`][pydantic_ai.AgentRetries] dict to
        override just one (e.g. `retries={'tools': 3}`). See
        [`Agent.__init__`][pydantic_ai.agent.Agent.__init__] for semantics of the two enforcement paths.
    infer_name: Whether to try to infer the agent name from the call frame if it's not set.
    toolsets: Optional additional toolsets for this run.
    event_stream_handler: Optional handler for events from the model's streaming response and the agent's execution of tools to use for this run. Under a durability capability, this per-run handler runs workflow-side; model events are replayed after each model request completes. For handler I/O inside the durable boundary, pass `event_stream_handler=` to the durability capability.
        It will receive all the events up until the final result is found, which you can then read or stream from inside the context manager.
        Note that it does _not_ receive any events after the final result is found.
    capabilities: Optional additional [capabilities](https://pydantic.dev/docs/ai/capabilities/overview/) for this run, merged with the agent's configured capabilities.
    spec: Optional agent spec to apply for this run. At run time, spec values are additive.

Returns:
    The result of the run.
Frn  )	r$   r?  rà   r1  r2  r3  r(   ÚStreamedRunResultSyncrB  rp  s                       rf   rq  rr  £  s‘   € ô| 	×'Ò'Ô)æ˜$Ÿ)™)Ñ+Ø×ÑœW×1Ò1Ó3Ô4ä×+Ò+Ø�O‰OØØ'Ø /Ø&;Ø /ØØØØ-Ø)Ø#5ØØ!ØØ Ø!Ø%9Ø)Øð' ð ó
ð 	
re   )rî   rû   r  r  r  rÜ   r  r£   rý   r  r  r*   r  r  r  rù   r  r  c               ó   • g ry   r]   ©rt   r   rî   rû   r  r  r  rÜ   r  r£   rý   r  r  r*   r  r  r  rù   r  r  s                       rf   Úrun_stream_eventsÚAbstractAgent.run_stream_events  rt  re   )rû   r  r  r  rÜ   r  r£   rý   r  r  r*   r  r  r  rù   r  r  c               ó   • g ry   r]   rx  s                       rf   ry  rz  7  s	   € ð. GJre   c               óâ   ^ ^^^^^^^^^	^
^^^^^^^^• U(       a1  T R                   c$  T R                  [        R                  " 5       5        SUUUUU	UUUUU
UUUU UUUUU4S jjn[	        U5      $ )a´  Run the agent with a user prompt in async mode and stream events from the run.

This is a convenience method that wraps [`self.run`][pydantic_ai.agent.AbstractAgent.run] and
uses the `event_stream_handler` kwarg to get a stream of events from the run.

The background run starts on the first iteration of the event handle, not on entering the
context manager, so entering and exiting without iterating never calls the model.

The handle can cancel the whole run and access its messages, usage, and completed result.

Must be used as an async context manager so the background run task is deterministically
cleaned up when the consumer stops iterating early.

Example:
```python
from pydantic_ai import Agent, AgentRunResultEvent, AgentStreamEvent

agent = Agent('openai:gpt-5.2')

async def main():
    collected: list[AgentStreamEvent | AgentRunResultEvent] = []
    async with agent.run_stream_events('What is the capital of France?') as events:
        async for event in events:
            collected.append(event)
    print(collected)
    '''
    [
        PartStartEvent(index=0, part=TextPart(content='The capital of ')),
        FinalResultEvent(tool_name=None, tool_call_id=None),
        PartDeltaEvent(index=0, delta=TextPartDelta(content_delta='France is Paris. ')),
        PartEndEvent(
            index=0, part=TextPart(content='The capital of France is Paris. ')
        ),
        AgentRunResultEvent(
            result=AgentRunResult(output='The capital of France is Paris. ')
        ),
    ]
    '''
```

Arguments are the same as for [`self.run`][pydantic_ai.agent.AbstractAgent.run],
except that `event_stream_handler` is now allowed.

Args:
    user_prompt: User input to start/continue the conversation.
    output_type: Custom output type to use for this run, `output_type` may only be used if the agent has no
        output validators since output validators would expect an argument that matches the agent's output type.
    message_history: History of the conversation so far.
    deferred_tool_results: Optional results for deferred tool calls in the message history.
    conversation_id: ID of the conversation this run belongs to. Pass `'new'` to start a fresh conversation, ignoring any `conversation_id` already on `message_history`. If omitted, falls back to the most recent `conversation_id` on `message_history` or a freshly generated UUID7.
    run_id: Optional ID for this agent run. Unlike `conversation_id`, never inherited from `message_history`. Passing an empty string, or a value that already appears on `message_history`, raises `UserError` because both break `new_messages()`; use `conversation_id` to correlate across turns or deferred-tool resume. If omitted, a fresh UUID7 is generated.
    model: Optional model to use for this run, required if `model` was not set when creating the agent.
    instructions: Optional additional instructions to use for this run.
    deps: Optional dependencies to use for this run.
    model_settings: Optional settings to use for this model's request, or a callable
        that receives [`RunContext`][pydantic_ai.tools.RunContext] and returns settings.
        Callables are called before each model request, allowing dynamic per-step settings.
    usage_limits: Optional limits on model request count or token usage.
    cancellation_token: Token used to cancel this run from another task or thread. Single-use:
        mint a fresh token per run, as a reused (already-cancelled) token prevents the run from starting.
    usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
    metadata: Optional metadata to attach to this run. Accepts a dictionary or a callable taking
        [`RunContext`][pydantic_ai.tools.RunContext]; merged with the agent's configured metadata.
    retries: Override the agent-level retry budgets for this run. Pass an `int` to override both
        the tool-retry and output budgets, or an [`AgentRetries`][pydantic_ai.AgentRetries] dict to
        override just one (e.g. `retries={'tools': 3}`). See
        [`Agent.__init__`][pydantic_ai.agent.Agent.__init__] for semantics of the two enforcement paths.
    infer_name: Whether to try to infer the agent name from the call frame if it's not set.
    toolsets: Optional additional toolsets for this run.
    capabilities: Optional additional [capabilities](https://pydantic.dev/docs/ai/capabilities/overview/) for this run, merged with the agent's configured capabilities.
    spec: Optional agent spec to apply for this run. At run time, spec values are additive.

Returns:
    An async context manager that yields an [`AgentRunEvents`][pydantic_ai.agent.AgentRunEvents]
    handle over `AgentStreamEvent`s ending with a final `AgentRunResultEvent` carrying the run result.
c              “  ód   >#   • TR                  TTTTTTT	TTT
TTTTTSTU TTS9I S h  v•N $  N7f)NFr  )r!  )r²   r  r  r  r  r£   r  rû   r  rÜ   rý   rî   r  r  rt   r  rù   r*   r  r   s    €€€€€€€€€€€€€€€€€€€rf   ru   Ú2AbstractAgent.run_stream_events.<locals>.run_agent¶  sb   øé € ØŸ™ØØ'Ø /Ø&;Ø /ØØØ)ØØ-Ø)Ø#5ØØ!ØØ Ø!Ø%9Ø)Øð) "ð ÷ ð ñ ùs   ƒ&0©.ª0)r²   zEventStreamHandler[AgentDepsT]r·   úAgentRunResult[Any])rà   r1  r2  r3  rÇ   )rt   r   rî   rû   r  r  r  rÜ   r  r£   rý   r  r  r*   r  r  r  rù   r  r  ru   s   ```````````````` ``` rf   ry  rz  P  sL   ÿÿú€ öF ˜$Ÿ)™)Ñ+Ø×ÑœW×1Ò1Ó3Ô4÷	÷ 	÷ 	ñ 	ô0 ' yÓ1Ð1re   c               ó   • g ry   r]   rx  s                       rf   r4  ÚAbstractAgent.iterÐ  s	   € ð. JMre   c               ó   • g ry   r]   rx  s                       rf   r4  r�  é  s	   € ð. MPre   c              ó   #   • [         e7f)a€  A contextmanager which can be used to iterate over the agent graph's nodes as they are executed.

This method builds an internal agent graph (using system prompts, tools and output schemas) and then returns an
`AgentRun` object. The `AgentRun` can be used to async-iterate over the nodes of the graph as they are
executed. This is the API to use if you want to consume the outputs coming from each LLM model response, or the
stream of events coming from the execution of tools.

The `AgentRun` also provides methods to access the full message history, new messages, and usage statistics,
and the final result of the run once it has completed.

For more details, see the documentation of `AgentRun`.

Example:
```python
from pydantic_ai import Agent

agent = Agent('openai:gpt-5.2')

async def main():
    nodes = []
    async with agent.iter('What is the capital of France?') as agent_run:
        async for node in agent_run:
            nodes.append(node)
    print(nodes)
    '''
    [
        UserPromptNode(
            user_prompt='What is the capital of France?',
            instructions_functions=[],
            system_prompts=(),
            system_prompt_functions=[],
            system_prompt_dynamic_functions={},
        ),
        ModelRequestNode(
            request=ModelRequest(
                parts=[
                    UserPromptPart(
                        content='What is the capital of France?',
                        timestamp=datetime.datetime(...),
                    )
                ],
                timestamp=datetime.datetime(...),
                run_id='...',
                conversation_id='...',
            )
        ),
        CallToolsNode(
            model_response=ModelResponse(
                parts=[TextPart(content='The capital of France is Paris.')],
                usage=RequestUsage(
                    cost=Decimal('0.000196'), input_tokens=56, output_tokens=7
                ),
                model_name='gpt-5.2',
                timestamp=datetime.datetime(...),
                run_id='...',
                conversation_id='...',
            )
        ),
        End(data=FinalResult(output='The capital of France is Paris.')),
    ]
    '''
    print(agent_run.result.output)
    #> The capital of France is Paris.
```

Args:
    user_prompt: User input to start/continue the conversation.
    output_type: Custom output type to use for this run, `output_type` may only be used if the agent has no
        output validators since output validators would expect an argument that matches the agent's output type.
    message_history: History of the conversation so far.
    deferred_tool_results: Optional results for deferred tool calls in the message history.
    conversation_id: ID of the conversation this run belongs to. Pass `'new'` to start a fresh conversation, ignoring any `conversation_id` already on `message_history`. If omitted, falls back to the most recent `conversation_id` on `message_history` or a freshly generated UUID7.
    run_id: Optional ID for this agent run. Unlike `conversation_id`, never inherited from `message_history`. Passing an empty string, or a value that already appears on `message_history`, raises `UserError` because both break `new_messages()`; use `conversation_id` to correlate across turns or deferred-tool resume. If omitted, a fresh UUID7 is generated.
    model: Optional model to use for this run, required if `model` was not set when creating the agent.
    instructions: Optional additional instructions to use for this run.
    deps: Optional dependencies to use for this run.
    model_settings: Optional settings to use for this model's request, or a callable
        that receives [`RunContext`][pydantic_ai.tools.RunContext] and returns settings.
        Callables are called before each model request, allowing dynamic per-step settings.
    usage_limits: Optional limits on model request count or token usage.
    cancellation_token: Token used to cancel this run from another task or thread. Single-use:
        mint a fresh token per run, as a reused (already-cancelled) token prevents the run from starting.
    usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
    metadata: Optional metadata to attach to this run. Accepts a dictionary or a callable taking
        [`RunContext`][pydantic_ai.tools.RunContext]; merged with the agent's configured metadata.
    retries: Override the agent-level retry budgets for this run. Pass an `int` to override both
        the tool-retry and output budgets, or an [`AgentRetries`][pydantic_ai.AgentRetries] dict to
        override just one (e.g. `retries={'tools': 3}`). See
        [`Agent.__init__`][pydantic_ai.agent.Agent.__init__] for semantics of the two enforcement paths.
    infer_name: Whether to try to infer the agent name from the call frame if it's not set.
    toolsets: Optional additional toolsets for this run.
    capabilities: Optional additional [capabilities](https://pydantic.dev/docs/ai/capabilities/overview/) for this run, merged with the agent's configured capabilities.
    spec: Optional agent spec to apply for this run. At run time, spec values are additive.

Returns:
    The result of the run.
rÚ   rx  s                       rf   r4  r�    s   é € ôt "Ð!ùó   ‚	)rà   r£   rÜ   rù   r[   Únative_toolsr  r  rý   r  r  c             #  ó   #   • [         e7f)a  Context manager to temporarily override agent configuration.

This is particularly useful when testing.
You can find an example of this [here](../testing.md#overriding-model-via-pytest-fixtures).

Args:
    name: The name to use instead of the name passed to the agent constructor and agent run.
    deps: The dependencies to use instead of the dependencies passed to the agent run.
    model: The model to use instead of the model passed to the agent run.
    toolsets: The toolsets to use instead of the toolsets passed to the agent constructor and agent run.
    tools: The tools to use instead of the tools registered with the agent.
    native_tools: The native tools to use instead of the agent's configured native tools.
    instructions: The instructions to use instead of the instructions registered with the agent.
    metadata: The metadata to use instead of the metadata passed to the agent constructor. When set, any
        per-run `metadata` argument is ignored.
    model_settings: The model settings to use instead of the model settings passed to the agent constructor.
        When set, any per-run `model_settings` argument is ignored.
    retries: The retry budgets to use instead of the agent-level configuration. Pass an `int` to
        override both the tool-retry and output budgets, or an [`AgentRetries`][pydantic_ai.AgentRetries]
        dict to override just one (e.g. `retries={'tools': 3}`).
        When set, any per-run `retries` argument is ignored.
    spec: Optional agent spec providing defaults for override.
rÚ   )rt   rà   r£   rÜ   rù   r[   r…  r  r  rý   r  r  s               rf   ÚoverrideÚAbstractAgent.override  s   é € ôP "Ð!ùr„  ©r£   rý   r  rù   r  r*   r  r  r  r  rû   c               óŽ   • U R                   c$  U R                  [        R                  " 5       5        [	        U UUUUUUUUU	U
UUS9$ )uÛ  Bind this agent's configuration to a realtime `model`, returning an accessor for realtime operations.

The returned [`AgentRealtime`][pydantic_ai.agent.AgentRealtime] carries the agent's realtime
configuration so that opening a session with [`session()`][pydantic_ai.agent.AgentRealtime.session]
reuses the same instructions, tools, capabilities, and run context without re-passing them.

These parameters mirror [`iter`][pydantic_ai.agent.AbstractAgent.iter]. Parameters specific to the
request-response graph â€” `output_type`, `retries`, `event_stream_handler`, `deferred_tool_results` â€”
do not apply; structured output should be delegated to a normal [`Agent`][pydantic_ai.Agent] (see the
realtime docs). Capabilities run `for_run` once when the session connects; their instructions,
toolsets, and native tools are applied. Tool hooks (`prepare_tools` and `before`/`after`/`wrap`/
`on_error` for `tool_validate` and `tool_execute`) run for each tool call. Run hooks
(`before_run`, `after_run`, `wrap_run`, `on_run_error`) run once around the session and
event-stream hooks wrap the session iterator; graph, model-request, and output-stage hooks
do not run.

```python
from pydantic_ai import Agent
from pydantic_ai.realtime import RealtimeTurnCompleteEvent
from pydantic_ai.realtime.openai import OpenAIRealtimeModel

agent = Agent(instructions='You are a helpful voice assistant.')

@agent.tool_plain
def get_weather(city: str) -> str:
    return f'Sunny in {city}'

async def main():
    model = OpenAIRealtimeModel('gpt-realtime')
    async with agent.realtime(model).session() as session:
        await session.send_audio(b'...')
        async for event in session:
            if isinstance(event, RealtimeTurnCompleteEvent):
                break  # keep listening in a real call; we stop after one reply
```

Args:
    model: The realtime model to connect to.
    deps: Dependencies passed to tool functions.
    model_settings: Optional realtime settings overriding the model's defaults for the session.
    instructions: Additional instructions for the session, combined with the agent's instructions.
        Dynamic instruction functions (`@agent.instructions`) are evaluated once at connect time
        (there is no per-request rebuild in a realtime session).
    toolsets: Optional additional toolsets for the session, on top of the agent's.
    capabilities: Optional additional capabilities for the session. Their `for_run`, setup
        contributions, and tool-lifecycle hooks apply; run hooks fire once around the session
        and event-stream hooks wrap the iterator; model-request, graph, and output hooks are not
        invoked.
    usage: Optional [`RunUsage`][pydantic_ai.usage.RunUsage] to accumulate token usage into;
        exposed as `session.usage`. A fresh one is used when omitted.
    usage_limits: Optional [`UsageLimits`][pydantic_ai.usage.UsageLimits]. Request, token, and
        tool-call limits are enforced as usage accrues; a breach raises
        [`UsageLimitExceeded`][pydantic_ai.exceptions.UsageLimitExceeded] from the session's
        event iterator, matching how `run` / `iter` surface a usage limit.
    metadata: Optional metadata set on the [`RunContext`][pydantic_ai.tools.RunContext] available
        to tools and capabilities, and on the realtime session telemetry span.
    conversation_id: Optional conversation id, set on the run context and the telemetry span so a
        realtime session can be correlated with other runs. Session-built messages are stamped
        with it as well, allowing a later standard run to resume the same conversation; seeded
        messages are left unchanged.
    run_id: Optional ID for this realtime session, which is one long-lived run covering every
        exchange. Never inherited from `message_history`; passing an empty or previously used ID
        raises `UserError`. If omitted, a fresh UUID7 is generated and stamped on session-built
        messages, while seeded messages are left unchanged.
    message_history: Prior conversation to seed the session with. Replayable text, transcripts,
        thinking, tool rounds, images, and supported retained user audio are projected to the
        provider's initial conversation items; unrepresentable content raises `UserError`. The
        history is included in [`session.all_messages()`][pydantic_ai.realtime.RealtimeSession.all_messages]
        (but not `new_messages()`). Hand off from a prior session or a standard
        [`Agent.run`][pydantic_ai.agent.AbstractAgent.run] by passing its messages here.
©Ú_agentÚ_modelÚ_depsÚ_model_settingsr#   Ú	_toolsetsÚ_capabilitiesÚ_usageÚ_usage_limitsÚ	_metadataÚ_conversation_idÚ_run_idÚ_message_history)rà   r1  r2  r3  ÚAgentRealtime)rt   rÜ   r£   rý   r  rù   r  r*   r  r  r  r  rû   s                rf   ÚrealtimeÚAbstractAgent.realtimeª  sZ   € ðt �9‰9ÑØ×ÑœW×1Ò1Ó3Ô4ÜØØØØ*Ø&ØØ&ØØ&ØØ,ØØ,ñ
ð 	
re   F)r£   rý   r  rù   r  r*   r  r  r  r  rû   Úrun_lifecyclec              ó   #   • [         e7f)u®  Resolve the agent configuration shared by realtime sessions and WebRTC signaling.

With `run_lifecycle`, the run-lifecycle hooks are dispatched around the resolved configuration
so they wrap the toolset â€” and the session the caller opens inside them â€” exactly as `iter`
does. Only `_open_realtime_session` asks for that: signaling only reads back the instructions
and tools a session would advertise, and is not itself a run.
rÚ   )rt   rÜ   r£   rý   r  rù   r  r*   r  r  r  r  rû   r›  s                 rf   Ú_resolve_realtime_sessionÚ'AbstractAgent._resolve_realtime_session  s   é € ô2 "Ð!ùr„  Útranscript_onlyr  éd   ©r£   rý   r  rù   r  r*   r  r  r  r  rû   Úaudio_retentionÚhandle_barge_inÚretain_images_every_nÚretain_images_maxÚprovider_sessionc              ó   #   • [         e7f)a  Worker behind [`AgentRealtime.session`][pydantic_ai.agent.AgentRealtime.session].

Implementations open the realtime session; not all agent implementations support realtime
sessions. Users go through [`realtime()`][pydantic_ai.agent.AbstractAgent.realtime].
rÚ   )rt   rÜ   r£   rý   r  rù   r  r*   r  r  r  r  rû   r¢  r£  r¤  r¥  r¦  s                     rf   Ú_open_realtime_sessionÚ$AbstractAgent._open_realtime_session2  s   é € ô6 "Ð!ùr„  c                óN  • U R                   b   S5       eUbŽ  UR                  =n(       az  UR                  R                  5        H  u  p4X@L d  M  X0l           g   UR                  UR                  :w  a0  UR                  R                  5        H  u  p4X@L d  M  X0l           g   gggg)zjInfer the agent name from the call frame.

RunUsage should be `self._infer_name(inspect.currentframe())`.
NzName already set)rà   ra  Úf_localsÚitemsÚ	f_globals)rt   Úfunction_frameÚparent_framerà   Úitems        rf   r1  ÚAbstractAgent._infer_nameP  s©   € ð
 �y‰yÑ Ð4Ð"4Ó4Ð ØÑ%Ø-×4Ñ4Ð4ˆ|Õ4Ø".×"7Ñ"7×"=Ñ"=Ö"?‘J�DØ”|Ø$(œ	Ùñ #@ð  ×(Ñ(¨L×,BÑ,BÓBà&2×&<Ñ&<×&BÑ&BÖ&D™
˜Øœ<Ø(,œIÙ"ò 'Eð Cð 5ð &re   c              #  ót   #   • [         R                  " U 5         Sv •  SSS5        g! , (       d  f       g= f7f)a�  Set the parallel execution mode during the context.

Args:
    mode: The execution mode for tool calls:
        - 'parallel': Run tool calls in parallel, yielding events as they complete (default).
        - 'sequential': Run tool calls one at a time in order.
        - 'parallel_ordered_events': Run tool calls in parallel, but events are emitted in order, after all calls complete.
N)r<   Úparallel_execution_moder  s    rf   Ú!parallel_tool_call_execution_modeÚ/AbstractAgent.parallel_tool_call_execution_modec  s#   é € ô ×0Ò0°Õ6Û÷ 7×6Ö6üó   ‚8™'ž	8§
5±8c              #  ót   #   • [         R                  " U 5         Sv •  SSS5        g! , (       d  f       g= f7f)aD  Use a custom executor for running sync functions in threads during the context.

By default, sync tool functions and other sync callbacks are run in threads using
[`anyio.to_thread.run_sync`][anyio.to_thread.run_sync], which creates ephemeral threads.
In long-running servers (e.g. FastAPI), this can lead to thread accumulation under sustained load.

This context manager lets you provide a bounded
[`ThreadPoolExecutor`][concurrent.futures.ThreadPoolExecutor] (or any
[`Executor`][concurrent.futures.Executor]) to control thread lifecycle:

```python {test="skip" lint="skip"}
from concurrent.futures import ThreadPoolExecutor
from contextlib import asynccontextmanager

from pydantic_ai import Agent

@asynccontextmanager
async def lifespan(app):
    executor = ThreadPoolExecutor(max_workers=16)
    with Agent.using_thread_executor(executor):
        yield
    executor.shutdown(wait=True)
```

For per-agent configuration, use the
[`UseThreadExecutor`][pydantic_ai.capabilities.UseThreadExecutor] capability instead.

Args:
    executor: The executor to use for running sync functions.
N)r$   Úusing_thread_executor)Úexecutors    rf   r¸  Ú#AbstractAgent.using_thread_executorq  s$   é € ôB ×)Ò)¨(Õ3Û÷ 4×3Ö3ür¶  c              #  ót   #   • [         R                  " U 5         Sv •  SSS5        g! , (       d  f       g= f7f)a„  Use a custom async sleep function for agent-graph delays during the context.

By default the agent graph uses `asyncio.sleep` when it needs to wait during a run (e.g. between
polls of a suspended/background model response). Durable execution frameworks (Temporal, Prefect,
DBOS, ...) register their own durable sleep here so delays survive workflow replays and don't
waste activity time.
N)r"   Úset_agent_graph_sleep)Ú
sleep_funcs    rf   Úusing_sleepÚAbstractAgent.using_sleep•  s#   é € ô ×/Ò/°
Õ;Û÷ <×;Ö;ür¶  c                ó6   • [        U [        R                  5      $ )z¶Check if the node is a `ModelRequestNode`, narrowing the type if it is.

This method preserves the generic parameters while narrowing the type, unlike a direct call to `isinstance`.
)rÐ   r"   ÚModelRequestNoderG  s    rf   r'  Ú#AbstractAgent.is_model_request_node¢  s   € ô ˜$¤× =Ñ =Ó>Ð>re   c                ó6   • [        U [        R                  5      $ )z³Check if the node is a `CallToolsNode`, narrowing the type if it is.

This method preserves the generic parameters while narrowing the type, unlike a direct call to `isinstance`.
)rÐ   r"   ÚCallToolsNoderG  s    rf   r(  Ú AbstractAgent.is_call_tools_node¬  s   € ô ˜$¤× :Ñ :Ó;Ð;re   c                ó6   • [        U [        R                  5      $ )z´Check if the node is a `UserPromptNode`, narrowing the type if it is.

This method preserves the generic parameters while narrowing the type, unlike a direct call to `isinstance`.
)rÐ   r"   rc  rG  s    rf   Úis_user_prompt_nodeÚ!AbstractAgent.is_user_prompt_node¶  s   € ô ˜$¤× ;Ñ ;Ó<Ð<re   c                ó"   • [        U [        5      $ )z©Check if the node is a `End`, narrowing the type if it is.

This method preserves the generic parameters while narrowing the type, unlike a direct call to `isinstance`.
)rÐ   r    rG  s    rf   Úis_end_nodeÚAbstractAgent.is_end_nodeÀ  s   € ô ˜$¤Ó$Ð$re   c              ƒ  ó   #   • [         e7fry   rÚ   rz   s    rf   rÍ   ÚAbstractAgent.__aenter__Ê  ó   é € ä!Ð!ùr„  c              ‡  ó   #   • [         e7fry   rÚ   )rt   Úargss     rf   rÕ   ÚAbstractAgent.__aexit__Î  rÎ  r„  c              ƒ  ó`   #   • SSK Jn  SSKJn  U" SU UU" 5       SUUUUUS9
I Sh  v•N   g N7f)aŠ  Run the agent in a CLI chat interface.

Args:
    deps: The dependencies to pass to the agent.
    prog_name: The name of the program to use for the CLI. Defaults to 'pydantic-ai'.
    message_history: History of the conversation so far.
    model_settings: Optional settings to use for this model's request.
    usage_limits: Optional limits on model request count or token usage.
    model: Optional model to use for the agent run.

Example:
```python {title="agent_to_cli.py" test="skip"}
from pydantic_ai import Agent

agent = Agent('openai:gpt-5.2', instructions='You always respond in Italian.')

async def main():
    await agent.to_cli()
```
r   )ÚConsole)Úrun_chatTÚmonokai)
r)  Úagentr£   ÚconsoleÚ
code_themeÚ	prog_namerû   rÜ   rý   r  N)Úrich.consolerÓ  Úpydantic_ai._clirÔ  )	rt   r£   rÙ  rû   rý   r  rÜ   rÓ  rÔ  s	            rf   Úto_cliÚAbstractAgent.to_cliÒ  s?   é € õ: 	)å-áØØØÙ“IØ ØØ+ØØ)Ø%ñ
÷ 	
ó 	
ùs   ‚$.¦,§.c                óR   • [         R                  " U R                  UUUUUUS95      $ )a´  Run the agent in a CLI chat interface with the non-async interface.

Args:
    deps: The dependencies to pass to the agent.
    prog_name: The name of the program to use for the CLI. Defaults to 'pydantic-ai'.
    message_history: History of the conversation so far.
    model_settings: Optional settings to use for this model's request.
    usage_limits: Optional limits on model request count or token usage.
    model: Optional model to use for the agent run.

```python {title="agent_to_cli_sync.py" test="skip"}
from pydantic_ai import Agent

agent = Agent('openai:gpt-5.2', instructions='You always respond in Italian.')
agent.to_cli_sync()
agent.to_cli_sync(prog_name='assistant')
```
)r£   rÙ  rû   rÜ   rý   r  )r$   r@  rÜ  )rt   r£   rÙ  rû   rý   r  rÜ   s          rf   Úto_cli_syncÚAbstractAgent.to_cli_sync   s:   € ô6 ×(Ò(Ø�K‰KØØ#Ø /ØØ-Ø)ð ð ó	
ð 		
re   )rà   )r·   ú1models.Model | models.KnownModelName | str | None)r·   ú
str | None)rå   râ  r·   r¸   )rå   z$TemplateStr[AgentDepsT] | str | Noner·   r¸   )r·   Útype)r·   zOutputSpec[OutputDataT])r·   ú%EventStreamHandler[AgentDepsT] | None)r·   zCombinedCapability[AgentDepsT])r·   z-Any | Callable[[RunContext[AgentDepsT]], Any])r·   z%Sequence[AbstractToolset[AgentDepsT]])r£   r=   rÜ   rá  rû   ú'Sequence[_messages.ModelMessage] | Nonerü   ú,str | Sequence[_messages.UserContent] | Noner*   ú_usage.RunUsage | Nonerý   úModelSettings | Noner·   z list[_messages.SystemPromptPart]ry   )rî   z/OutputSpec[OutputDataT | RunOutputDataT] | Noner·   r.   )*r   ræ  rî   r¸   rû   rå  r  úDeferredToolResults | Noner  râ  r  râ  rÜ   rá  r  ú+_instructions.AgentInstructions[AgentDepsT]r£   r=   rý   ú%AgentModelSettings[AgentDepsT] | Noner  ú_usage.UsageLimits | Noner  úCancellationToken | Noner*   rç  r  ú AgentMetadata[AgentDepsT] | Noner  úint | AgentRetries | Noner  Úboolrù   ú,Sequence[AbstractToolset[AgentDepsT]] | Noner²   rä  r  ú,Sequence[AgentCapability[AgentDepsT]] | Noner  ú!dict[str, Any] | AgentSpec | Noner·   r¹   )*r   ræ  rî   úOutputSpec[RunOutputDataT]rû   rå  r  ré  r  râ  r  râ  rÜ   rá  r  rê  r£   r=   rý   rë  r  rì  r  rí  r*   rç  r  rî  r  rï  r  rð  rù   rñ  r²   rä  r  rò  r  ró  r·   zAgentRunResult[RunOutputDataT])*r   ræ  rî   ú!OutputSpec[RunOutputDataT] | Nonerû   rå  r  ré  r  râ  r  râ  rÜ   rá  r  rê  r£   r=   rý   rë  r  rì  r  rí  r*   rç  r  rî  r  rï  r  rð  rù   rñ  r²   rä  r  rò  r  ró  r·   r  )*r   ræ  rî   r¸   rû   rå  r  ré  r  râ  r  râ  rÜ   rá  r  rê  r£   r=   rý   rë  r  rì  r  rí  r*   rç  r  rî  r  rï  r  rð  rù   rñ  r²   rä  r  rò  r  ró  r·   zNAbstractAsyncContextManager[result.StreamedRunResult[AgentDepsT, OutputDataT]])*r   ræ  rî   rô  rû   rå  r  ré  r  râ  r  râ  rÜ   rá  r  rê  r£   r=   rý   rë  r  rì  r  rí  r*   rç  r  rî  r  rï  r  rð  rù   rñ  r²   rä  r  rò  r  ró  r·   zQAbstractAsyncContextManager[result.StreamedRunResult[AgentDepsT, RunOutputDataT]])*r   ræ  rî   rõ  rû   rå  r  ré  r  râ  r  râ  rÜ   rá  r  rê  r£   r=   rý   rë  r  rì  r  rí  r*   rç  r  rî  r  rï  r  rð  rù   rñ  r²   rä  r  rò  r  ró  r·   z9AsyncGenerator[result.StreamedRunResult[AgentDepsT, Any]])(r   ræ  rî   r¸   rû   rå  r  ré  r  râ  r  râ  rÜ   rá  r£   r=   rý   rë  r  rì  r  rí  r*   rç  r  rî  r  rï  r  rð  rù   rñ  r²   rä  r  rò  r  ró  r·   z5result.StreamedRunResultSync[AgentDepsT, OutputDataT])(r   ræ  rî   rô  rû   rå  r  ré  r  râ  r  râ  rÜ   rá  r£   r=   rý   rë  r  rì  r  rí  r*   rç  r  rî  r  rï  r  rð  rù   rñ  r²   rä  r  rò  r  ró  r·   z8result.StreamedRunResultSync[AgentDepsT, RunOutputDataT])(r   ræ  rî   rõ  rû   rå  r  ré  r  râ  r  râ  rÜ   rá  r£   r=   rý   rë  r  rì  r  rí  r*   rç  r  rî  r  rï  r  rð  rù   rñ  r²   rä  r  rò  r  ró  r·   z-result.StreamedRunResultSync[AgentDepsT, Any])(r   ræ  rî   r¸   rû   rå  r  ré  r  râ  r  râ  rÜ   rá  r  rê  r£   r=   rý   rë  r  rì  r  rí  r*   rç  r  rî  r  rï  r  rð  rù   rñ  r  rò  r  ró  r·   z8AbstractAsyncContextManager[AgentRunEvents[OutputDataT]])(r   ræ  rî   rô  rû   rå  r  ré  r  râ  r  râ  rÜ   rá  r  rê  r£   r=   rý   rë  r  rì  r  rí  r*   rç  r  rî  r  rï  r  rð  rù   rñ  r  rò  r  ró  r·   z;AbstractAsyncContextManager[AgentRunEvents[RunOutputDataT]])(r   ræ  rî   rõ  rû   rå  r  ré  r  râ  r  râ  rÜ   rá  r  rê  r£   r=   rý   rë  r  rì  r  rí  r*   rç  r  rî  r  rï  r  rð  rù   rñ  r  rò  r  ró  r·   z0AbstractAsyncContextManager[AgentRunEvents[Any]])(r   ræ  rî   r¸   rû   rå  r  ré  r  râ  r  râ  rÜ   rá  r  rê  r£   r=   rý   rë  r  rì  r  rí  r*   rç  r  rî  r  rï  r  rð  rù   rñ  r  rò  r  ró  r·   z>AbstractAsyncContextManager[AgentRun[AgentDepsT, OutputDataT]])(r   ræ  rî   rô  rû   rå  r  ré  r  râ  r  râ  rÜ   rá  r  rê  r£   r=   rý   rë  r  rì  r  rí  r*   rç  r  rî  r  rï  r  rð  rù   rñ  r  rò  r  ró  r·   zAAbstractAsyncContextManager[AgentRun[AgentDepsT, RunOutputDataT]])(r   ræ  rî   rõ  rû   rå  r  ré  r  râ  r  râ  rÜ   rá  r  rê  r£   r=   rý   rë  r  rì  r  rí  r*   rç  r  rî  r  rï  r  rð  rù   rñ  r  rò  r  ró  r·   z)AsyncGenerator[AgentRun[AgentDepsT, Any]])rà   zstr | _utils.Unsetr£   zAgentDepsT | _utils.UnsetrÜ   z9models.Model | models.KnownModelName | str | _utils.Unsetrù   z4Sequence[AbstractToolset[AgentDepsT]] | _utils.Unsetr[   zKSequence[Tool[AgentDepsT] | ToolFuncEither[AgentDepsT, ...]] | _utils.Unsetr…  z4Sequence[AgentNativeTool[AgentDepsT]] | _utils.Unsetr  z:_instructions.AgentInstructions[AgentDepsT] | _utils.Unsetr  z(AgentMetadata[AgentDepsT] | _utils.Unsetrý   z-AgentModelSettings[AgentDepsT] | _utils.Unsetr  z!int | AgentRetries | _utils.Unsetr  ró  r·   úGenerator[None])rÜ   ú,RealtimeModel | KnownRealtimeModelName | strr£   r=   rý   úRealtimeModelSettings | Noner  rê  rù   rñ  r  rò  r*   rç  r  rì  r  rî  r  râ  r  râ  rû   rå  r·   zAgentRealtime[AgentDepsT])rÜ   r÷  r£   r=   rý   rø  r  rê  rù   rñ  r  rò  r*   rç  r  rì  r  rî  r  râ  r  râ  rû   rå  r›  rð  r·   z6AsyncGenerator[_RealtimeSessionResolution[AgentDepsT]])$rÜ   r÷  r£   r=   rý   rø  r  rê  rù   rñ  r  rò  r*   rç  r  rì  r  rî  r  râ  r  râ  rû   rå  r¢  rG   r£  rð  r¤  rZ   r¥  ú
int | Noner¦  úRealtimeProviderSession | Noner·   úAsyncGenerator[RealtimeSession])r®  zFrameType | Noner·   r¸   )Úparallel)r  z"tool_manager.ParallelExecutionModer·   rö  )r¹  r   r·   rö  )r½  z _agent_graph.AgentGraphSleepFuncr·   rö  )r9  ú9_agent_graph.AgentNode[T, S] | End[result.FinalResult[S]]r·   z+TypeIs[_agent_graph.ModelRequestNode[T, S]])r9  rý  r·   z(TypeIs[_agent_graph.CallToolsNode[T, S]])r9  rý  r·   z)TypeIs[_agent_graph.UserPromptNode[T, S]])r9  rý  r·   z"TypeIs[End[result.FinalResult[S]]])r·   z&AbstractAgent[AgentDepsT, OutputDataT])rÐ  r   r·   zbool | None)Nzpydantic-aiNNNN)rt   r   r£   r=   rÙ  Ústrrû   rå  rý   rè  r  rì  rÜ   rá  r·   r¸   )0r^   r_   r`   ra   rb   rÅ   r   rÜ   rà   Úsetterrç   rë   rî   r²   ró   rö   rù   rÿ   r  r   r!  r;  rB  r   rq  ry  r4  r   r$   ÚUNSETr‡  r™  r�  r¨  r1  Ústaticmethodr´  r¸  r¾  r'  r(  rÇ  rÊ  rÍ   rÕ   rÜ  rß  rd   r]   re   rf   rØ   rØ   Z  sê  † ñ càØó"ó ó ð"ð Øó"ó ó ð"ð 
‡[�[Øó"ó ó ð"ð Øó"ó ó ð"ð ×ÑØó"ó ó ð"ð Øó"ó ó ð"ð Øó"ó ó ð"ð Øó"ó ó ð"ð ó"ó ð"ôð Øó"ó ó ð"ð  ØCGØCGØ?CØ(,Ø/3ñð ðð Að	ð
 Aðð =ðð &ðð -ðð 
*õöBð, ð EIð*ð !ØCGØ<@Ø&*Ø!ØCGØDHØØ@DØ26Ø7;Ø(,Ø59Ø-1ØØAEØFJØEIØ26ñ-*àAð*ð ð	*ð
 Að*ð  :ð*ð $ð*ð ð*ð Að*ð Bð*ð ð*ð >ð*ð 0ð*ð 5ð*ð &ð*ð  3ð!*ð" +ð#*ð$ ð%*ð& ?ð'*ð( Dð)*ð* Cð+*ð, 0ð-*ð. 
%õ/*ó ð*ð2 ð EIð-ð
 DHØ<@Ø&*Ø!ØCGØDHØØ@DØ26Ø7;Ø(,Ø59Ø-1ØØAEØFJØEIØ26ñ--àAð-ð 0ð	-ð
 Að-ð  :ð-ð $ð-ð ð-ð Að-ð Bð-ð ð-ð >ð-ð 0ð-ð 5ð-ð &ð-ð  3ð!-ð" +ð#-ð$ ð%-ð& ?ð'-ð( Dð)-ð* Cð+-ð, 0ð--ð. 
(õ/-ó ð-ð6 EIðN ð :>ØCGØ<@Ø&*Ø!ØCGØDHØØ@DØ26Ø7;Ø(,Ø59Ø-1ØØAEØFJØEIØ26ñ-N àAðN ð 7ð	N ð
 AðN ð  :ðN ð $ðN ð ðN ð AðN ð BðN ð ðN ð >ðN ð 0ðN ð 5ðN ð &ðN ð  3ð!N ð" +ð#N ð$ ð%N ð& ?ð'N ð( Dð)N ð* Cð+N ð, 0ð-N ð. 
ö/N ð` ð EIð*ð !ØCGØ<@Ø&*Ø!ØCGØDHØØ@DØ26Ø7;Ø(,Ø59Ø-1ØØAEØFJØEIØ26ñ-*àAð*ð ð	*ð
 Að*ð  :ð*ð $ð*ð ð*ð Að*ð Bð*ð ð*ð >ð*ð 0ð*ð 5ð*ð &ð*ð  3ð!*ð" +ð#*ð$ ð%*ð& ?ð'*ð( Dð)*ð* Cð+*ð, 0ð-*ð. 
%õ/*ó ð*ð2 ð EIð-ð
 DHØ<@Ø&*Ø!ØCGØDHØØ@DØ26Ø7;Ø(,Ø59Ø-1ØØAEØFJØEIØ26ñ--àAð-ð 0ð	-ð
 Að-ð  :ð-ð $ð-ð ð-ð Að-ð Bð-ð ð-ð >ð-ð 0ð-ð 5ð-ð &ð-ð  3ð!-ð" +ð#-ð$ ð%-ð& ?ð'-ð( Dð)-ð* Cð+-ð, 0ð--ð. 
(õ/-ó ð-ð6 EIðj
ð :>ØCGØ<@Ø&*Ø!ØCGØDHØØ@DØ26Ø7;Ø(,Ø59Ø-1ØØAEØFJØEIØ26ñ-j
àAðj
ð 7ð	j
ð
 Aðj
ð  :ðj
ð $ðj
ð ðj
ð Aðj
ð Bðj
ð ðj
ð >ðj
ð 0ðj
ð 5ðj
ð &ðj
ð  3ð!j
ð" +ð#j
ð$ ð%j
ð& ?ð'j
ð( Dð)j
ð* Cð+j
ð, 0ð-j
ð. 
ö/j
ðX ð EIð]ð !ØCGØ<@Ø&*Ø!ØCGØDHØØ@DØ26Ø7;Ø(,Ø59Ø-1ØØAEØFJØEIØ26ñ-]àAð]ð ð	]ð
 Að]ð  :ð]ð $ð]ð ð]ð Að]ð Bð]ð ð]ð >ð]ð 0ð]ð 5ð]ð &ð]ð  3ð!]ð" +ð#]ð$ ð%]ð& ?ð']ð( Dð)]ð* Cð+]ð, 0ð-]ð. 
Xõ/]ó ð]ð2 ð EIð`ð
 DHØ<@Ø&*Ø!ØCGØDHØØ@DØ26Ø7;Ø(,Ø59Ø-1ØØAEØFJØEIØ26ñ-`àAð`ð 0ð	`ð
 Að`ð  :ð`ð $ð`ð ð`ð Að`ð Bð`ð ð`ð >ð`ð 0ð`ð 5ð`ð &ð`ð  3ð!`ð" +ð#`ð$ ð%`ð& ?ð'`ð( Dð)`ð* Cð+`ð, 0ð-`ð. 
[õ/`ó ð`ð2 ð EIð}bð :>ØCGØ<@Ø&*Ø!ØCGØDHØØ@DØ26Ø7;Ø(,Ø59Ø-1ØØAEØFJØEIØ26ñ-}bàAð}bð 7ð	}bð
 Að}bð  :ð}bð $ð}bð ð}bð Að}bð Bð}bð ð}bð >ð}bð 0ð}bð 5ð}bð &ð}bð  3ð!}bð" +ð#}bð$ ð%}bð& ?ð'}bð( Dð)}bð* Cð+}bð, 0ð-}bð. 
Cõ/}bó ð}bð~ ð EIðDð !ØCGØ<@Ø&*Ø!ØCGØØ@DØ26Ø7;Ø(,Ø59Ø-1ØØAEØFJØEIØ26ñ+DàAðDð ð	Dð
 AðDð  :ðDð $ðDð ðDð AðDð ðDð >ðDð 0ðDð 5ðDð &ðDð 3ðDð  +ð!Dð" ð#Dð$ ?ð%Dð& Dð'Dð( Cð)Dð* 0ð+Dð, 
?õ-Dó ðDð0 ð EIðGð
 DHØ<@Ø&*Ø!ØCGØØ@DØ26Ø7;Ø(,Ø59Ø-1ØØAEØFJØEIØ26ñ+GàAðGð 0ð	Gð
 AðGð  :ðGð $ðGð ðGð AðGð ðGð >ðGð 0ðGð 5ðGð &ðGð 3ðGð  +ð!Gð" ð#Gð$ ?ð%Gð& Dð'Gð( Cð)Gð* 0ð+Gð, 
Bõ-Gó ðGð4 EIðy
ð :>ØCGØ<@Ø&*Ø!ØCGØØ@DØ26Ø7;Ø(,Ø59Ø-1ØØAEØFJØEIØ26ñ+y
àAðy
ð 7ð	y
ð
 Aðy
ð  :ðy
ð $ðy
ð ðy
ð Aðy
ð ðy
ð >ðy
ð 0ðy
ð 5ðy
ð &ðy
ð 3ðy
ð  +ð!y
ð" ð#y
ð$ ?ð%y
ð& Dð'y
ð( Cð)y
ð* 0ð+y
ð, 
7ö-y
ðv ð EIðGð !ØCGØ<@Ø&*Ø!ØCGØDHØØ@DØ26Ø7;Ø(,Ø59Ø-1ØØAEØEIØ26ñ+GàAðGð ð	Gð
 AðGð  :ðGð $ðGð ðGð AðGð BðGð ðGð >ðGð 0ðGð 5ðGð &ðGð  3ð!Gð" +ð#Gð$ ð%Gð& ?ð'Gð( Cð)Gð* 0ð+Gð, 
Bõ-Gó ðGð0 ð EIðJð
 DHØ<@Ø&*Ø!ØCGØDHØØ@DØ26Ø7;Ø(,Ø59Ø-1ØØAEØEIØ26ñ+JàAðJð 0ð	Jð
 AðJð  :ðJð $ðJð ðJð AðJð BðJð ðJð >ðJð 0ðJð 5ðJð &ðJð  3ð!Jð" +ð#Jð$ ð%Jð& ?ð'Jð( Cð)Jð* 0ð+Jð, 
Eõ-Jó ðJð4 EIð~2ð :>ØCGØ<@Ø&*Ø!ØCGØDHØØ@DØ26Ø7;Ø(,Ø59Ø-1ØØAEØEIØ26ñ+~2àAð~2ð 7ð	~2ð
 Að~2ð  :ð~2ð $ð~2ð ð~2ð Að~2ð Bð~2ð ð~2ð >ð~2ð 0ð~2ð 5ð~2ð &ð~2ð  3ð!~2ð" +ð#~2ð$ ð%~2ð& ?ð'~2ð( Cð)~2ð* 0ð+~2ð, 
:ö-~2ð@ ð EIðMð !ØCGØ<@Ø&*Ø!ØCGØDHØØ@DØ26Ø7;Ø(,Ø59Ø-1ØØAEØEIØ26ñ+MàAðMð ð	Mð
 AðMð  :ðMð $ðMð ðMð AðMð BðMð ðMð >ðMð 0ðMð 5ðMð &ðMð  3ð!Mð" +ð#Mð$ ð%Mð& ?ð'Mð( Cð)Mð* 0ð+Mð, 
Hõ-Mó ðMð0 ð EIðPð
 DHØ<@Ø&*Ø!ØCGØDHØØ@DØ26Ø7;Ø(,Ø59Ø-1ØØAEØEIØ26ñ+PàAðPð 0ð	Pð
 AðPð  :ðPð $ðPð ðPð AðPð BðPð ðPð >ðPð 0ðPð 5ðPð &ðPð  3ð!Pð" +ð#Pð$ ð%Pð& ?ð'Pð( Cð)Pð* 0ð+Pð, 
Kõ-Pó ðPð0 Øð EIðyð :>ØCGØ<@Ø&*Ø!ØCGØDHØØ@DØ26Ø7;Ø(,Ø59Ø-1ØØAEØEIØ26ñ+yàAðyð 7ð	yð
 Aðyð  :ðyð $ðyð ðyð Aðyð Bðyð ðyð >ðyð 0ðyð 5ðyð &ðyð  3ð!yð" +ð#yð$ ð%yð& ?ð'yð( Cð)yð* 0ð+yð, 
3õ-yó ó ðyðv Øð $*§<¡<Ø*0¯,©,ØKQÏ<É<ØIOÏÉØ]c×]iÑ]iØMSÏ\É\ØSY×S_ÑS_Ø=C¿\¹\ØHNÏÉØ5;·\±\Ø26ñ'ð !ð'ð (ð	'ð
 Ið'ð Gð'ð [ð'ð Kð'ð Qð'ð ;ð'ð Fð'ð 3ð'ð 0ð'ð 
ô'ó ó ð'ðZ  Ø7;ØDHØAEØEIØ(,Ø26Ø59Ø&*Ø!ØCGñj
à;ðj
ð ð	j
ð
 5ðj
ð Bðj
ð ?ðj
ð Cðj
ð &ðj
ð 0ðj
ð 3ðj
ð $ðj
ð ðj
ð Aðj
ð 
#õj
ðX ð
  Ø7;ØDHØAEØEIØ(,Ø26Ø59Ø&*Ø!ØCGØ#ñà;ðð ð	ð
 5ðð Bðð ?ðð Cðð &ðð 0ðð 3ðð $ðð ðð Aðð ðð  
@ô!ó ðð6 ð
  Ø7;ØDHØAEØEIØ(,Ø26Ø59Ø&*Ø!ØCGØ*;Ø %Ø%&Ø(+Ø;?ñ'à;ðð ð	ð
 5ðð Bðð ?ðð Cðð &ðð 0ðð 3ðð $ðð ðð Aðð (ðð  ð!ð"  #ð#ð$ &ð%ð& 9ð'ð( 
)ô)ó ðô:#ð& Øõ
ó ó ð
ð Øó ó ó ð ðD Øó	ó ó ð	ð ð?ØGð?à	4ó?ó ð?ð ð<ØGð<à	1ó<ó ð<ð ð=ØGð=à	2ó=ó ð=ð ð%ØGð%à	+ó%ó ð%ð ó"ó ð"ð ó"ó ð"ð
  Ø&ØCGØ/3Ø26ØCGð,
Øð,
àð,
ð ð,
ð Að	,
ð
 -ð,
ð 0ð,
ð Að,
ð 
õ,
ð`  Ø&ØCGØ/3Ø26ØCGð$
Øð$
àð$
ð ð$
ð Að	$
ð
 -ð$
ð 0ð$
ð Að$
ð 
÷$
ð $
re   rØ   c                  ó6   • \ rS rSr% SrSrS\S'   SrS\S'   Srg)	Ú_RealtimeSessionLifecyclei'  u`  Hand-off between the run-lifecycle hooks entered during resolution and the session they wrap.

The hooks are entered before the session exists â€” and a `wrap_run` that short-circuits means it
never will â€” so the session, and the result returned in its place, are handed back through this
mutable holder once `_open_realtime_session` has built them.
NzRealtimeSession | NoneÚsessionzAgentRunResult[Any] | NoneÚshort_resultr]   )	r^   r_   r`   ra   rb   r  rc   r  rd   r]   re   rf   r  r  '  s   ‡ ñð '+€GÐ#Ó*Ø/3€LÐ,Ö3re   r  c                  ó¶   • \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S\S'   S\S'    S\S'   S\S'   S\S'   S\S'   S\S'   SrS\S'   SrS\S'    SrS\S'   S r	g)!Ú_RealtimeSessionResolutioni4  zYThe resolved inputs shared by `AgentRealtime.session()` and its WebRTC signaling methods.rJ   rÜ   zRunContext[AgentDepsT]Úrun_contextzToolManager[AgentDepsT]r)   zmodels.ModelRequestParametersÚmodel_request_parametersrø  rý   râ  r  rÃ   Úrequest_messagesrK   Úmodel_profilezInstrumentationSettings | NoneÚinstrumentation_settingsrþ  r  r  NzgCallable[[AsyncIterable[_messages.AgentStreamEvent]], AsyncIterable[_messages.AgentStreamEvent]] | NoneÚwrap_event_streamz _RealtimeSessionLifecycle | NoneÚ	lifecycleFrð  Úshort_circuitedr]   )
r^   r_   r`   ra   rb   rc   r  r  r  rd   r]   re   rf   r  r  4  s|   ‡ ácàÓØ'Ó'Ø)Ó)Ø;Ó;Ø0Ó0ØÓð2ð 3Ó2Ø'Ó'Ø<Ó<ØÓØƒKð 	ð Øoóð 37€IÐ/Ó6ØcØ!€O�TÓ!Úfre   r  c                  óÊ   • \ rS rSrSrSSSSSSSSSSSS.                           SS jjrSS jrSS.SS jjr\S	S
SSSS.           SS jj5       r	Sr
g)r˜  iO  a  An agent bound to a realtime model, returned by [`AbstractAgent.realtime`][pydantic_ai.agent.AbstractAgent.realtime].

Carries the agent's realtime configuration (mirroring the parameters of
[`iter`][pydantic_ai.agent.AbstractAgent.iter]) so that opening a session reuses the same
instructions, tools, capabilities, and run context without re-passing them. Construct it via
[`agent.realtime(model, ...)`][pydantic_ai.agent.AbstractAgent.realtime],
then open a session with [`session()`][pydantic_ai.agent.AgentRealtime.session].
N)rŽ  r�  r#   r�  r‘  r’  r“  r”  r•  r–  r—  c               ó    • Xl         X l        X0l        X@l        XPl        X`l        Xpl        X€l        X�l        X l	        X°l
        XÀl        XÐl        g ry   r‹  )rt   rŒ  r�  rŽ  r�  r#   r�  r‘  r’  r“  r”  r•  r–  r—  s                 rf   rv   ÚAgentRealtime.__init__Y  sK   € ð" ŒØŒØŒ
Ø.ÔØ*ÔØ"ŒØ*ÔØŒØ*ÔØ"ŒØ 0ÔØŒØ 0Õre   c              ƒ  óN  #   • U R                   R                  U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  S9 ISh  v•N nUR                  R                  UUR                   UR"                  R$                  UR&                  S9I Sh  v•N sSSS5      ISh  v•N   $  Na N N	! , ISh  v•N  (       d  f       g= f7f)aT  Resolve this agent's realtime configuration and relay a browser WebRTC SDP offer.

The resolved instructions and tool definitions are baked into the call, so the provider session
is fully configured before (or without) a server sideband attaching. If a sideband later attaches
with [`session(provider_session=...)`][pydantic_ai.agent.AgentRealtime.session], it resolves and
pushes the same configuration over the control channel again.

Resolution uses the same machinery as opening a session: dynamic `@agent.instructions` functions
and capability `for_run` hooks run, and toolsets are set up (including starting MCP servers) to list
their tools, then torn down. Bound `message_history` is not baked into the offer; a sideband session
seeds it when it attaches.

This delegates to
[`answer_webrtc_offer`][pydantic_ai.realtime.RealtimeModel.answer_webrtc_offer], which is implemented
by the OpenAI and Azure OpenAI realtime models. Other models raise
[`UserError`][pydantic_ai.exceptions.UserError]; branch on
[`supports_webrtc`][pydantic_ai.realtime.RealtimeModelProfile.supports_webrtc] to check up front.
r‰  N)r  r[   rý   )rŒ  r�  r�  rŽ  r�  r#   r�  r‘  r’  r“  r”  r•  r–  r—  rÜ   Úanswer_webrtc_offerr  r	  Úfunction_toolsrý   )rt   Ú	sdp_offerÚresolveds      rf   r  Ú!AgentRealtime.answer_webrtc_offerx  sð   é € ð& —;‘;×8Ñ8Ø�K‰KØ—‘Ø×/Ñ/Ø×+Ñ+Ø—^‘^Ø×+Ñ+Ø—+‘+Ø×+Ñ+Ø—^‘^Ø ×1Ñ1Ø—<‘<Ø ×1Ñ1ð 9÷ 
ñ 
ð Ø!Ÿ™×;Ñ;ØØ%×2Ñ2Ø×7Ñ7×FÑFØ'×6Ñ6ð	 <ð ÷ ÷
÷ 
ó 
ñ÷
÷ 
÷ 
ð 
üó[   ‚B!D%Â#DÂ$D%Â'ADÃ/DÃ0DÃ3D%Ã?D	Ä D%ÄDÄ	D%ÄD"ÄDÄD"ÄD%)Úexpires_after_secondsc             ƒ  óN  #   • U R                   R                  U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  S9 ISh  v•N nUR                  R                  UR                   UR"                  R$                  UR&                  US9I Sh  v•N sSSS5      ISh  v•N   $  Na N N	! , ISh  v•N  (       d  f       g= f7f)aâ  Resolve this agent's realtime configuration and mint a browser client secret.

The resolved instructions and tool definitions are baked into the secret, so the provider session
is fully configured before (or without) a server sideband attaching. If a sideband later attaches
with [`session(provider_session=...)`][pydantic_ai.agent.AgentRealtime.session], it resolves and
pushes the same configuration over the control channel again.

Resolution uses the same machinery as opening a session: dynamic `@agent.instructions` functions
and capability `for_run` hooks run, and toolsets are set up (including starting MCP servers) to list
their tools, then torn down. Bound `message_history` is not baked into the secret; a sideband session
seeds it when it attaches.

This delegates to [`create_client_secret`][pydantic_ai.realtime.RealtimeModel.create_client_secret],
which is implemented by the OpenAI and Azure OpenAI realtime models. Other models raise
[`UserError`][pydantic_ai.exceptions.UserError]; branch on
[`supports_webrtc`][pydantic_ai.realtime.RealtimeModelProfile.supports_webrtc] to check up front.

Args:
    expires_after_seconds: Requested lifetime of the client secret in seconds. The provider may
        constrain the accepted value.
r‰  N)r  r[   rý   r  )rŒ  r�  r�  rŽ  r�  r#   r�  r‘  r’  r“  r”  r•  r–  r—  rÜ   Úcreate_client_secretr  r	  r  rý   )rt   r  r  s      rf   r  Ú"AgentRealtime.create_client_secret   sð   é € ð, —;‘;×8Ñ8Ø�K‰KØ—‘Ø×/Ñ/Ø×+Ñ+Ø—^‘^Ø×+Ñ+Ø—+‘+Ø×+Ñ+Ø—^‘^Ø ×1Ñ1Ø—<‘<Ø ×1Ñ1ð 9÷ 
ñ 
ð Ø!Ÿ™×<Ñ<Ø%×2Ñ2Ø×7Ñ7×FÑFØ'×6Ñ6Ø&;ð	 =ð ÷ ÷
÷ 
ó 
ñ÷
÷ 
÷ 
ð 
ür  rŸ  Fr  r   )r¢  r£  r¤  r¥  r¦  c              óÆ  #   • U R                   R                  U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  UUUUUS9 ISh  v•N nU7v •  SSS5      ISh  v•N   g N N! , ISh  v•N  (       d  f       g= f7f)u
  Open a realtime speech-to-speech session backed by the agent's tools.

The session connects to the bound realtime model and automatically executes tool calls using the
agent's registered tools, sending the results back to the model. See
[`Agent.realtime`][pydantic_ai.agent.Agent.realtime] for how `run`/`iter` features map to a
duplex session.

Args:
    audio_retention: How much spoken audio the session retains in its history, on top of
        transcripts. Defaults to `'transcript_only'` (drop audio bytes); see
        [`AudioRetention`][pydantic_ai.realtime.AudioRetention].
    handle_barge_in: Let the session handle the local half of barge-in itself. When the user
        starts speaking over the model, the session discards the buffered audio the user
        will never hear, truncates the provider's transcript to what was actually played,
        and cancels the response â€” normalizing what each provider signals and supports, and
        doing nothing when the previous reply was heard in full. Requires playback to drain
        the session's single [`stream_audio()`][pydantic_ai.realtime.RealtimeSession.stream_audio]
        iterator chunk by chunk at device pace (the setup behind
        [`played_audio_bytes`][pydantic_ai.realtime.RealtimeSession.played_audio_bytes]);
        any other playback topology should leave this off and call
        [`interrupt()`][pydantic_ai.realtime.RealtimeSession.interrupt] itself. Defaults to
        `False`.
    retain_images_every_n: Keep one of every `N` images sent during the session in message
        history. Defaults to `1` (keep every image); increase for high-rate camera/screen streams.
    retain_images_max: Bound on how many images stay in message history; once exceeded, the
        oldest retained image is evicted. Defaults to `100` so a long-running frame stream
        can't grow memory without limit; `0` retains no images, `None` removes the bound.
    provider_session: A [`RealtimeProviderSession`][pydantic_ai.realtime.RealtimeProviderSession] to attach a **sideband**
        control session to, from
        [`answer_webrtc_offer`][pydantic_ai.realtime.RealtimeModel.answer_webrtc_offer]. When set,
        the browser exchanges audio with the provider directly over WebRTC and this session runs
        only the control plane (instructions, tools, transcripts, history) â€” the audio methods
        (`send_audio`/`commit_audio`/`clear_audio`) are unavailable and `audio_retention` must be
        left at `'transcript_only'`. See the realtime docs for the full browser/WebRTC flow.
r¡  N)rŒ  r¨  r�  rŽ  r�  r#   r�  r‘  r’  r“  r”  r•  r–  r—  )rt   r¢  r£  r¤  r¥  r¦  r  s          rf   r  ÚAgentRealtime.sessionË  s»   é € ðZ —;‘;×5Ñ5Ø�K‰KØ—‘Ø×/Ñ/Ø×+Ñ+Ø—^‘^Ø×+Ñ+Ø—+‘+Ø×+Ñ+Ø—^‘^Ø ×1Ñ1Ø—<‘<Ø ×1Ñ1Ø+Ø+Ø"7Ø/Ø-ð# 6÷ 
ñ 
ð$ Ø‹M÷'
÷ 
÷ 
÷ 
÷ 
ó 
üsH   ‚B&C!Â(CÂ)C!Â,CÂ2C!Â=CÂ>C!ÃC!ÃCÃCÃCÃC!)rŒ  r‘  r•  rŽ  r#   r—  r”  r�  r�  r–  r�  r’  r“  )rŒ  zAbstractAgent[AgentDepsT, Any]r�  r÷  rŽ  r=   r�  rø  r#   rê  r�  rñ  r‘  rò  r’  rç  r“  rì  r”  rî  r•  râ  r–  râ  r—  rå  r·   r¸   )r  rþ  r·   rO   )r  rù  r·   rI   )r¢  rG   r£  rð  r¤  rZ   r¥  rù  r¦  rú  r·   rû  )r^   r_   r`   ra   rb   rv   r  r  r   r  rd   r]   re   rf   r˜  r˜  O  s3  † ñð !Ø8<ØEIØBFØFJØ)-Ø37Ø6:Ø'+Ø"ØDHñ1ð /ð1ð =ð	1ð
 ð1ð 6ð1ð Cð1ð @ð1ð Dð1ð 'ð1ð 1ð1ð 4ð1ð %ð1ð ð1ð Bð1ð  
õ!1ô>&ðP QU÷ )ðV ð +<Ø %Ø%&Ø(+Ø;?ñ?ð (ð?ð ð	?ð
  #ð?ð &ð?ð 9ð?ð 
)ô?ó ó?re   r˜  )„Ú
__future__r   Ú_annotationsr½   r2  Úabcr   r   Úcollections.abcr   r   r   r	   r
   r   r   Úconcurrent.futuresr   Ú
contextlibr   r   r   Údataclassesr   Útypesr   r   Útypingr   r   r   r   r   r   rƒ   Úanyio.streams.memoryr   Úpydanticr   Útyping_extensionsr   r   r   r   Úpydantic_graphr    Ú r"   r#   r$   r%   r&   r»   r'   r(   r)   r*   r’  Ú_cancelr+   r,   r-   Ú_json_schemar.   Ú_outputr/   r  r0   r1   r\   r2   r3   r4   r5   r6   r!  r7   r8   r9   Úsettingsr:   Útemplater;   r<   r[   r=   r>   r?   r@   rA   rB   rù   rC   Úpydantic_ai.agent.specrD   Úpydantic_ai.capabilitiesrE   Úpydantic_ai.models.instrumentedrF   Úpydantic_ai.realtimerG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rã  ÚNoneTyperR   rT   rc   rV   Údictrþ  ÚAgentMetadataÚAgentInstructionsÚInstructionsÚAgentModelSettingsrX   rh   r¼   rj   rÇ   rØ   r  r  r˜  r]   re   rf   Ú<module>r=     s–  ðÞ 2ã Û ß #÷÷ ñ õ (ß WÑ WÝ !ß *ß I× Iã Ý :Ý  ß >Ó >å ÷
÷ 
õ 
÷ IÑ HÝ %Ý ,Ý *Ý %ß ,ß @Ñ @ß ?Ñ ?Ý $Ý "Ý &÷÷ õ 'æÝ0Ý;ÝG÷
÷ 
õ 
ñ ˆCƒL€ÙˆCƒL€Ù�‹:€ÙÐ)Ó*€Ø dà (Ø�
ÑÐHÐIÈ9ÐUYÉ?ÐZñ!Ð �Ió ð zà"*Ø�
ÑÐHÐIØ/ð1ñ#Ð �ió ðlð
 �S˜#�X‘ ¨:°jÑ+AÐ*BÀDÈÈcÈÁNÐ*RÑ!SÑS€à!×3Ñ3Ð Ø cà €Ø 2à" X¨z¸*Ñ/EÐ.FÈÐ.UÑ%VÑVÐ ð \ô�9 Eò ð. %-Ð.@ÀÑ.EÐ-FÈ	ÐR`ÐalÑRmÑHnÐ-nÑ$oÐ ˜	Ó oØ hôl6ØˆKÑ˜-¨	×(BÑ(BÐEXÐYdÑEeÑ(eÑfôl6ô^ <˜g kÑ2Ð4OÐP^Ð_jÑPkÑ4lô  <ôFJ
�G˜J¨Ð3Ñ4°cô J
ðZ6 ÷	4ð 	4ó ð	4ð ôg ¨Ñ!4ó gó ðgô4|�G˜JÑ'õ |re   