o
    iϓ                     @  s  d dl mZ d dlZd dlZd dlZd dlmZmZ d dl	m
Z
mZmZ d dlmZmZ d dlmZmZmZmZmZmZ d dlmZmZmZ d dlmZmZ d d	lmZm Z m!Z! d d
l"m#Z# ddl$m%Z%m&Z&m'Z( ddl)m*Z*m+Z+ ddl,m-Z-m.Z.m/Z/ ddl0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z< ddl=m>Z>m?Z?m@Z@ ddlAmBZBmCZC er	 e!dZD	 e!deEdZF	 ee+e* eFgeFf ee+e* eFge
eF f B eeFgeFf B eeFge
eF f B ZG	 dZHdZIeJdZK	dWdXd#d$ZLeG d%d& d&ee*eFf ZMedd'G d(d) d)eee3 ZNed*d+G d,d- d-eNe3 ZOed*d+G d.d/ d/eNe3 ZPG d0d1 d1eNe3 ZQed*d+G d2d3 d3eNe3 eZRG d4d5 d5eRe3 ZSed*d+G d6d7 d7eRe3 ZTed*d+G d8d9 d9eNe3 ZUG d:d; d;eee3 ZVedd'G d<d= d=eVe3 ZWed*d+G d>d? d?eWe3 ZXed*d+G d@dA dAeWe3 ZYeG dBdC dCZZeG dDdE dEZ[ed*d+G dFdG dGeWe3 Z\G dHdI dIeVe3 Z]ed*d+G dJdK dKe]e3 Z^ed*d+G dLdM dMeBe* Z_edYdQdRZ`edZdUdRZ`dZdVdRZ`dS )[    )annotationsN)ABCabstractmethod)	AwaitableCallableSequence)	dataclassfield)TYPE_CHECKINGAnyGenericLiteralcastoverload)JsonTypeAdapterValidationError)SchemaValidatorto_json)Self	TypedDictTypeVar)InstrumentationNames   )_function_schema_utilsmessages)
AgentDepsT
RunContext)
ModelRetryToolRetryError	UserError)DeferredToolRequestsNativeOutputOutputDataT
OutputModeOutputObjectDefinition
OutputSpecOutputTypeOrFunctionPromptedOutput
TextOutputTextOutputFunc
ToolOutput_OutputSpecItem)GenerateToolJsonSchemaObjectJsonSchemaToolDefinition)AbstractToolsetToolsetToolTOutputDataT_inv)defaultfinal_resultz/The final response which ends this conversationz[^a-zA-Z0-9-_]Tfunction_schema_function_schema.FunctionSchemarun_contextRunContext[AgentDepsT]argsdict[str, Any]wrap_validation_errorsboolreturnr   c                   s  t |j}|jpt| jdd}|d| d}|jr!|j|d< |jr-t|	 ||j
< tdi |jr@|j
ddi|jddiini di i|jrMdi ini d	|d
< |jj|||d[}z| ||I dH }W n$ ty }	 z|rtj|	j|jd}
|jr|j|
_t|
|	 d}	~	ww |jr| rddlm} ||jt|tr|nt|| |W  d   S 1 sw   Y  dS )ap  Execute an output function within a traced span with error handling.

    This function executes the output function within an OpenTelemetry span for observability,
    automatically records the function response, and handles ModelRetry exceptions by converting
    them to ToolRetryError when wrap_validation_errors is True.

    Args:
        function_schema: The function schema containing the function to execute
        run_context: The current run context containing tracing and tool information
        args: Arguments to pass to the function
        wrap_validation_errors: If True, wrap ModelRetry exceptions in ToolRetryError

    Returns:
        The result of the function execution

    Raises:
        ToolRetryError: When wrap_validation_errors is True and a ModelRetry is caught
        ModelRetry: When wrap_validation_errors is False and a ModelRetry occurs
    __name__output_functionzrunning output function: )gen_ai.tool.namezlogfire.msgzgen_ai.tool.call.idobjecttyperB   )rD   
