
    .h                         d dl mZ d dlZd dlmZ d dlmZ d dlmZ dede	fdZ
dded	ee         de	fd
Zdded	ee         de	fdZddedee	         dej        fdZdS )    )OptionalN)Agent)Handoff)Toolagentreturnc                     dg}|                     t          |                      |                     t          |                      |                     d           d                    |          S )z
    Generates the main graph structure in DOT format for the given agent.

    Args:
        agent (Agent): The agent for which the graph is to be generated.

    Returns:
        str: The DOT format string representing the graph.
    zq
    digraph G {
        graph [splines=true];
        node [fontname="Arial"];
        edge [penwidth=1.5];
    } )appendget_all_nodesget_all_edgesjoin)r   partss     \/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/agents/extensions/visualization.pyget_main_graphr   
   sf    	E 
LLu%%&&&	LLu%%&&&	LL775>>    parentc                 N   g }|                     d           |s&|                     d| j         d| j         d           | j        D ](}|                     d|j         d|j         d           )| j        D ]}t	          |t
                    r&|                     d|j         d|j         d           t	          |t                    rH|                     d|j         d|j         d           |                     t          |                     d	                    |          S )z
    Recursively generates the nodes for the given agent and its handoffs in DOT format.

    Args:
        agent (Agent): The agent for which the nodes are to be generated.

    Returns:
        str: The DOT format string representing the nodes.
    z"__start__" [label="__start__", shape=ellipse, style=filled, fillcolor=lightblue, width=0.5, height=0.3];"__end__" [label="__end__", shape=ellipse, style=filled, fillcolor=lightblue, width=0.5, height=0.3];"z
" [label="zJ", shape=box, style=filled, fillcolor=lightyellow, width=1.5, height=0.8];zM", shape=ellipse, style=filled, fillcolor=lightgreen, width=0.5, height=0.3];zY", shape=box, style=filled, style=rounded, fillcolor=lightyellow, width=1.5, height=0.8];r   )
r   nametoolshandoffs
isinstancer   
agent_namer   r   r   r   r   r   toolhandoffs        r   r   r   "   s    E 
LL	7    
=
 = =ej = = =	
 	
 	

  
 
=	 = =TY = = =	
 	
 	
 	

 > 1 1gw'' 	LLBG& B B'2D B B B  
 gu%% 	1LLBGL B BGL B B B  
 LLw//000775>>r   c                    g }|s|                     d| j         d           | j        D ]8}|                     d| j         d|j         d|j         d| j         d	           9| j        D ]}t	          |t
                    r&|                     d| j         d|j         d           t	          |t                    rI|                     d| j         d|j         d           |                     t          ||                      | j        s3t	          | t                    s|                     d| j         d	           d

                    |          S )aA  
    Recursively generates the edges for the given agent and its handoffs in DOT format.

    Args:
        agent (Agent): The agent for which the edges are to be generated.
        parent (Agent, optional): The parent agent. Defaults to None.

    Returns:
        str: The DOT format string representing the edges.
    z"__start__" -> "z";z

        "z" -> "z)" [style=dotted, penwidth=1.5];
        "z" [style=dotted, penwidth=1.5];z
            "r   z" -> "__end__";r   )r   r   r   r   r   r   r   r   r   r   r   r   s        r   r   r   T   s    E 86
666777 J J I
*I I II I
)I I :I I I 	J 	J 	J 	J > 8 8gw'' 	:LL 9j9 9 ' 29 9 9 : : :gu%% 	8LL 3j3 3 '3 3 3 4 4 4LLw66777> 6*UD"9"9 64444555775>>r   filenamec                     t          |           }t          j        |          }|r|                    |dd           |S )aG  
    Draws the graph for the given agent and optionally saves it as a PNG file.

    Args:
        agent (Agent): The agent for which the graph is to be drawn.
        filename (str): The name of the file to save the graph as a PNG.

    Returns:
        graphviz.Source: The graphviz Source object representing the graph.
    pngT)formatcleanup)r   graphvizSourcerender)r   r    dot_codegraphs       r   
draw_graphr*   x   sE     e$$HOH%%E ;XeT:::Lr   )N)typingr   r%   agentsr   agents.handoffsr   agents.toolr   strr   r   r   r&   r*    r   r   <module>r1      s                # # # # # #      % C    0/ / / /3 / / / /d! ! ! !3 ! ! ! !H e x}       r   