• Solan Sync
  • Posts
  • [Latest AI] What is AutoGen ?— Develop Robust AI Agents with ChatGPT/GPT-4

[Latest AI] What is AutoGen ?— Develop Robust AI Agents with ChatGPT/GPT-4

Discover AutoGen, a Microsoft library designed for creating LLM applications with agents that can communicate and assist in solving complex tasks.

We’ll start with an overview of AutoGen and its advantages. 

We’ll proceed with a simple example of creating a single agent to analyze trends in stock prices. Following that, we’ll move on to a more complex exercise, employing four agents to develop a cryptocurrency indicator that leverages historical price data and news for insights.

Why AutoGen ?

  • Dynamic Conversations: AutoGen enables agents to communicate with each other to tackle challenges, offering a more robust solution than a single LLM operating alone.

  • Tailored Solutions: You can customize agents for specific functions, select the LLM models to employ, define how participants join conversations, and integrate additional tools for enhanced performance.

  • Human Collaboration: AutoGen also incorporates human participation, allowing people to contribute ideas and feedback to assist the agents. AutoGen acts like a team of intelligent collaborators, pooling their efforts to solve problems, all built with insights from leading researchers.

Setup

You can install AutoGen with pipand some libraries:

pip install -Uqqq pip --progress-bar off
pip install -qqq pyautogen==0.1.10 --progress-bar off

import json
from getpass import getpass
 
import autogen
import pandas as pd
import requests
from autogen import AssistantAgent, UserProxyAgent
from IPython.display import Image

Next, you’ll need to input your OpenAI API key (obtain one from https://platform.openai.com/account/api-keys (this link opens in a new tab)):

OPENAI_API_KEY = getpass()

We’ll source news and historical prices for Bitcoin and Ethereum from Alpha Vantage. Obtain your API key at https://www.alphavantage.co/support/#api-key (this link opens in a new tab). 

Please enter it here:

ALPHA_VANTAGE_API_KEY = getpass()

Simple Agent

Let’s begin with a straightforward example. We’ll set up an agent to retrieve historical prices for Bitcoin, Ethereum, and Tesla stock, and then plot these prices.

First, we must configure our agent:

gpt_config_list = [
    {
        "model": "gpt-4", # or use "gpt-3.5-turbo"
        "api_key": OPENAI_API_KEY,
    }
]
 
llm_config = {"config_list": gpt_config_list, "use_cache": False, "temperature": 0}

The crucial steps involve choosing the model and entering the API key. For this example, we’ll use GPT-4. Alternatively, you could use GPT-3.5 Turbo (ChatGPT). Now, let’s proceed to create the agent:

assistant = AssistantAgent(
    name="assistant",
    llm_config=llm_config,
)

To initiate the conversation, we need an additional agent to act as the user (that’s you). We’ll employ the UserProxyAgent for this purpose:

def is_termination_msg(data):
    has_content = "content" in data and data["content"] is not None
    return has_content and "TERMINATE" in data["content"]
 
user_proxy = UserProxyAgent(
    name="user_proxy",
    human_input_mode="NEVER",
    max_consecutive_auto_reply=10,
    is_termination_msg=is_termination_msg,
    code_execution_config={"work_dir": "coding"},
)

We’ll utilize the is_termination_msg function to end the conversation whenever the agent includes "TERMINATE" in any part of the text. The code_execution_config will instruct the agent to store any assets (such as code, images, etc.) in the coding directory. Let's begin the conversation:

user_proxy.initiate_chat(
    assistant,
    message="What is the current year? Compare the year-to-date gain for BTC, ETH and TESLA.",
)

Here’s the closing message from the assistant:

assistant

Excellent! The code has successfully retrieved the data and generated the plot.
The plot is saved in a file called 'price_ytd.png' located in the current directory.
Please open the 'price_ytd.png' file to see the plot. 
It displays the year-to-date (YTD) price changes for BTC (Bitcoin), ETH (Ethereum), and TSLA (Tesla).
TERMINATE

Advanced Example: Multi-Agent System for Cryptocurrency Analysis

To leverage the full capability of AutoGen, multiple agents can be employed to develop a comprehensive cryptocurrency indicator:

  • Multiple Agents: Collaborate to analyze both historical price data and current news to derive trading insights.

  • Specialized Roles: Each agent can be tailored for specific aspects like data retrieval, analysis, market predictions, or news sentiment analysis.

This approach enhances the robustness and depth of the analysis, providing a solid foundation for informed trading decisions.

Opportunities and Business Ideas

Why Now?

  • Rapid growth in AI capabilities: The continuous advancements in AI and machine learning are creating new possibilities for financial analysis and decision-making.

  • Increasing relevance of real-time data analysis: In today’s fast-paced financial markets, the ability to quickly analyze and act on real-time data is crucial.

Business Ideas:

  1. AI-driven financial advisory: Utilize AutoGen to create personalized investment advice based on real-time market data.

  2. Automated trading system: Develop a system that uses AI agents to execute trades based on predictive analytics derived from multiple data sources.

  3. Market sentiment analysis tool: Build a tool that analyzes news and social media to gauge market sentiment, helping traders to make more informed decisions.

These ideas highlight the potential of AutoGen to transform data into actionable insights, providing a competitive edge in various markets.

Thank you for reading this article so far, you can also access the FREE Top 100 AI Tools List and the AI-Powered Business Ideas Guides on my FREE newsletter.

What Will You Get?

  • Access to AI-Powered Business Ideas.

  • Access our News Letters to get help along your journey.

  • Access to our Upcoming Premium Tools for free.

If you find this helpful, please consider buying me a cup of coffee.

✅ Stop paying subscription. Try Awesome AI Tools & Prompts with the Best Deals

🧰 Find the Best AI Content Creation jobs

⭐️ ChatGPT materials

💡 Bonus

🪄 Notion AI — If you are fan of Notion and solo-entrepreneur, Check this out.

If you’re a fan of notion this new Notion AI feature Q&A will be a total GameChanger for you.

After using notion for 3 years it has practically become my second brain it’s my favorite productivity app.

And I use it for managing almost all aspects of my day but my problem now with having so much stored on ocean is quickly referring back to things.

Let me show you how easy it is to use so you can ask it things like

“What is the status of my partnership” or “How many books have I read this year?” and this is unlike other AI tools because the model truly comprehends your notion workspace.

So if you want to boost your productivity this new year go check out Notion AI and some of the awesome new features Q&A!

Reply

or to participate.