propertieszlogfire.json_schema)
attributesNcontent	tool_namer   )InstrumentedModel)r   for_versioninstrumentation_versionrI   getattrfunctiontool_call_idtrace_include_contentr   decodetool_arguments_attrjsondumpstool_result_attrtracerstart_as_current_spanget_output_tool_span_namecallr   	_messagesRetryPromptPartmessager    is_recordingmodels.instrumentedrJ   set_attribute
isinstancestrserialize_any)r7   r9   r;   r=   instrumentation_namesrI   rF   spanoutputrmrJ    rh   Y/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/pydantic_ai/_output.pyexecute_traced_output_functionL   sh   


	


$rj   c                   @  sP   e Zd ZU ded< eddZded< eddZded< dd	 Z	
ddddZdS )OutputValidatorz0OutputValidatorFunc[AgentDepsT, OutputDataT_inv]rN   Finitr>   
_takes_ctx	_is_asyncc                 C  s*   t t| jjdk| _t| j| _d S )Nr   )	leninspect	signaturerN   
parametersrn   r   is_async_callablero   selfrh   rh   ri   __post_init__   s   zOutputValidator.__post_init__Tresultr3   r9   r:   r=   r?   c           	   
     s   | j r	||f}n|f}z4| jr'tttgtt f | j}|| I dH }W |S tttgtf | j}tj	|g|R  I dH }W |S  t
ye } z|r_tj|j|jd}|jrZ|j|_t|||d}~ww )a  Validate a result but calling the function.

        Args:
            result: The result data after Pydantic validation the message content.
            run_context: The current run context.
            wrap_validation_errors: If true, wrap the validation errors in a retry message.

        Returns:
            Result of either the validated result data (ok) or a retry message (Err).
        NrG   )rn   ro   r   r   r   r   r3   rN   r   run_in_executorr   rZ   r[   r\   rI   rO   r    )	rv   rx   r9   r=   r;   rN   result_datarf   rg   rh   rh   ri   validate   s0   

zOutputValidator.validateNT)rx   r3   r9   r:   r=   r>   r?   r3   )	r@   
__module____qualname____annotations__r	   rn   ro   rw   r{   rh   rh   rh   ri   rk      s   
 rk   )kw_onlyc                   @  s   e Zd ZU dZded< dZded< dZded< dZd	ed
< dZd	ed< e	d"ddZ
e	d#ddZeddddd$ddZe			d%d&d d!ZdS )'OutputSchemaN'BaseOutputProcessor[OutputDataT] | Nonetext_processorOutputToolset[Any] | NonetoolsetzOutputObjectDefinition | None
object_defFr>   allows_deferred_toolsallows_imager?   r%   c                 C  s   t  NNotImplementedErrorru   rh   rh   ri   mode   s   zOutputSchema.modec                 C  s
   | j d uS r   r   ru   rh   rh   ri   allows_text   s   
