
    /Ui              	           d dl 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
mZ d dlmZ d dlmZ  e j                   d      Zd	Zd
edefdZdddd
ededz  dedz  defdZddededee   fdZy)    N)ToolMessage)BaseToolInjectedToolCallIdtool)CompiledStateGraph)InjectedStateToolNode)Command)	Annotatedz\s+__handoff_destination
agent_namereturnc                 f    t         j                  d| j                               j                         S )z8Normalize an agent name to be used inside the tool name._)WHITESPACE_REsubstriplower)r   s    s/home/jay/workspace/tools/ai-image-gen/jaaz-app/server/venv/lib/python3.12/site-packages/langgraph_swarm/handoff.py_normalize_agent_namer      s'    S*"2"2"45;;==    )namedescriptionr   r   c                      dt                |d  d}t        |      dt        t        t        f   dt        t
        t        f   f f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 help)r   statetool_call_idc                 r    t        d |      }t        t        j                  | d   |gz   d      S )Nz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*   sM    
 #2:,?%

 .. %j 1\N BT^_
 	
r   )	r   r   r   dictr   strr    METADATA_KEY_HANDOFF_DESTINATIONmetadata)r   r   r   r'   s   ``  r   create_handoff_toolr,      s    " |3J?@A#J<z:	$K(
},-
%7 78
 )
 "B: Nr   agenttool_node_namec                 @   | j                         j                  }||vrg S ||   j                  }t        |t              sg S |j
                  j                         }|D cg c]3  }|j                  %t        |j                  v r|j                  t           5 c}S c c}w )z6Get a list of destinations from agent's handoff tools.)		get_graphnodesdata
isinstancer	   tools_by_namevaluesr+   r*   )r-   r.   r1   	tool_nodetoolsr   s         r   get_handoff_destinationsr8   >   s    OO##EU"	n%**Ii*	##**,E ==$)IT]])Z 	67  s    8B)r7   )relangchain_core.messagesr   langchain_core.toolsr   r   r   langgraph.graph.stater   langgraph.prebuiltr   r	   langgraph.typesr
   typing_extensionsr   compiler   r*   r)   r   r,   listr8    r   r   <module>rC      s    	 / C C 4 6 # '

6"#:  >c >c > ,04((!Dj(>ADj((V$6  Z^_bZc r   