
    Ti              	           d dl mZmZmZmZmZ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mZ d dlmZ d dlmZ  G d d	e      Zd
edefdZdddded
ee   dee   defdZ G d de      Z G d d      Zy)    )	AnnotatedOptionalDictAnySequenceList	TypedDict)Command)InjectedState)ToolMessage)BaseToolInjectedToolCallIdtool) METADATA_KEY_HANDOFF_DESTINATION)ToolInfoJsonc                       e Zd ZU dZeed<   y)
ToolConfigu   工具配置r   N__name__
__module____qualname____doc__str__annotations__     h/home/jay/workspace/tools/ai-image-gen/jaaz-app/server/services/langgraph_service/configs/base_config.pyr   r   
   s
    
Ir   r   namereturnc                 b    | j                         j                  dd      j                  dd      S )z6Normalize agent name to be compatible with tool names. _-)lowerreplace)r   s    r   _normalize_agent_namer&      s(    ::<S)11#s;;r   N)r   description
agent_namer'   c                     dt                |d  d}t        |dz         dt        t        t        t
        f   t        f   dt        t        t        f   dt        t
           f fd	       }t        |d
t         i       |S )a7  Create a tool that can handoff control to the requested agent.

    Args:
        agent_name: The name of the agent to handoff control to, i.e.
            the name of the agent node in the multi-agent graph.
            Agent names should be simple, clear and unique, preferably in snake_case,
            although you are only limited to the names accepted by LangGraph
            nodes as well as the tool names accepted by LLM providers
            (the tool name will look like this: `transfer_to_<agent_name>`).
        name: Optional name of the tool to use for the handoff.
            If not provided, the tool name will be `transfer_to_<agent_name>`.
        description: Optional description for the handoff tool.
            If not provided, the tool description will be `Ask agent <agent_name> for help`.
    transfer_to_zAsk agent 'z
' for helpaE  
    
IMPORTANT RULES:
            1. You MUST complete the other tool calls and wait for their result BEFORE attempting to transfer to another agent
            2. Do NOT call this handoff tool with other tools simultaneously
            3. Always wait for the result of other tool calls before making this handoff call
    )r'   statetool_call_idr   c                 r    t        d |      }t        t        j                  | d   |gz   d      S )Nz.<hide_in_user_ui> Successfully transferred to )contentr   r,   messages)r/   active_agent)gotographupdate)r   r
   PARENT)r+   r,   tool_messager(   r   s      r   handoff_to_agentz-create_handoff_tool.<locals>.handoff_to_agent+   sS     #DZLQ%

 .. %j 1!N!#4>@
 	
r   metadata)r&   r   r   r   r   r   r   r   r
   setattrr   )r(   r   r'   r6   s   ``  r   create_handoff_toolr9      s    " |3J?@A#J<z:	$K )  	
c3h67
%7 78
 

	
  j,j+: ; r   c                   &    e Zd ZU dZeed<   eed<   y)HandoffConfigu   切换智能体配置r(   r'   Nr   r   r   r   r;   r;   G   s    Or   r;   c                   B    e Zd ZdZ	 d	dedee   dedeee	      ddf
dZ
y)
BaseAgentConfigu   智能体配置基类

    此类用于存储智能体配置信息的配置类，不是实际的智能体。
    实际的智能体将通过 LangGraph 的 create_react_agent 函数创建。
    Nr   toolssystem_prompthandoffsr   c                 D    || _         || _        || _        |xs g | _        y N)r   r>   r?   r@   )selfr   r>   r?   r@   s        r   __init__zBaseAgentConfig.__init__T   s%     	
*-5^r   rB   )r   r   r   r   r   r   r   r   r   r;   rD   r   r   r   r=   r=   M   sP     37
<
< %
< 	
<
 4./
< 

<r   r=   )typingr   r   r   r   r   r   r	   langgraph.typesr
   langgraph.prebuiltr   langchain_core.messagesr   langchain_core.toolsr   r   r   langgraph_swarm.handoffr   models.tool_modelr   r   r   r&   r9   r;   r=   r   r   r   <module>rL      s    L L L # , / C C D * 
< < < /3QU00&sm0AI#00fI < <r   