
    D_iK                       % S r SSKJr  SSKrSSKrSSKrSSKJrJrJ	r	J
r
JrJr  SSKJrJr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JrJr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*J+r+J,r,  SSK-J.r.  \(       a  SSK/J0r0J1r1  SSK%J2r2J3r3  O\4\-  S-  r1 " S S\$SS9r5 " S S\$SS9r6/ SQr7/ SQr8Sr9\" SSS9r:S\;S'       S/S jr<\S0S j5       r=S1S2S  jjr>      S3S! jr?SSSSSS".             S4S# jjr@S5S$ jrA S1           S6S% jjrB S1           S7S& jjrCS8S' jrD    S9S( jrE\" S)5      rF\" S*5      rG " S+ S,\5      rH\    S:S- j5       rI          S;S. jrJg)<z&Configuration utilities for Runnables.    )annotationsN)	AwaitableCallable	GeneratorIterableIteratorSequence)ExecutorFutureThreadPoolExecutor)contextmanager)Context
ContextVarTokencopy_context)partial)TYPE_CHECKINGAny	ParamSpecTypeVarcast)_set_tracing_contextget_tracing_context)	TypedDict)AsyncCallbackManagerCallbackManager)InputOutputaccepts_configaccepts_run_manager)LangChainTracer)BaseCallbackManager	Callbacks)AsyncCallbackManagerForChainRunCallbackManagerForChainRunc                      \ rS rSrSrSrg)	EmptyDict/   zEmpty dict type. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r)       Y/home/james-whalen/.local/lib/python3.13/site-packages/langchain_core/runnables/config.pyr'   r'   /   s    r0   r'   F)totalc                  x    \ rS rSr% SrS\S'    S\S'    S\S'    S	\S
'    S\S'    S\S'    S\S'    S\S'   Srg)RunnableConfig3   zConfiguration for a `Runnable`.

