
    .hr               	      Z   U d dl mZ d dlZd dlZd dl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mZmZmZmZmZmZmZmZ d dlmZmZ d dlmZ d dlmZ d d	l m!Z! d
dl"m#Z#m$Z$ d
dl%m&Z& erd
dl'm(Z( eZ)	 eZ*	 eZ+	 eZ,	  edee+e*f                   Z-e G d de	e-         ej.                              Z/e G d de/e                               Z0e G d de/e                               Z1e G d de/e*                               Z2eeeeef         Z3de4d<   	 e G d de/e3                               Z5e G d de/eeef                                        Z6e G d de/e                               Z7ee0e1e2e5e6e7f         Z8de4d <   	 e G d! d"                      Z9 G d# d$          Z:dS )%    )annotationsN)	dataclass)TYPE_CHECKINGAnyGenericLiteralTypeVarUnion)ResponseResponseComputerToolCallResponseFileSearchToolCallResponseFunctionToolCallResponseFunctionWebSearchResponseInputItemParamResponseOutputItemResponseOutputMessageResponseOutputRefusalResponseOutputTextResponseStreamEvent)ComputerCallOutputFunctionCallOutput)ResponseReasoningItem)	BaseModel)	TypeAlias   )AgentsExceptionModelBehaviorError)Usage)AgentT)boundc                  0    e Zd ZU ded<   	 ded<   	 d	dZdS )
RunItemBase
Agent[Any]agentr    raw_itemreturnTResponseInputItemc                    t          | j        t                    r| j        S t          | j        t                    r| j                            d          S t          dt          | j                             )zHConverts this item into an input item suitable for passing to the model.Texclude_unsetzUnexpected raw item type: )
isinstancer&   dictr   
model_dumpr   typeselfs    I/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/agents/items.pyto_input_itemzRunItemBase.to_input_item:   sn    dmT** 	V= y11 	V=++$+???!"TtDM?R?R"T"TUUU    N)r'   r(   )__name__
__module____qualname____annotations__r3    r4   r2   r#   r#   /   sM         ?KKK
	V 	V 	V 	V 	V 	Vr4   r#   c                  .    e Zd ZU dZded<   	 dZded<   dS )MessageOutputItemz"Represents a message from the LLM.r   r&   message_output_itemzLiteral['message_output_item']r/   Nr5   r6   r7   __doc__r8   r/   r9   r4   r2   r;   r;   F   s8         ,,####*+@D@@@@@@r4   r;   c                  .    e Zd ZU dZded<   	 dZded<   dS )HandoffCallItemz?Represents a tool call for a handoff from one agent to another.r   r&   handoff_call_itemzLiteral['handoff_call_item']r/   Nr=   r9   r4   r2   r@   r@   P   s8         II&&&&J)<D<<<<<<r4   r@   c                  F    e Zd ZU dZded<   	 ded<   	 ded<   	 dZded	<   d