zOutputSchema.allows_textnamedescriptionstrictoutput_specOutputSpec[OutputDataT]r   
str | Noner   r   bool | NoneOutputSchema[OutputDataT]c                C  s  t |}t|v }|rdd |D }t|dkrtdtj|v }|r)dd |D }tdd |D d }rft|d	kr?td
t |j}	t|	v rLtdtj|	v rUtdt| j	|	|j
|j|jd||dS tdd |D d }rt|d	kr|tdt |j}	t|	v rtdtj|	v rtdt|j| j	|	|j
|jd||dS g }
g }g }|D ]>}|tu r|
ttt | qt|tr|
| qt|tr|| qt|trtd
t|trtd|| qtj|| |||d}d}t|
dkr.t|
d	kr	td|
d }t|trt|j}nt }|r't||||dS t|||dS t|dkr<t|||dS t|dkrRt| j	||||d|||dS |rZt |dS td)z4Build an OutputSchema dataclass from an output type.c                 S  s   g | ]}|t ur|qS rh   )r"   .0re   rh   rh   ri   
<listcomp>   s    z&OutputSchema.build.<locals>.<listcomp>r   zLAt least one output type must be provided other than `DeferredToolRequests`.c                 S  s   g | ]	}|t jur|qS rh   )rZ   BinaryImager   rh   rh   ri   r      s    c                 s      | ]
}t |tr|V  qd S r   )r`   r#   r   rh   rh   ri   	<genexpr>       z%OutputSchema.build.<locals>.<genexpr>Nr   z,`NativeOutput` must be the only output type.z`NativeOutput` cannot contain `DeferredToolRequests`. Include it alongside the native output marker instead: `output_type=[NativeOutput(...), DeferredToolRequests]`z`NativeOutput` cannot contain `BinaryImage`. Include it alongside the native output marker instead: `output_type=[NativeOutput(...), BinaryImage]`r   	processorr   r   c                 s  r   r   )r`   r)   r   rh   rh   ri   r     r   z.`PromptedOutput` must be the only output type.z`PromptedOutput` cannot contain `DeferredToolRequests`. Include it alongside the prompted output marker instead: `output_type=[PromptedOutput(...), DeferredToolRequests]`z`PromptedOutput` cannot contain `BinaryImage`. Include it alongside the prompted output marker instead: `output_type=[PromptedOutput(...), BinaryImage]`)r   r   )templater   r   r   z*Only one `str` or `TextOutput` is allowed.)r   r   r   r   r   r   r   )r   r   r   )r   r   r   r   )r   z*At least one output type must be provided.)!_flatten_output_specr"   rp   r!   rZ   r   nextoutputsNativeOutputSchema_build_processorr   r   r   PromptedOutputSchemar   ra   appendr   rD   r`   r*   r,   r#   r)   OutputToolsetbuildTextFunctionOutputProcessorrA   TextOutputProcessorToolOutputSchemaTextOutputSchemaAutoOutputSchemaImageOutputSchema)clsr   r   r   r   r   r   r   re   flattened_outputstext_outputstool_outputsother_outputsr   r   text_outputrh   rh   ri   r      s   











zOutputSchema.buildr   +Sequence[OutputTypeOrFunction[OutputDataT]]&BaseObjectOutputProcessor[OutputDataT]c                 C  s8   t | } t| dkrt| d |||dS t| |||dS )Nr   r   )re   r   r   r   )r   r   r   r   )r   rp   ObjectOutputProcessorUnionOutputProcessor)r   r   r   r   rh   rh   ri   r   o  s   zOutputSchema._build_processorr?   r%   )r?   r>   )
r   r   r   r   r   r   r   r   r?   r   NNN)
r   r   r   r   r   r   r   r   r?   r   )r@   r}   r~   r   r   r   r   r   r   propertyr   r   classmethodr   staticmethodr   rh   rh   rh   ri   r      s*   
  
r   Frl   c                      s6   e Zd ZU ded< d fdd	ZedddZ  ZS )r   r   r   r   r   r   r>   r   c                   s"   t  j||j|||d || _d S )N)r   r   r   r   r   super__init__r   r   )rv   r   r   r   r   	__class__rh   ri   r     s   

zAutoOutputSchema.__init__r?   r%   c                 C     dS )Nautorh   ru   rh   rh   ri   r        zAutoOutputSchema.mode)r   r   r   r   r   r>   r   r>   r   )r@   r}   r~   r   r   r   r   __classcell__rh   rh   r   ri   r   }  s
   
 r   c                      s,   e Zd Zd fddZedd
dZ  ZS )r   r    TextOutputProcessor[OutputDataT]r   r>   r   c                  s   t  j|||d d S )Nr   r   r   )rv   r   r   r   r   rh   ri   r     s
   