See the [reference docs](https://reference.langchain.com/python/langchain_core/runnables/#langchain_core.runnables.RunnableConfig)
for more details.
z	list[str]tagszdict[str, Any]metadatar#   	callbacksstrrun_name
int | Nonemax_concurrencyintrecursion_limitconfigurablezuuid.UUID | Nonerun_idr)   N)r*   r+   r,   r-   r.   __annotations__r/   r)   r0   r1   r4   r4   3   sm     O
 
 
 M*  
 
 !  r0   r4   )r6   r7   r8   r:   r<   r>   r?   r@   )r6   r7   r8   r?      child_runnable_config)defaultz!ContextVar[RunnableConfig | None]var_child_runnable_configc                \   [         R                  U 5      nSnU R                  S5      =n(       a{  [        USS5      =n(       ag  [	        S [        US/ 5       5       S5      =n(       aB  UR
                  R                  [        U5      5      =n(       a  [        5       n[        SU05        X4$ )zSet the child Runnable config + tracing context.

Args:
    config: The config to set.

Returns:
    The token to reset the config and the previous tracing context.
Nr8   parent_run_idc              3  T   #    U  H  n[        U[        5      (       d  M  Uv   M      g 7fN)
isinstancer!   ).0handlers     r1   	<genexpr>&_set_config_context.<locals>.<genexpr>   s#      #E!'?; G#Es   (	(handlersparent)	rE   setgetgetattrnextrun_mapr9   r   r   )configconfig_tokencurrent_contextr8   rG   tracerruns          r1   _set_config_contextr[      s     -008LOjj-	-	-$YFFMF #*9j"#E
  F  NN&&s='9::S:-/h_-((r0   c              #  X  #    [        5       nUR                  [        U 5      u  p# Uv   UR                  [        R                  U5        UR                  [
        SSSSSSS.5        g! UR                  [        R                  U5        UR                  [
        SSSSSSS.5        f = f7f)zxSet the child Runnable config + tracing context.

Args:
    config: The config to set.

Yields:
    The config context.
N)rP   project_namer6   r7   enabledclient)r   rZ   r[   rE   resetr   )rV   ctxrW   _s       r1   set_config_contextrc      s      .Cgg16:OL
	)//>  $ 
	
 	)//>  $ 
	
s   #B*A( >B*(?B''B*c                r   [        / 0 S[        0 S9n[        R                  5       =n(       a]  UR	                  [        SUR                  5        VVs0 s H&  u  p4Uc  M
  X3[        ;   a  UR                  5       OU_M(     snn5      5        U bi  UR	                  [        SU R                  5        VVs0 s H2  u  p4Uc  M
  U[        ;   d  M  X3[        ;   a  UR                  5       OU_M4     snn5      5        U b1  U R                  5        H  u  p4U[        ;  d  M  Uc  M  XAS   U'   M     UR                  S0 5      R                  5        H]  u  pVUR                  S5      (       a  M  [        U[        [        [        [        45      (       d  MD  XQS   ;  d  MN  US:w  d  MV  XaS   U'   M_     U$ s  snnf s  snnf )zEnsure that a config is a dict with all keys present.

Args:
    config: The config to ensure.

Returns:
    The ensured config.
N)r6   r7   r8   r>   r?   r4   r?   __r7   api_key)r4   DEFAULT_RECURSION_LIMITrE   rR   updater   itemsCOPIABLE_KEYScopyCONFIG_KEYS
startswithrJ   r9   r=   floatbool)rV   empty
var_configkvkeyvalues          r1   ensure_configrv      s    /E /2244z4  !+ 0 0 2 2 =A#5qvvx1< 2		
   !' . =)*k)9 =A#5qvvx1< .		
 LLNDA#+,n%a( # ii399;
t$$53UD"9::,,y %**c" < L=s   	F- F-1	F3>F3
 F3c           	        US:  a  SU 3n[        U5      e[        U [        5      (       a,  [        U 5      U:w  a  S[        U 5       SU S3n[        U5      e[        U [        5      (       a  [	        [        [        U 5      5      $ US:  a  [        U [        5      (       a  U R                  S5      b  [        R                  " S[        S	S
9  [        SU R                  5        VVs0 s H  u  p4US:w  d  M  X4_M     snn5      n[        U5       Vs/ s H   nU(       a  [        U5      O
[        U 5      PM"     sn$ [        U5       Vs/ s H  n[        U 5      PM     sn$ s  snnf s  snf s  snf )aV  Get a list of configs from a single config or a list of configs.

 It is useful for subclasses overriding batch() or abatch().

Args:
    config: The config or list of configs.
    length: The length of the list.

Returns:
    The list of configs.

Raises:
    ValueError: If the length of the list is not equal to the length of the inputs.

r   zlength must be >= 0, but got z<config must be a list of the same length as inputs, but got z configs for z inputs   r@   z@Provided run_id be used only for the first element of the batch.   )category
stacklevelr4   )
ValueErrorrJ   r	   lenlistmaprv   dictrR   warningswarnRuntimeWarningr   ri   range)rV   lengthmsgrr   rs   
subsequentis          r1   get_config_listr      sT   $ z-fX6o&(##Fv(=6{m=A 	 o&(##Cv.//zj..6::h3G3SN#	

 P!x-tqtP


 6]
" *+M*%f0EE"
 	
 ,1=9=aM&!=99 Q
 :s   &E 6E 'E&E+)r8   r>   r<   r:   r?   c                   [        U 5      n Ub  XS'   SU ;   a  U S	 SU ;   a  U S	 Ub  X S'   Ub  X0S'   Ub  X@S'   Ub  0 U R                  S0 5      EUEU S'   U $ )a?  Patch a config with new values.

Args:
    config: The config to patch.
    callbacks: The callbacks to set.
    recursion_limit: The recursion limit to set.
    max_concurrency: The max concurrency to set.
    run_name: The run name to set.
    configurable: The configurable to set.

Returns:
    The patched config.
r8   r:   r@   r>   r<   r?   )rv   rR   )rV   r8   r>   r<   r:   r?   s         r1   patch_configr   *  s    , 6"F ({z"vx "$3 !"$3 !%z!SFJJ~r$B!Sl!S~Mr0   c            
        0 nS U  5        GHE  nU GH:  nUS:X  a3  0 UR                  S0 5      EUR                  S5      =(       d    0 EUS'   M=  US:X  aD  [        [        UR                  S/ 5      UR                  S5      =(       d    / -   5      5      US'   M  US:X  a3  0 UR                  S0 5      EUR                  S5      =(       d    0 EUS'   M  US:X  Ga  UR                  S5      nUS   n[        U[        5      (       ah  Uc  UR                  5       US'   GM  [        U[        5      (       a
  XE-   US'   GM*  UR                  5       nU H  nUR                  USS9  M     XaS'   GMZ  Ubu  Uc  UR                  5       US'   GMv  [        U[        5      (       a0  UR                  5       nU H  nUR                  USS9  M     XaS'   GM  UR                  U5      US'   GM  GM  US:X  a  US   [        :w  a  US   US'   GM  GM  U[        ;   a  X#   b  X#   R                  5       X'   GM  X#   =(       d    UR                  U5      X'   GM=     GMH     U$ )	zmMerge multiple configs into one.

Args:
    *configs: The configs to merge.

Returns:
    The merged config.
c              3  @   #    U  H  oc  M  [        U5      v   M     g 7frI   )rv   )rK   cs     r1   rM    merge_configs.<locals>.<genexpr>`  s     FW#=##Ws   r7   r6   r?   r8   T)inheritr>   )
rR   sortedrQ   rJ   r~   rk   add_handlermergerg   rj   )configsbaserV   rt   base_callbacksthese_callbacksmngrcallbacks           r1   merge_configsr   T  sd    D GWFCj $hhz2.$zz*-3$Z  %,

60B0HbIJ V &(hh~r2(zz.17R(^$ #!%+!6"("5 ot44%-,;,@,@,B[)#ND99,:,L[)  .224(7H ,,Xt,D )8,0[)$0%-,;,@,@,B[)#ND99.335(6H ,,Xt,D )7,0[) -;,@,@,Q[) 1 ))+,0GG.45F.GD*+ H%&+*A"K,,.	"K8488C=	c  Gf Kr0   c                    [        U 5      (       a"  Ub  [        X#R                  5       S9US'   OX$S'   Ub  [        U 5      (       a  X4S'   U " U40 UD6$ )ad  Call function that may optionally accept a run_manager and/or config.

Args:
    func: The function to call.
    input: The input to the function.
    config: The config to pass to the function.
    run_manager: The run manager to pass to the function.
    **kwargs: The keyword arguments to pass to the function.

Returns:
    The output of the function.
r8   rV   run_managerr   r   	get_childr    funcinputrV   r   kwargss        r1   call_func_with_variable_argsr     s^    , d"+F>S>S>UVF8%8#6t#<#< +}   r0   c                    [        U 5      (       a"  Ub  [        X#R                  5       S9US'   OX$S'   Ub  [        U 5      (       a  X4S'   U " U40 UD6$ )aj  Async call function that may optionally accept a run_manager and/or config.

Args:
    func: The function to call.
    input: The input to the function.
    config: The config to pass to the function.
    run_manager: The run manager to pass to the function.
    **kwargs: The keyword arguments to pass to the function.

Returns:
    The output of the function.
r   rV   r   r   r   s        r1   acall_func_with_variable_argsr     s^    0 d"+F>S>S>UVF8%8#6t#<#< +}   r0   c                    [         R                  " U R                  S5      U R                  S5      U R                  S5      S9$ )zhGet a callback manager for a config.

Args:
    config: The config.

Returns:
    The callback manager.
r8   r6   r7   inheritable_callbacksinheritable_tagsinheritable_metadata)r   	configurerR   rV   s    r1   get_callback_manager_for_configr     s;     $$$jj5F+#ZZ
3 r0   c                    [         R                  " U R                  S5      U R                  S5      U R                  S5      S9$ )zuGet an async callback manager for a config.

Args:
    config: The config.

Returns:
    The async callback manager.
r8   r6   r7   r   )r   r   rR   r   s    r1   %get_async_callback_manager_for_configr     s;      ))$jj5F+#ZZ
3 r0   PTc                  `   ^  \ rS rSrSr        SU 4S jjr        SU 4S jjrSrU =r$ )ContextThreadPoolExecutori  z?ThreadPoolExecutor that copies the context to the child thread.c           
     v   > [         TU ]  [        S[        [	        5       R
                  U/UQ70 UD65      5      $ )zSubmit a function to the executor.

Args:
    func: The function to submit.
    *args: The positional arguments to the function.
    **kwargs: The keyword arguments to the function.

Returns:
    The future for the function.
Callable[..., T])supersubmitr   r   r   rZ   )selfr   argsr   	__class__s       r1   r    ContextThreadPoolExecutor.submit  s;      w~#W\^-?-?%W%WPV%WX
 	
r0   c                   >^^ [        [        US   5      5       Vs/ s H  n[        5       PM     snmSUU4S jjn[        TU ]  " U/UQ70 UD6$ s  snf )zMap a function to multiple iterables.

Args:
    fn: The function to map.
    *iterables: The iterables to map over.
    timeout: The timeout for the map.
    chunksize: The chunksize for the map.

Returns:
    The iterator for the mapped function.
r   c                 F   > TR                  5       R                  " T/U Q76 $ rI   )poprZ   )r   contextsfns    r1   _wrapped_fn2ContextThreadPoolExecutor.map.<locals>._wrapped_fn(  s    <<>%%b0400r0   )r   r   returnr   )r   r}   r   r   r   )r   r   	iterablesr   rb   r   r   r   s    `    @r1   r   ContextThreadPoolExecutor.map  sc    " -2#il2C,DE,DqLN,DE	1 	1 w{

 
 	
 Fs   Ar)   )r   Callable[P, T]r   P.argsr   P.kwargsr   z	Future[T])r   r   r   zIterable[Any]r   r   r   zIterator[T])	r*   r+   r,   r-   r.   r   r   r/   __classcell__)r   s   @r1   r   r     sa    I

 
 	

 

(

 "
 	

 

 
r0   r   c              #     #    U =(       d    0 n [        U R                  S5      S9 nUv   SSS5        g! , (       d  f       g= f7f)zXGet an executor for a config.

Args:
    config: The config.

Yields:
    The executor.
r<   )max_workersN)r   rR   )rV   executors     r1   get_executor_for_configr   2  s<      \rF	"JJ01
	
 
 
s   $A4	A
AAc           
     Z  ^^^#    SUUU4S jjnU b  [        U [        5      (       aS  [        R                  " 5       R	                  S[        S[        [        5       R                  U5      5      5      I Sh  vN $ [        R                  " 5       R	                  X5      I Sh  vN $  N0 N7f)a  Run a function in an executor.

Args:
    executor_or_config: The executor or config to run in.
    func: The function.
    *args: The positional arguments to the function.
    **kwargs: The keyword arguments to the function.

Returns:
    The output of the function.
c                 H   >  T" T0 TD6$ ! [          a  n [        U eS n A ff = frI   )StopIterationRuntimeError)excr   r   r   s    r1   wrapper run_in_executor.<locals>.wrapperW  s2    	(((( 	( C'		(s    
!!Nr   )r   r   )	rJ   r   asyncioget_running_looprun_in_executorr   r   r   rZ   )executor_or_configr   r   r   r   s    ``` r1   r   r   E  s     $( ( !Z0BD%I%I--/??#W\^-?-?%IJ
 
 	

 ))+;;<NXXX

 Ys$   A1B+6B'7+B+"B)#B+)B+)rV   r4   r   z:tuple[Token[RunnableConfig | None], dict[str, Any] | None])rV   r4   r   zGenerator[Context, None, None]rI   )rV   RunnableConfig | Noner   r4   )rV   z0RunnableConfig | Sequence[RunnableConfig] | Noner   r=   r   zlist[RunnableConfig])rV   r   r8   zBaseCallbackManager | Noner>   r;   r<   r;   r:   z
str | Noner?   zdict[str, Any] | Noner   r4   )r   r   r   r4   )r   zCallable[[Input], Output] | Callable[[Input, RunnableConfig], Output] | Callable[[Input, CallbackManagerForChainRun], Output] | Callable[[Input, CallbackManagerForChainRun, RunnableConfig], Output]r   r   rV   r4   r   z!CallbackManagerForChainRun | Noner   r   r   r   )r   zCallable[[Input], Awaitable[Output]] | Callable[[Input, RunnableConfig], Awaitable[Output]] | Callable[[Input, AsyncCallbackManagerForChainRun], Awaitable[Output]] | Callable[[Input, AsyncCallbackManagerForChainRun, RunnableConfig], Awaitable[Output]]r   r   rV   r4   r   z&AsyncCallbackManagerForChainRun | Noner   r   r   zAwaitable[Output])rV   r4   r   r   )rV   r4   r   r   )rV   r   r   zGenerator[Executor, None, None])
r   z Executor | RunnableConfig | Noner   r   r   r   r   r   r   r   )Kr.   
__future__r   r   uuidr   collections.abcr   r   r   r   r   r	   concurrent.futuresr
   r   r   
contextlibr   contextvarsr   r   r   r   	functoolsr   typingr   r   r   r   r   langsmith.run_helpersr   r   typing_extensionsr    langchain_core.callbacks.managerr   r   langchain_core.runnables.utilsr   r   r   r     langchain_core.tracers.langchainr!   langchain_core.callbacks.baser"   r#   r$   r%   r~   r'   r4   rl   rj   rg   rE   rA   r[   rc   rv   r   r   r   r   r   r   r   r   r   r   r   r   r)   r0   r1   <module>r      s   , "    X X C C % @ @   L ' R  =L  s
T!I	 6Ye 6r	   @JT@ <  ) )? )F 
 
82j+:<+:FI+:+:b -1"&"&*.'!' *'  	'
  ' ' (' 'T?R 6:!L!
 ! ! 3! ! !R ;?!! ! ! 8! ! !D $ cNCL1
 2 1
h !$ $"Y8"Y
"Y "Y 	"Y
 "Yr0   