- unwind ai
- Posts
- Build a Multi-agent LLM app with GPT-4o
Build a Multi-agent LLM app with GPT-4o
Fully Functional LLM App in just 15 lines of Python Code (step-by-step instructions)
The tech world is evolving so fast that staying up-to-speed is overwhelming. How about multiple AI agents doing that research for you from the most dynamic yet cluttered source of top tech stories, Hacker News?
In this tutorial, we’ll show you how to build an AI-powered multi-agent researcher using Streamlit and AI agents to research top stories and users on HackerNews, generating blog posts, reports, and social media content, all autonomously and in just 15 lines of Python code.
🎁 $50 worth AI Bonus Content at the end!
What We’re Building
Our multi-agent AI researcher combines multiple AI agents working together to streamline HackerNews research. With this app, you can explore trending stories and popular users, as well as generate summaries and insights to create reports, blogs, or social media posts. This AI assistant uses:
Streamlit for an intuitive and engaging interface
Phidata to equip the AI assistant with memory and real-time knowledge
GPT-4o to analyze Hacker News data and generate insights
Automate content creation, including blogs and reports
Prerequisites
Before we begin, make sure you have:
Python installed on your machine (version 3.7 or higher is recommended)
Basic familiarity with Python programming
Your OpenAI API Key (or an alternative LLM provider’s API key)
A code editor of your choice (we recommend VSCode or PyCharm for their excellent Python support)
Step-by-Step Instructions
Step 1: Setting Up the Environment
First, let's get our development environment ready:
Clone the GitHub repository:
git clone https://github.com/Shubhamsaboo/awesome-llm-apps.git
Go to the multi_agent_researcher folder:
cd multi_agent_researcher
Install the required dependencies:
pip install -r requirements.txt
Get Your OpenAI API Key:
Sign up for an OpenAI account and generate an API key. You can also any other LLM of your choice.
Step 2: Creating the Streamlit App
Now that the environment is set, let’s create our Streamlit app. Create a new file named research_agent.py
and add the following code:
Import Required Libraries: At the top of your file, add:
import streamlit as st
from phi.assistant import Assistant
from phi.tools.hackernews import HackerNews
from phi.llm.openai import OpenAIChat
Set Up the Streamlit App: Define the structure of the Streamlit app by adding the following code:
st.title("Multi-Agent AI Researcher 🔍🤖")
st.caption("This app allows you to research top stories and users on HackerNews and write blogs, reports and social posts.")
Get OpenAI API Key from the User: Add an input field to accept the OpenAI API key from the user:
openai_api_key = st.text_input("OpenAI API Key", type="password")
Create the Assistant Instance: Create a text input for the user to enter OpenAI API. If the OpenAI API key is provided, create instances of Assistants: - HackerNews Story Researcher
- HackerNews User Researcher
- Combine the assistants into a team called "Hackernews Team"
if openai_api_key:
# Create instances of the Assistant
story_researcher = Assistant(
name="HackerNews Story Researcher",
role="Researches hackernews stories and users.",
tools=[HackerNews()],
)
user_researcher = Assistant(
name="HackerNews User Researcher",
role="Reads articles from URLs.",
tools=[HackerNews()],
)
hn_assistant = Assistant(
name="Hackernews Team",
team=[story_researcher, user_researcher],
llm=OpenAIChat(
model="gpt-4o",
max_tokens=1024,
temperature=0.5,
api_key=openai_api_key
)
)
Creating Input Fields for the Research Query: Add an input field where the user can enter a research query:
query = st.text_input("Enter your report query")
if query:
# Get the response from the assistant
response = hn_assistant.run(query, stream=False)
st.write(response)
Step 3: Running the App
With our code in place, it's time to launch the app and start comparing stocks.
Start the Streamlit App In your terminal, navigate to the project folder, and run the following command:
streamlit run research_agent.py
Access Your AI Assistant: Streamlit will provide a local URL (typically http://localhost:8501). Open this in your web browser and start comparing stocks by entering their symbols.
Working Application Demo
Conclusion
You’ve just built a multi-agent AI researcher that allows you to quickly gather insights from HackerNews. This app uses AI agents to research trending stories and popular users, providing you with actionable content in minutes.
Feel free to expand this project by adding more AI tools or integrating other data sources.
We share hands-on tutorials like this 2-3 times a week, to help you stay ahead in the world of AI. If you're serious about levelling up your AI skills and staying ahead of the curve, subscribe now and be the first to access our latest tutorials.
Reply