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

Visualizing AutoGen workflow #39

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft

Visualizing AutoGen workflow #39

wants to merge 15 commits into from

Conversation

marklysze
Copy link
Collaborator

@marklysze marklysze commented Sep 12, 2024

-- Draft PR --

Creates a visual diagram of an AutoGen workflow! Check the flow between agents, LLM calls, function calls.

This is a starting point and your feedback, contributions, and testing are needed! Recreating a workflow from logs isn't always straightforward... :)

The proposed technical approach is:

  • Use existing AutoGen logging mechanism as the source to build the diagram
  • Utilise GraphViz's diagram building capability. More info on GraphViz.
  • Create an output to SVG (or a more interactive format that allows you to view underlying data)

Steps:

  • Add additional logging points to help give necessary detail (such as when in a nested chat, when in group chat select speaker, max turns reached, etc.)
  • Add new tool/package/contrib that creates the visualisation. It will be a sub-package referenced as autogen.visualize and will be installed as an optional dependency pip install autogen[visualize].

Work to do:

  • Add new logging events (this PR, done some)
  • Add support for file logging (this PR, done)
  • Add new tool/package/contrib for the actual visualisation logic (this PR, done some)
  • Tests (this PR, not started)
  • Documentation, examples, installation guide (basic guide in this PR)

Future (not this PR):

  • Add support for SQLite logger
  • Documentation / Blog

How to run it:

  • You will need to install GraphViz twice - install GraphViz for your OS (see here and also install the Python package pip install graphviz. You need both.
  • Load this branch

Code examples:

# Create a diagram from an existing log file, saved file as: autogen_logs/test_output.svg

from autogen.visualize import Visualize
visualisation = Visualize("./autogen_logs/20240912_224640_runtime_async_function_call.log")
visualisation.create_svg("autogen_logs/test_output.svg")
# Create a diagram from a file logger object, saved file as: autogen_logs/my_diagram.svg

from autogen import ConversableAgent, UserProxyAgent
import datetime
import autogen.runtime_logging
from autogen.visualize import Visualize

altmodel_llm_config = {
    "config_list":
    [
        {
            "api_type": "ollama",
            "model": "llama3.1:8b-instruct-q8_0",
            "client_host": "http://192.168.0.1:11434",
            "cache_seed": None,
        }
    ]
}

timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"{timestamp}_runtime_simple_chat.log"

# Start logging with logger_type and the filename to log to
logging_session_id = autogen.runtime_logging.start(logger_type="file", config={"filename": filename})
print("Logging session ID: " + str(logging_session_id))

# Create the agent that uses the LLM.
assistant = ConversableAgent("agent", llm_config=altmodel_llm_config)

# Create the agent that represents the user in the conversation.
user_proxy = UserProxyAgent("user", code_execution_config=False)

# Let the assistant start the conversation.  It will end when the user types exit.
assistant.initiate_chat(user_proxy, message="How can I help you today?")

autogen.runtime_logging.stop()

visualisation = Visualize(autogen.runtime_logging.autogen_logger) # Uses logger object
visualisation.create_svg("autogen_logs/my_diagram.svg", True)

Note: In VSCode if you preview the SVG diagram you should be able to hover over any bold text and it will show you the message/content.

What does it look like so far

Screenshot from 2024-09-13 09-27-25
Screenshot from 2024-09-13 09-41-17

CC for help @Hk669

Why are these changes needed?

Helps developers understand how AutoGen works under the hood. Testing / Production, helps understand running workflows.

Checks

@Hk669
Copy link
Collaborator

Hk669 commented Sep 13, 2024

@marklysze this looks perfect, let me try to help. thanks for the efforts on making this better.

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.

2 participants