zTextOutputSchema.__init__r?   r%   c                 C  r   )Ntextrh   ru   rh   rh   ri   r     r   zTextOutputSchema.mode)r   r   r   r>   r   r>   r   r@   r}   r~   r   r   r   r   rh   rh   r   ri   r     s    r   c                      s,   e Zd Zd	 fddZed
ddZ  ZS )r   r   r>   c                  s   t  j|dd d S )NT)r   r   r   )rv   r   r   rh   ri   r     s   zImageOutputSchema.__init__r?   r%   c                 C  r   )Nimagerh   ru   rh   rh   ri   r     r   zImageOutputSchema.mode)r   r>   r   r   rh   rh   r   ri   r     s    r   c                      s(   e Zd ZU ded< d fddZ  ZS )	StructuredTextOutputSchemar   r   r   r>   r   c                  s    t  j||j||d || _d S )N)r   r   r   r   r   )rv   r   r   r   r   rh   ri   r     s   
z#StructuredTextOutputSchema.__init__)r   r   r   r>   r   r>   )r@   r}   r~   r   r   r   rh   rh   r   ri   r     s   
 r   c                   @  s   e Zd ZedddZdS )r   r?   r%   c                 C  r   )Nnativerh   ru   rh   rh   ri   r     r   zNativeOutputSchema.modeNr   )r@   r}   r~   r   r   rh   rh   rh   ri   r     s    r   c                      sT   e Zd ZU ded< ddd fd
dZedddZedddZdddZ	  Z
S )r   r   r   N)r   r   r   r   r>   r   c                  s    t  jt|||d || _d S )Nr   )r   r   PromptedOutputProcessorr   )rv   r   r   r   r   r   rh   ri   r     s   
zPromptedOutputSchema.__init__r?   r%   c                 C  r   )Npromptedrh   ru   rh   rh   ri   r     r   zPromptedOutputSchema.modera   r   r&   c                 C  sR   |j  }|jr|j|d< |jr|j|d< d|vr d|dg}|jt|dS )z<Build instructions from a template and an object definition.titler   z{schema}z

)schema)json_schemacopyr   r   joinformatrS   rT   )r   r   r   r   rh   rh   ri   build_instructions  s   


z'PromptedOutputSchema.build_instructionsdefault_templatec                 C  s(   | j p|}| j}|dusJ | ||S )zBGet instructions to tell model to output JSON matching the schema.N)r   r   r   )rv   r   r   r   rh   rh   ri   instructions  s   
z!PromptedOutputSchema.instructions)r   r   r   r   r   r>   r   r>   r   )r   ra   r   r&   r?   ra   )r   ra   r?   ra   )r@   r}   r~   r   r   r   r   r   r   r   r   rh   rh   r   ri   r     s   
 r   c                      s2   e Zd Zddd fd
