
    .hS#                    N   U d dl mZ d dlZd dlm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 d dlmZmZ dd	lmZmZ dd
l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!m"Z"m#Z# erddl$m%Z%  ede	          Z&e
ee	         e&ge	f         Z'e
ee	         ge	f         Z( ed           G d d                      Z)e
e)ge)f         Z*de+d<   	 e G d dee                               Z,eddddd0d$            Z-edddd%d1d*            Z-edddd%d2d,            Z-	 	 	 	 	 d3d4d/Z-dS )5    )annotationsN)	Awaitable)	dataclass)TYPE_CHECKINGAnyCallableGenericcastoverload)TypeAdapter)	TypeAliasTypeVar   )ModelBehaviorError	UserError)RunItemTResponseInputItem)RunContextWrapperTContext)ensure_strict_json_schema)	SpanError)_error_tracing_json_transforms)AgentTHandoffInput)defaultT)frozenc                  2    e Zd ZU ded<   	 ded<   	 ded<   dS )HandoffInputDataz$str | tuple[TResponseInputItem, ...]input_historyztuple[RunItem, ...]pre_handoff_items	new_itemsN)__name__
__module____qualname____annotations__     L/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/agents/handoffs.pyr    r       sH         7777 +*** #""" r)   r    r   HandoffInputFilterc                      e Zd ZU dZded<   	 ded<   	 ded<   	 ded<   	 ded	<   	 d
Zded<   	 dZded<   	 ddZedd            Z	edd            Z
d
S )Handoffa1  A handoff is when an agent delegates a task to another agent.
    For example, in a customer support scenario you might have a "triage agent" that determines
    which agent should handle the user's request, and sub-agents that specialize in different
    areas like billing, account management, etc.
    str	tool_nametool_descriptionzdict[str, Any]input_json_schemazCCallable[[RunContextWrapper[Any], str], Awaitable[Agent[TContext]]]on_invoke_handoff
agent_nameNzHandoffInputFilter | Noneinput_filterTboolstrict_json_schemaagent
Agent[Any]returnc                    d|j          d}|S )Nz{'assistant': 'z'})name)selfr7   bases      r*   get_transfer_messagezHandoff.get_transfer_messagee   s    1%*111r)   c                :    t          j        d|j                   S )Ntransfer_to_)r   transform_string_function_styler;   clsr7   s     r*   default_tool_namezHandoff.default_tool_namei   s    :;V%*;V;VWWWr)   c                *    d|j          d|j        pd S )NzHandoff to the z agent to handle the request.  )r;   handoff_descriptionrB   s     r*   default_tool_descriptionz Handoff.default_tool_descriptionm   s/    1ej 1 1(.B1 1	
r)   )r7   r8   r9   r.   )r$   r%   r&   __doc__r'   r4   r6   r>   classmethodrD   rH   r(   r)   r*   r-   r-   4   s           NNN;B%%%% [ZZZ OOO<.2L2222  $####    X X X [X 
 
 
 [
 
 
r)   r-   )tool_name_overridetool_description_overrider4   r7   Agent[TContext]rK   
str | NonerL   r4   5Callable[[HandoffInputData], HandoffInputData] | Noner9   Handoff[TContext]c                   d S Nr(   )r7   rK   rL   r4   s       r*   handoffrS   u   s	     r)   )rL   rK   r4   
on_handoff!OnHandoffWithInput[THandoffInput]
input_typetype[THandoffInput]c                   d S rR   r(   )r7   rT   rV   rL   rK   r4   s         r*   rS   rS      s	     r)   OnHandoffWithoutInputc                   d S rR   r(   )r7   rT   rL   rK   r4   s        r*   rS   rS      s	     r)   @OnHandoffWithInput[THandoffInput] | OnHandoffWithoutInput | Nonetype[THandoffInput] | Nonec                |    rsrr
J d            xt                    s
J d            t          j                  }t          |j                  dk    rt          d          t                                                    }nAdi };t          j                  }t          |j                  dk    rt          d          	 dd fd}|pt          	                               }	|pt          
                               }
t          |          }t          |	|
||| j                  S )a  Create a handoff from an agent.

    Args:
        agent: The agent to handoff to, or a function that returns an agent.
        tool_name_override: Optional override for the name of the tool that represents the handoff.
        tool_description_override: Optional override for the description of the tool that
            represents the handoff.
        on_handoff: A function that runs when the handoff is invoked.
        input_type: the type of the input to the handoff. If provided, the input will be validated
            against this type. Only relevant if you pass a function that takes an input.
        input_filter: a function that filters the inputs that are passed to the next agent.
    z@You must provide either both on_input and input_type, or neitherNzon_handoff must be callable   z5on_handoff must take two arguments: context and inputr   z*on_handoff must take one argument: contextctxRunContextWrapper[Any]
input_jsonrN   r9   r8   c                  K   |4t          j        t          dddi                     t          d          t	          j        |d          }t          t          t                             }t          j
        |          r || |           d {V  nU || |           nHFt          t                    }t          j
        |          r ||            d {V  n ||            S )Nz6Handoff function expected non-null input, but got Nonedetailszinput_json is None)messagedataF)json_strtype_adapterpartial)r   attach_error_to_current_spanr   r   r   validate_jsonr
   OnHandoffWithInputr   inspectiscoroutinefunctionrY   )	r_   ra   validated_input
input_funcno_input_funcr7   rV   rT   rg   s	        r*   _invoke_handoffz handoff.<locals>._invoke_handoff   sG      !l&>!; X')=>     ))abbb#1#)  O
 0?LLJ*:66 1 jo6666666666
30000# !6
CCM*=99 ##mC((((((((((c"""r)   )r/   r0   r1   r2   r4   r3   rR   )r_   r`   ra   rN   r9   r8   )callablerl   	signaturelen
parametersr   r   json_schemar-   rD   rH   r   r;   )r7   rK   rL   rT   rV   r4   sigr1   rq   r/   r0   rg   s   `  ``      @r*   rS   rS      s   (  : z j  J   
##BB%BBBB
++s~!##STTT":..(4466!#J//C3>""a'' LMMM ?C         @ #Fg&?&?&F&FI0[G4T4TUZ4[4[ 22CDD)+)!:   r)   )
r7   rM   rK   rN   rL   rN   r4   rO   r9   rP   )r7   rM   rT   rU   rV   rW   rL   rN   rK   rN   r4   rO   r9   rP   )r7   rM   rT   rY   rL   rN   rK   rN   r4   rO   r9   rP   )NNNNN)r7   rM   rK   rN   rL   rN   rT   r[   rV   r\   r4   rO   r9   rP   ).
__future__r   rl   collections.abcr   dataclassesr   typingr   r   r   r	   r
   r   pydanticr   typing_extensionsr   r   
exceptionsr   r   itemsr   r   run_contextr   r   strict_schemar   tracing.spansr   utilr   r   r   r7   r   r   rk   rY   r    r+   r'   r-   rS   r(   r)   r*   <module>r      s   " " " " " " "  % % % % % % ! ! ! ! ! ! H H H H H H H H H H H H H H H H             0 0 0 0 0 0 0 0 5 5 5 5 5 5 5 5 . . . . . . . . 4 4 4 4 4 4 4 4 4 4 4 4 4 4 $ $ $ $ $ $ 4 4 4 4 4 4 4 4 4 4  55505}EsJK  "3C"8!93!>?  $       $ !)*:);=M)M N  N N N N F =
 =
 =
 =
 =
gh =
 =
 =
@ 
 &*,0JN     
 
 -1%)JN     
 

 -1%)JN     
 &*,0SW-1JNV V V V V V Vr)   