
    .Ui                        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
dZ		 d	 	 	 	 	 	 	 ddZ
	 d	 	 	 	 	 	 	 ddZddd	Zy)    )annotationsN)Agent)Handoff)Toolc                    dg}|j                  t        |              |j                  t        |              |j                  d       dj                  |      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)agentpartss     {/home/jay/workspace/tools/ai-image-gen/jaaz-app/server/venv/lib/python3.12/site-packages/agents/extensions/visualization.pyget_main_graphr   
   sL    	E 
LLu%&	LLu%&	LL775>    c                n   |
t               }| j                  |v ry|j                  | j                         g }|s=|j                  d       |j                  d| j                   d| j                   d       | j                  D ].  }|j                  d|j                   d|j                   d       0 | j
                  D ].  }|j                  d|j                   d|j                   d       0 | j                  D ]  }t        |t              r,|j                  d|j                   d|j                   d       t        |t              sP|j                  |vr,|j                  d|j                   d|j                   d       |j                  t        || |              dj                  |      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.
    r	   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];zF", shape=box, style=filled, fillcolor=lightgrey, width=1, height=0.5];zY", shape=box, style=filled, style=rounded, fillcolor=lightyellow, width=1.5, height=0.8];)setnameaddr
   toolsmcp_servershandoffs
isinstancer   
agent_namer   r   r   r   parentvisitedr   tool
mcp_serverhandoffs          r   r   r   "   s    %zzWKK

E ;	
 	

|:ejj\ 2= =	

  
		{*TYYK 0< =	

 '' 


 
:??*; <9 :	

 >> Agw'LLG&&'z'2D2D1E FA B
 gu%||7*~Z~ >E F
 LLww?@A  775>r   c                   |
t               }| j                  |v ry|j                  | j                         g }|s|j                  d| j                   d       | j                  D ]H  }|j                  d| j                   d|j                   d|j                   d| j                   d	       J | j
                  D ]H  }|j                  d| j                   d|j                   d|j                   d| j                   d		       J | j                  D ]  }t        |t              r,|j                  d
| j                   d|j                   d       t        |t              sP|j                  d
| j                   d|j                   d       |j                  t        || |              | j                  s/t        | t              s|j                  d| j                   d       dj                  |      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.
    r	   z"__start__" -> "z";z

        "z" -> "z)" [style=dotted, penwidth=1.5];
        "z" [style=dotted, penwidth=1.5];z)" [style=dashed, penwidth=1.5];
        "z" [style=dashed, penwidth=1.5];z
            "r   z" -> "__end__";)r   r   r   r
   r   r   r   r   r   r   r   r   r   r   r   s          r   r   r   c   s    %zzWKK

E'

|267 J 

**VDII; '

))F5::,&EI 	JJ
 '' P
 

**VJOO, -

//	&,KO 	PP
 >> Agw'LL jj\ 2 2329 :gu%LL jj\~R3 4LLww?@A >>*UD"9qO45775>r   c                r    t        |       }t        j                  |      }|r|j                  |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   filenamedot_codegraphs       r   
draw_graphr.      s6     e$HOOH%EXeT:Lr   )r   r   returnstr)NN)r   r   r   zAgent | Noner   zset[str] | Noner/   r0   )N)r   r   r+   z
str | Noner/   zgraphviz.Source)
__future__r   r(   agentsr   agents.handoffsr   agents.toolr   r   r   r   r.    r   r   <module>r6      sx    "   # 2 KO>>&>8G>>D KO..&.8G..br   