dZedddZ  ZS )r   Nr   r   r   r   r   r   r>   r   c                  s   t  j||||d d S )N)r   r   r   r   r   )rv   r   r   r   r   r   rh   ri   r     s   
zToolOutputSchema.__init__r?   r%   c                 C  r   )Ntoolrh   ru   rh   rh   ri   r   
  r   zToolOutputSchema.mode)r   r   r   r   r   r>   r   r>   r   r   rh   rh   r   ri   r     s
    r   c                   @  s    e Zd Ze		ddddZdS )BaseOutputProcessorFTdatara   r9   r:   allow_partialr>   r=   r?   r$   c                   s   t  )z`Process an output message, performing validation and (if necessary) calling the output function.r   rv   r   r9   r   r=   rh   rh   ri   process  s   	zBaseOutputProcessor.processNFT
r   ra   r9   r:   r   r>   r=   r>   r?   r$   )r@   r}   r~   r   r   rh   rh   rh   ri   r     s
    r   c                   @     e Zd ZU ded< dS )BaseObjectOutputProcessorr&   r   Nr@   r}   r~   r   rh   rh   rh   ri   r        
 r   c                      s8   e Zd ZU ded< d fddZ		ddddZ  ZS )r   r   wrappedc                   s   || _ t j|jd d S )Nr   )r   r   r   r   )rv   r   r   rh   ri   r   %  s   z PromptedOutputProcessor.__init__FTr   ra   r9   r:   r   r>   r=   r?   r$   c                   s&   t |}| jj||||dI d H S )Nr   r=   )r   strip_markdown_fencesr   r   )rv   r   r9   r   r=   r   rh   rh   ri   r   )  s
   
zPromptedOutputProcessor.process)r   r   r   r   r@   r}   r~   r   r   r   r   rh   rh   r   ri   r   !  s   
 r   c                      sv   e Zd ZU dZded< ded< dZded< ddddd$ fddZ		d%d&ddZ	d'd(dd Z	d)d*d"d#Z	  Z
S )+r   Nr   outer_typed_dict_keyr   	validatorz&_function_schema.FunctionSchema | Noner   r   re   !OutputTypeOrFunction[OutputDataT]r   r   r   r   c                  sD  t |s
t |r!t|t| _| jj| _| jj}| jj|d< nHt	
|r-t| }}n$d| _ttt |}tdd|i}	t|	}tdd|t| B i}
t|
}tt|j| _t	|jtd}| jri|d |d u rw|dd  }rw|}|dd  }r|d u r|}n| d| }t jt|pt|dd |||d	d
 d S )Nr   responseresponse_data_typed_dictresponse_validation_typed_dict)schema_generatorr   z. r@   )r   r   r   r   r   )rq   
isfunctionismethodr   r7   r.   r   r   r   r   is_model_liker   r   r   rD   r$   r   r   r   check_object_json_schemapopgetr   r   r&   rM   )rv   re   r   r   r   r   json_schema_type_adaptervalidation_type_adapteroutput_typer   r   json_schema_titlejson_schema_descriptionr   rh   ri   r   =  sN   




zObjectOutputProcessor.__init__FTr   str | dict[str, Any] | Noner9   r:   r   r>   r=   r?   r$   c              
     sh   z|  ||}W n ty' } z|r"tj|jddd}t|| d}~ww | |||I dH }|S )a  Process an output message, performing validation and (if necessary) calling the output function.

        Args:
            data: The output data to validate.
            run_context: The current run context.
            allow_partial: If true, allow partial validation.
            wrap_validation_errors: If true, wrap the validation errors in a retry message.

        Returns:
            Either the validated output data (left) or a retry message (right).
        F)include_urlrH   N)r{   r   rZ   r[   errorsr    rY   )rv   r   r9   r   r=   re   erg   rh   rh   ri   r   ~  s   

	zObjectOutputProcessor.processr<   c                 C  s>   |rdnd}t |tr| jj|pd|dS | jj|pi |dS )Nztrailing-stringsoffz{})r   )r`   ra   r   validate_jsonvalidate_python)rv   r   r   pyd_allow_partialrh   rh   ri   r{     s   
zObjectOutputProcessor.validater   c                   s4   | j  }r
|| }| jrt| j|||I d H }|S r   )r   r   rj   )rv   re   r9   r=   krh   rh   ri   rY     s   


zObjectOutputProcessor.call)re   r   r   r   r   r   r   r   r   )
r   r   r9   r:   r   r>   r=   r>   r?   r$   )F)r   r   r   r>   r?   r<   r|   )re   r<   r9   r:   r=   r>   r?   r   )r@   r}   r~   r   r   r   r   r   r{   rY   r   rh   rh   r   ri   r   7  s   
 E$r   c                   @  s   e Zd ZU ded< ded< dS )UnionOutputResultra   kindr/   r   Nr   rh   rh   rh   ri   r	    s   
 r	  c                   @  r   )UnionOutputModelr	  rx   Nr   rh   rh   rh   ri   r    r   r  c                      sJ   e Zd ZU ded< ded< ddddd fddZ		ddddZ  ZS ) r   z'ObjectOutputProcessor[UnionOutputModel]_union_processorz-dict[str, ObjectOutputProcessor[OutputDataT]]_processorsNr   r   r   r   r   r   r   r   c                  sp  t td| _g }i | _|D ]G}t ||d}|j}|jp|j}	d}
