Rushab's Data World

Building AI Agents With Autogen

17 Aug 2024

In the rapidly evolving landscape of artificial intelligence, AI autonomous agents are emerging as a game-changing technology, capable of automating entire workloads. Among the frameworks simplifying the creation and deployment of these agents, Autogen stands out as an impressive solution.

AutoGen is an open-source framework that harnesses the power of multiple AI agents to facilitate complex workflows. What sets AutoGen apart is its execution capability – it can not only produce code output but also run it autonomously. This unique feature allows for the integration of self-sufficient agents that can create, execute, and even self-correct code to achieve effective results. By combining these capabilities, AutoGen opens up new possibilities for creating sophisticated, adaptable AI systems that can tackle a wide range of tasks with minimal human intervention.

In this blog post, we’ll explore how to use Autogen Studio to build a YouTube agent that can generate responses and answer questions based on video transcripts.

Link to Github

Getting Started with Autogen Studio UI

Autogen Studio UI provides an intuitive interface for creating and testing agents. Here’s how to get started:

  1. Create a new project in your IDE.
  2. Set up a virtual environment, using Python 3.11.
  3. Install Autogen Studio using pip: pip install autogenstudio
  4. Run the command autogenstudio ui -port 8080 in your terminal.
  5. Access the interface by clicking on the link provided in the terminal.

Autogen AI Playground
Autogen Studio Playground

Building a Workflow

The Autogen Studio UI is divided into two main sections: Build (for creating agents) and Playground (for interacting with workflows). The Build section is further divided into four key components:

1. Skills

Skills define what your agent can do. For our YouTube agent, we created a function that allows the agent to fetch and process YouTube video transcripts, as well as a function that allows the agent to generate a markdown file. Both functions were crafted in the same format as the skills provided.

Autogen AI skill
Skill UI

2. Model

This section specifies the Large Language Model (LLM) to use. We chose the open-source model Llama 3.1, available through the Groq API. The configuration is as follows:

  • Model: llama-3.1-70b-versatile
  • API Key: [Your Groq API key]
  • Base URL: https://api.groq.com/openai/v1

Autogen AI model
Model UI

3. Agents

Here, we configure the agent that will be used in our workflow. We used the default parameters:

  • Max Consecutive Autoreply: 25
  • Human Input Mode: Never
  • System Message: Default message providing instructions for generating and executing Python code to achieve specified objectives.

We also specified the model and skills to be used as defined in the previous steps.

Autogen AI agent
Agent UI

4. Workflows

In this section, we create an autonomous workflow. We set the initiator as the User Proxy and the receiver as the Agent we created.

Autogen AI workflow
Workflow UI

Deploying the Workflow

Once the workflow is ready, it can be exported as a JSON file and used in a Python script with just a few lines of code:

from autogenstudio import WorkflowManager

# Load workflow from exported JSON workflow file
workflow_manager = WorkflowManager(workflow="path/to/your/workflow_.json")

# Run the workflow on a task
workflow_manager.run(message="Write a blog based on [YOUTUBE LINK] and save the result in a markdown file")

Autogen Studio automatically caches the query, storing all the skills and functions used in the work_dir. These can be reused or added to the Agent as skills in future projects.

Autogen cache
cache

When the Python file is executed, the process carried out by the autonomous agents, along with their thoughts, is documented and can be viewed in the terminal as demonstrated below.

Run 1
Agents in Action
Run 2
Result

Conclusion

Autogen AI provides a powerful and user-friendly framework for building AI agents. By following the steps outlined in this blog post, you can create a YouTube video analyzer that can generate responses and answer questions based on video transcripts. This is just one example of the many possibilities that Autogen opens up for developers and AI enthusiasts.

As AI continues to advance, tools like Autogen will play a crucial role in democratizing access to sophisticated AI capabilities, enabling more people to create intelligent agents for a wide range of applications. Whether you’re a seasoned AI developer or just starting your journey, Autogen offers an exciting platform to explore the potential of autonomous AI agents.