ó
    ±"³j|  ã                  ó²   • S SK Jr  S SKJr  S SKJrJr  S SKJrJ	r	  S SK
Jr  S SKJrJr  SSKJrJr  \(       a  S S	KJr  \ " S
 S\\	   5      5       rSS jrg)é    )Úannotations)ÚExecutor)ÚKW_ONLYÚ	dataclass)ÚTYPE_CHECKINGÚAny)Ú_utils)Ú
AgentDepsTÚ
RunContexté   )ÚAbstractCapabilityÚWrapRunHandler)ÚAgentRunResultc                  ój   • \ rS rSr% SrS\S'    S\S'   SrS\S	'    \SS
 j5       r      SS jr	Sr
g)ÚUseThreadExecutoré   aÇ  Use a custom executor for running sync functions in threads.

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 capability provides a bounded [`ThreadPoolExecutor`][concurrent.futures.ThreadPoolExecutor]
(or any [`Executor`][concurrent.futures.Executor]) to use instead, scoped to agent runs:

```python
from concurrent.futures import ThreadPoolExecutor

from pydantic_ai import Agent
from pydantic_ai.capabilities import UseThreadExecutor

executor = ThreadPoolExecutor(max_workers=16, thread_name_prefix='agent-worker')
agent = Agent('openai:gpt-5.2', capabilities=[UseThreadExecutor(executor)])
```

To set an executor for all agents globally, use
[`Agent.using_thread_executor()`][pydantic_ai.agent.AbstractAgent.using_thread_executor].
r   Úexecutorr   Ú_Úuse_thread_executorú
str | NoneÚidc                ó   • g ©N© )Úclss    Úe/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pydantic_ai/capabilities/thread_executor.pyÚget_serialization_nameÚ(UseThreadExecutor.get_serialization_name6   s   € àó    c             ƒ  ó¢   #   • [         R                  " U R                  5         U" 5       I S h  v•N sS S S 5        $  N! , (       d  f       g = f7fr   )r	   Úusing_thread_executorr   )ÚselfÚctxÚhandlers      r   Úwrap_runÚUseThreadExecutor.wrap_run:   s3   é € ô ×)Ò)¨$¯-©-Õ8Ù ›—?÷ 9Ñ8Ù"÷ 9Õ8üs%   ‚!A£>®<¯>²
A¼>¾
AÁAr   N)Úreturnr   )r#   zRunContext[AgentDepsT]r$   r   r'   zAgentRunResult[Any])Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__r   Úclassmethodr   r%   Ú__static_attributes__r   r   r   r   r      s[   ‡ ñð. ÓØ9àƒJà*€Bˆ
Ó*ðð óó ðð#à#ð#ð  ð	#ð
 
÷#r   r   c                ó~   • U S:X  a!  SS K nSSKJn  UR                  SUSS9  [        $ [        S[        < SU < 35      e)	NÚThreadExecutorr   )ÚPydanticAIDeprecationWarningz‰`ThreadExecutor` has been renamed to `UseThreadExecutor`. Update your imports; this deprecated alias will be removed in a future release.é   )Ú
stacklevelzmodule z has no attribute )ÚwarningsÚpydantic_ai._warningsr2   Úwarnr   ÚAttributeErrorr(   )Únamer5   r2   s      r   Ú__getattr__r:   E   sO   € ØÐÓÛåFà�‰ð^à(Øð	 	ñ 	
ô !Ð Ü
˜7¤8¡,Ð.@ÀÁÐIÓ
JÐJr   N)r9   Ústrr'   Úobject)Ú
__future__r   Úconcurrent.futuresr   Údataclassesr   r   Útypingr   r   Úpydantic_air	   Úpydantic_ai.toolsr
   r   Úabstractr   r   Úpydantic_ai.runr   r   r:   r   r   r   Ú<module>rE      sH   ðÝ "å 'ß *ß %å ß 4ç 8æÝ.ð ô0#Ð*¨3Ñ/ó 0#ó ð0#õhKr   