|	}|	| jv r7|
d7 }
| d|
 }	|	| jv s'|| j|	< |j}|jrG|j|d< |jrO|j|d< |	| qt
|\}}g }t| j |D ]0\}	}|dd }|dd }dd|	d	|d
ddgdd}|r||d< |r||d< |	| qfddd|iidgdd}|r||d< t jt||||dd d S )N)re   )re   r   r   _r   r   rC   string)rD   const)r
  r   r
  r   F)rD   rE   requiredadditionalPropertiesrx   anyOfz$defs)r   r   r   r   r   )r   r  r  r  r   r   r@   r   r   r   r   merge_json_schema_defszipkeysr   r   r   r&   )rv   r   r   r   r   json_schemasre   r   r   
object_keyioriginal_keyr   all_defsdiscriminated_json_schemasr   discriminated_json_schemar   rh   ri   r     sr   






zUnionOutputProcessor.__init__FTr   ra   r9   r:   r   r>   r=   r?   r$   c              
     s   | j j||||dI d H }|j}|j}|j}z| j| }	W n ty; }
 z|r6tjd| d}t	||
 d }
~
ww |	j||||dI d H S )Nr   zInvalid kind: r  )
r  r   rx   r
  r   r  KeyErrorrZ   r[   r    )rv   r   r9   r   r=   union_objectrx   r
  
inner_datar   r  rg   rh   rh   ri   r     s&   
zUnionOutputProcessor.process)r   r   r   r   r   r   r   r   r   r   r   rh   rh   r   ri   r     s   
 Ur   c                   @  s   e Zd Z		ddddZdS )r   FTr   ra   r9   r:   r   r>   r=   r?   r$   c                   s   t t|S r   )r   r$   r   rh   rh   ri   r   9  s   
zTextOutputProcessor.processNr   r   )r@   r}   r~   r   rh   rh   rh   ri   r   8  s    r   c                      s@   e Zd ZU ded< ded< dddZ			
dd fddZ  ZS )r   r8   r   ra   _str_argument_namerA   TextOutputFunc[OutputDataT]c                 C  sl   t |t| _ | j jdi  }r-t|dks-tt| d  }r-||i ddkr1t	d|| _
d S )NrE   r   rD   r  z>TextOutput must take a function taking a single `str` argument)r   r7   r.   r   r   rp   r   iterr  r!   r!  )rv   rA   arguments_schemaargument_namerh   rh   ri   r   H  s   
z$TextFunctionOutputProcessor.__init__FTr   r9   r:   r   r>   r=   r?   r$   c                   s:   | j |i}t| j|||I d H }t ||||I d H S r   )r!  rj   r   r   r   )rv   r   r9   r   r=   r;   r   rh   ri   r   X  s   
z#TextFunctionOutputProcessor.process)rA   r"  r   r   r   rh   rh   r   ri   r   C  s   
 