S )HandoffOutputItemz#Represents the output of a handoff.r(   r&   r$   source_agenttarget_agenthandoff_output_itemzLiteral['handoff_output_item']r/   Nr=   r9   r4   r2   rC   rC   Z   sV         --    F*0+@D@@@@@@r4   rC   r   ToolCallItemTypesc                  .    e Zd ZU dZded<   	 dZded<   dS )ToolCallItemzDRepresents a tool call e.g. a function call or computer action call.rG   r&   tool_call_itemzLiteral['tool_call_item']r/   Nr=   r9   r4   r2   rI   rI   s   s8         NN!&6D666666r4   rI   c                  :    e Zd ZU dZded<   	 ded<   	 dZded<   d	S )
ToolCallOutputItemz%Represents the output of a tool call.z'FunctionCallOutput | ComputerCallOutputr&   r   outputtool_call_output_itemz Literal['tool_call_output_item']r/   Nr=   r9   r4   r2   rL   rL   }   sI         //5555&KKK .EDDDDDDDr4   rL   c                  .    e Zd ZU dZded<   	 dZded<   dS )ReasoningItemzRepresents a reasoning item.r   r&   reasoning_itemzLiteral['reasoning_item']r/   Nr=   r9   r4   r2   rP   rP      s8         &&####!&6D666666r4   rP   RunItemc                  <    e Zd ZU ded<   	 ded<   	 ded<   	 dd	Zd
S )ModelResponsezlist[TResponseOutputItem]rM   r   usage
str | Noneresponse_idr'   list[TResponseInputItem]c                $    d | j         D             S )zPConvert the output into a list of input items suitable for passing to the model.c                :    g | ]}|                     d           S )Tr*   )r.   ).0its     r2   
<listcomp>z0ModelResponse.to_input_items.<locals>.<listcomp>   s&    HHHbD11HHHr4   )rM   r0   s    r2   to_input_itemszModelResponse.to_input_items   s    
 IHDKHHHHr4   N)r'   rX   )r5   r6   r7   r8   r^   r9   r4   r2   rT   rT      s\         %%%%NLLL1I I I I I Ir4   rT   c                      e Zd Zedd            Zedd            Zedd            Zedd            Zedd            Zedd            Z	dS )ItemHelpersmessageTResponseOutputItemr'   strc                    t          |t                    sdS |j        d         }t          |t                    r|j        S t          |t
                    r|j        S t          dt          |                     )z9Extracts the last text content or refusal from a message. zUnexpected content type: )	r,   r   contentr   textr   refusalr   r/   clsra   last_contents      r2   extract_last_contentz ItemHelpers.extract_last_content   s     '#899 	2r*l$677 	W$$&;<< 	W''$%UlASAS%U%UVVVr4   rV   c                    t          |t                    r)|j        d         }t          |t                    r|j        S dS )zHExtracts the last text content from a message, if any. Ignores refusals.rf   N)r,   r   rg   r   rh   rj   s      r2   extract_last_textzItemHelpers.extract_last_text   sD     g455 	)"?2.L,(:;; )#((tr4   inputstr | list[TResponseInputItem]rX   c                `    t          |t                    r|ddgS t          j        |          S )zDConverts a string or list of input items into a list of input items.user)rg   role)r,   rc   copydeepcopy)rk   rp   s     r2   input_to_new_input_listz#ItemHelpers.input_to_new_input_list   sD    
 eS!! 	  %"   }U###r4   itemslist[RunItem]c                n    d}|D ]/}t          |t                    r||                     |          z  }0|S )zFConcatenates all the text content from a list of message output items.re   )r,   r;   text_message_output)rk   rx   rh   items       r2   text_message_outputsz ItemHelpers.text_message_outputs   sI      	6 	6D$ 122 6//555r4   r;   c                f    d}|j         j        D ]!}t          |t                    r
||j        z  }"|S )z@Extracts all the text content from a single message output item.re   )r&   rg   r,   r   rh   )rk   ra   rh   r|   s       r2   r{   zItemHelpers.text_message_output   sC     $, 	" 	"D$ 233 "	!r4   	tool_callr   rM   r   c                    |j         |ddS )z@Creates a tool call output item from a tool call and its output.function_call_output)call_idrM   r/   )r   )rk   r   rM   s      r2   rN   z!ItemHelpers.tool_call_output_item   s     !(*
 
 	
r4   N)ra   rb   r'   rc   )ra   rb   r'   rV   )rp   rq   r'   rX   )rx   ry   r'   rc   )ra   r;   r'   rc   )r   r   rM   rc   r'   r   )
r5   r6   r7   classmethodrm   ro   rw   r}   r{   rN   r9   r4   r2   r`   r`      s        W W W [W    [ $ $ $ [$    [    [ 
 
 
 [
 
 
r4   r`   );
__future__r   abcru   dataclassesr   typingr   r   r   r   r	   r
   openai.types.responsesr   r   r   r   r   r   r   r   r   r   r   0openai.types.responses.response_input_item_paramr   r   .openai.types.responses.response_reasoning_itemr   pydanticr   typing_extensionsr   
exceptionsr   r   rU   r   r%   r   	TResponser(   rb   TResponseStreamEventr    ABCr#   r;   r@   rC   rG   r8   rI   rL   rP   rR   rT   r`   r9   r4   r2   <module>r      s   " " " " " " " 



  ! ! ! ! ! ! G G G G G G G G G G G G G G G G                          d c c c c c c c P P P P P P       ' ' ' ' ' ' ; ; ; ; ; ; ; ;       	 =+  K(  G*  HGCu02DDEFFF V V V V V'!*cg V V V, A A A A A$9: A A A = = = = =k":; = = = A A A A A$67 A A A  %       / 7 7 7 7 7;01 7 7 7 E E E E EU+=?Q+Q%RS E E E 7 7 7 7 7K 56 7 7 7      % I I I I I I I I,B
 B
 B
 B
 B
 B
 B
 B
 B
 B
r4   