-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Visualization Extension] Enhance agent graph visualization to prevent infinite recursion, add mermaid graph #445
base: main
Are you sure you want to change the base?
Conversation
…with recursive handoffs
Hey @rm-openai I noticed the original PR hasn’t had updates, so I’ve created a follow-up here with additional fixes and improvements. Happy to adjust things if needed. |
Addressed #387 (comment) and #387 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, PR is looking great! Some changes requested inline
|
||
@dataclass(frozen=True) | ||
class Edge: | ||
source: str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't these be Node
not str
?
def _add_agent_nodes_and_edges( | ||
self, | ||
agent: Agent, | ||
parent: Optional[Agent], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use Agent | None instead?
graph: Graph, | ||
) -> None: | ||
# Add agent node | ||
graph.add_node(Node(agent.name, agent.name, NodeType.AGENT)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using agent.name
as the ID isn't safe unfortunately, since agents can have the same name. You'd need to do an instance equality check everywhere instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works when agent.handoffs have Agent instances. but apparently it's a bit tricky when Handoff objects are passed. It only has the target agent's name (handoff.agent_name), not an Agent instance. The instance itself only gets resolved at runtime with handoff.on_invoke_handoff. so we can't consistently do instance equality checks to link Handoff instances back to the Agent instances at build time if we consider cases with recursive handoffs. The only option I see is to resolve this using agent names but mention the caveat in the docs. any suggestions?
|
||
|
||
def draw_graph( | ||
agent: Agent, filename: Optional[str] = None, renderer: str = "graphviz" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renderer
should be either a Literal or an enum here
Also please add str | None = None
instead of Optional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as before
should be looking good now |
Improves agent graph visualization logic:
Improves on PR #387, addressing pending change requests.