r   c                   @  s   e Zd ZU dZded< 	 ded< 	 ded< ded	< e	
	
	
d,d-ddZ		
d.d/ddZed0ddZ	ed1ddZ
d2d#d$Zd3d*d+Zd
S )4r   zEA toolset that contains contains output tools for agent output types.list[ToolDefinition]
_tool_defs%dict[str, ObjectOutputProcessor[Any]]
processorsintmax_retriesz&list[OutputValidator[AgentDepsT, Any]]output_validatorsNr   Alist[OutputTypeOrFunction[OutputDataT] | ToolOutput[OutputDataT]]r   r   r   r   r   r?   Self | Nonec              	   C  sL  t |dkrd S i }g }|pt}|}|}	t |dk}
|D ]}d }d }d }t|tr5|j}|j}|j}|j}|p8|}|d u r?|	}t|||d}|j	}|d u ra|}|
rat
d|jpXd}|d| 7 }d}|}||v rx|d7 }| d| }||v si|j}|st}|
r|j d| }t|||j|j|jdd}|||< || q| ||d	S )
Nr   r   )re   r   r    r  z: re   )r   r   parameters_json_schemar   r   r
  )r)  	tool_defs)rp   DEFAULT_OUTPUT_TOOL_NAMEr`   r,   r   r   r   re   r   r   OUTPUT_TOOL_NAME_SANITIZERsubDEFAULT_OUTPUT_TOOL_DESCRIPTIONr0   r   r   r   )r   r   r   r   r   r)  r1  default_namedefault_descriptiondefault_strictmultiplere   r   r   	safe_namer  original_nametool_defrh   rh   ri   r   p  sb   
zOutputToolset.buildr   r1  -list[OutputValidator[AgentDepsT, Any]] | Nonec                 C  s    || _ || _|| _|pg | _d S r   )r)  r'  r+  r,  )rv   r1  r)  r+  r,  rh   rh   ri   r     s   zOutputToolset.__init__c                 C  r   )Nz<output>rh   ru   rh   rh   ri   id  r   zOutputToolset.idra   c                 C  r   )Nzthe agent's output toolsrh   ru   rh   rh   ri   label  r   zOutputToolset.labelctxr:   "dict[str, ToolsetTool[AgentDepsT]]c                   s    fdd j D S )Nc              	     s,   i | ]}|j t | j j|j  jd qS ))r   r<  r+  args_validator)r   r2   r+  r)  r   )r   r<  ru   rh   ri   
<dictcomp>  s    z+OutputToolset.get_tools.<locals>.<dictcomp>)r'  )rv   r@  rh   ru   ri   	get_tools  s   
zOutputToolset.get_tools	tool_argsr<   r   ToolsetTool[AgentDepsT]r   c                   sD   | j | j||ddI d H }| jD ]}|j||ddI d H }q|S )NF)r=   )r)  rY   r,  r{   )rv   r   rE  r@  r   re   r   rh   rh   ri   	call_tool  s
   
zOutputToolset.call_toolr   )
r   r-  r   r   r   r   r   r   r?   r.  )r   N)r1  r&  r)  r(  r+  r*  r,  r=  )r?   r   )r?   ra   )r@  r:   r?   rA  )
r   ra   rE  r<   r@  r:   r   rF  r?   r   )r@   r}   r~   __doc__r   r   r   r   r   r>  r?  rD  rG  rh   rh   rh   ri   r   e  s,   
 I
r   r   ;OutputTypeOrFunction[T] | Sequence[OutputTypeOrFunction[T]]!Sequence[OutputTypeOrFunction[T]]c                 C     d S r   rh   r   rh   rh   ri   r     s   r   OutputSpec[T]Sequence[_OutputSpecItem[T]]c                 C  rK  r   rh   rL  rh   rh   ri   r     s   c                 C  sz   t | tr| }n| f}g }|D ]+}t |tr#|tttt | qt| }r0|| q|	tt
t | q|S r   )r`   r   extendr   r   r'   r3   r   get_union_argsr   r-   )r   r   outputs_flatre   union_typesrh   rh   ri   r     s   

r|   )
r7   r8   r9   r:   r;   r<   r=   r>   r?   r   )r   rI  r?   rJ  )r   rM  r?   rN  )a
__future__r   _annotationsrq   rS   reabcr   r   collections.abcr   r   r   dataclassesr   r	   typingr
   r   r   r   r   r   pydanticr   r   r   pydantic_corer   r   typing_extensionsr   r   r   pydantic_ai._instrumentationr   r/  r   r   r   rZ   _run_contextr   r   
exceptionsr   r    r!   re   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   toolsr.   r/   r0   toolsets.abstractr1   r2   r3   ra   r4   OutputValidatorFuncr2  r5  compiler3  rj   rk   r   r   r   r   r   r   r   r   r   r   r   r   r	  r  r   r   r   r   r   rh   rh   rh   ri   <module>   s     8

T4 (	, q!x