feat: Add Graphviz-based agent visualization functionality#147
feat: Add Graphviz-based agent visualization functionality#147rm-openai merged 35 commits intoopenai:mainfrom
Conversation
…into feat/draw_graph
rm-openai
left a comment
There was a problem hiding this comment.
This is such a great PR/idea. Couple of small things to get it in:
- Could you please add this to the
agents/src/extensionsdirectory? So the import would befrom agents.extensions import visualization - Could you please add an optional dependency group? So you can do
pip install openai-agents[visualization]to install it, and if you don't, there's an import error.
Thank you!
| import graphviz | ||
| import pytest | ||
|
|
||
| from src.agents.agent import Agent |
There was a problem hiding this comment.
| from src.agents.agent import Agent | |
| from agents import Agent |
…into feat/draw_graph
rm-openai
left a comment
There was a problem hiding this comment.
Looks like tests are failing. I think you can add an optional dependency to pyproject.toml
[project.optional-dependencies]
visualization=["graphviz"]
| # Bigger handoffs (rounded box, yellow) | ||
| for handoff in agent.handoffs: | ||
| parts.append( | ||
| f'"{handoff.name}" [label="{handoff.name}", shape=box, style=filled, style=rounded, ' |
There was a problem hiding this comment.
I think you want handoff.agent_name not handoff.name, if it's a Handoff instance
There was a problem hiding this comment.
Added isinstance check.
| f'"{handoff.name}" [label="{handoff.name}", shape=box, style=filled, style=rounded, ' | ||
| f"fillcolor=lightyellow, width=1.5, height=0.8];" | ||
| ) | ||
| parts.append(get_all_nodes(handoff)) |
There was a problem hiding this comment.
I don't think this is right - the handoffs list is list[Handoff | Agent]. So the node might be an Agent, but it might also be a Handoff object, where you don't statically know which agent is being handed off to. You can use handoff.agent_name for that
There was a problem hiding this comment.
Added isinstance check.
…proved handling of agents and handoffs
…nd improving type hints
rm-openai
left a comment
There was a problem hiding this comment.
THink you just need a rebase and should be good to go
| [project.optional-dependencies] | ||
| visualization = [ | ||
| "graphviz>=0.17", | ||
| ] | ||
|
|
There was a problem hiding this comment.
you might need a rebase, as [project.optional-dependencies] exists already. Also perhaps viz is a shorter optional dependency heh
There was a problem hiding this comment.
Yeah looks like this lack of rebase is causing all the checks to fail.
…into feat/draw_graph
…into feat/draw_graph
|
Oof unfortunately checks still failing. I tried to update them but you may need to run |
|
Ok, now it cannot fail. |
This pull request introduces functionality for visualizing agent structures using Graphviz. The changes include adding a new dependency, implementing functions to generate and draw graphs, and adding tests for these functions.
New functionality for visualizing agent structures:
graphvizas a new dependency inpyproject.toml.src/agents/visualizations.pyto generate and draw graphs for agents using Graphviz. These functions includeget_main_graph,get_all_nodes,get_all_edges, anddraw_graph.Testing the new visualization functionality:
tests/test_visualizations.pyto verify the correctness of the graph generation and drawing functions. The tests coverget_main_graph,get_all_nodes,get_all_edges, anddraw_graph.For example, given the following code:
Generates the following image: