Skip to content
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

feat: Add Graphviz-based agent visualization functionality #147

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

MartinEBravo
Copy link

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:

  • Added graphviz as a new dependency in pyproject.toml.
  • Implemented functions in src/agents/visualizations.py to generate and draw graphs for agents using Graphviz. These functions include get_main_graph, get_all_nodes, get_all_edges, and draw_graph.

Testing the new visualization functionality:

  • Added tests in tests/test_visualizations.py to verify the correctness of the graph generation and drawing functions. The tests cover get_main_graph, get_all_nodes, get_all_edges, and draw_graph.

For example, given the following code:

from agents import Agent, function_tool
from agents.visualizations import draw_graph


@function_tool
def get_weather(city: str) -> str:
    return f"The weather in {city} is sunny."


spanish_agent = Agent(
    name="Spanish agent",
    instructions="You only speak Spanish.",
)

english_agent = Agent(
    name="English agent",
    instructions="You only speak English",
)

triage_agent = Agent(
    name="Triage agent",
    instructions="Handoff to the appropriate agent based on the language of the request.",
    handoffs=[spanish_agent, english_agent],
    tools=[get_weather],
)


draw_graph(triage_agent)

Generates the following image:

Screenshot 2025-03-13 at 18 36 23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant