Full-featured AI agent app in less than 50 lines of Python code (step-by-step guide)
AI tools are changing the way entrepreneurs identify trends and make decisions, but building a scalable solution to analyze startup opportunities often requires integrating multiple data sources and processing them quickly. However, with advanced Large Language Models (LLMs) equipped with the right tools, this process can be automated to deliver actionable insights.
In this tutorial, we will guide you through the process of building a AI Entrepreneurial Trends Analytics Agent. This AI agent will analyze startup news, identify emerging trends, and validate startup ideas. It will use less than 50 lines of Python code, combined with Newspaper4k cap (a poem) DuckDuckGoand use Claude 3.5 Sonnet.
Key Features:
- User input: allows entrepreneurs to input specific entrepreneurial areas or technologies of interest
- News gathering: using @DuckDuckGo
Collect the latest startup news and market analysis
- Abstract generation: Use Newspaper4k to generate concise abstracts of validated information.
- Trend Analysis: Identifying Emerging Models of Venture Financing, Technology Adoption and Market Opportunities
- Front-end interface: @streamlit
Provide user-friendly interactive interface
The system architecture consists of three Agents:
- News gathering: responsible for searching and collecting relevant articles
- Summary writing: processing and summarizing article content
- Trend analysis: analyzing summaries and identifying trends
Realization Steps:
- Environment setup: including installing necessary dependencies and obtaining API keys
- Creating a Streamlit Application: Building the User Interface
- Implementing the functions of three Agents and combining them into a team
- Execute analytical workflows and present results
What we will build
The AI Startup Trend Analysis Agent is a tool designed for emerging entrepreneurs to generate actionable insights by identifying incipient trends, potential market gaps, and growth opportunities in specific sectors. It combines Newspaper4k and DuckDuckGo to scan and analyze startup-centric articles and market data. With Claude 3.5 Sonnet, it processes this information to extract emerging patterns and help entrepreneurs identify promising startup opportunities.
functionality
- user prompt: Entrepreneurs can enter specific entrepreneurial areas or technologies of interest for research.
- News Collection: The agency collects recent startup news, funding updates, and market analysis via DuckDuckGo.
- Abstract Generation: Use Newspaper4k to generate concise summaries of verified information.
- Trend analysis: Systematically identify trends in startup financing, technology adoption, and market opportunities, and analyze related stories.
- Streamlit Interface: The application utilizes a user-friendly interface built with Streamlit for easy interaction.
pre-conditions
Before we begin, please make sure you have the following in place:
- Install Python on your computer (3.7 or higher recommended)
- possession Anthropic API key
- Basic understanding of Python programming
- Use your favorite code editor (we recommend VS Code or PyCharm, which have excellent Python support)
Step-by-step instructions
Setting up the development environment
First, let's prepare the development environment:
- Clone a GitHub repository:
git clone https://github.com/Shubhamsaboo/awesome-llm-apps.git
- go into ai_startup_trend_analysis_agent Folder:
cd ai_agent_tutorials/ai_startup_trend_analysis_agent
- mounting Required dependencies::
pip install -r requirements.txt
- Get your API key: Register Anthropic account and get your API key.
Creating a Streamlit Application
Let's create the application. New file startup_trends_agent.py
, and add the following code:
- Import the necessary libraries:
- Streamlit for building web applications
- for building AI agents and tools Phidata
- Large Language Model Claude Sonnet 3.5
- DuckDuckGo for search
- Newspaper4k for article processing
import streamlit as st
from phi.agent import Agent
from phi.tools.duckduckgo import DuckDuckGo
from phi.model.anthropic import Claude
from phi.tools.newspaper4k import Newspaper4k
from phi.tools.import Tool
import logging
- Create a Streamlit application:
- Simple and clear interface
- Secure API key entry
- Theme-based analysis
# Setting up the Streamlit app
st.title("AI Startup Trend Analysis Assistant 📈")
st.caption("Get the latest trend analysis and startup opportunities based on your topics of interest with just one click.")
topic = st.text_input("Enter the startup area you are interested in:")
anthropic_api_key = st.sidebar.text_input("Enter Anthropic API key", type="password")
if st.button("Generate Analysis"):: if not anthropic_api_key = st.sidebar.text_input("Enter Anthropic API key", type="password")
if not anthropic_api_key.
st.warning("Please enter the required API key.")
else: with st.spinner
with st.spinner("Processing your request...") :: try: with st.spinner("Your request is being processed...")
try: # Initialization
# Initializing the Anthropic model
anthropic_model = Claude(id = "claude-3-5-sonnet-20240620",api_key=anthropic_api_key)
- Create a newsgathering agent:
- Searching with DuckDuckGo
- Collection of latest articles
- Limit to 5 results to maintain focus
# Defining News Gathering Agents - The DuckDuckGo search tool enables agents to search for information from the web.
search_tool = DuckDuckGo(search=True, news=True, fixed_max_results=5)
news_collector = Agent(
name="news_collector",
role="Collects the latest news articles on a given topic",
tools=[search_tool],
model=anthropic_model,
instructions=["Gather the latest articles on the topic"],
show_tool_calls=True,
markdown=True, )
)
- Add a summary generation agent:
- Processing of article content
- Creating succinct summaries
- Retention of key information
# Define the summary generation agent
news_tool = Newspaper4k(read_article=True, include_summary=True)
summary_writer = Agent(
name="Summary Generator", role="Generate a summary for a collection of articles.
role="Generate a summary for collected news articles",
tools=[news_tool],
model=anthropic_model,
instructions=["Provide a succinct summary of the article"],
show_tool_calls=True,
markdown=True, )
)
- Create a trend analysis agent:
- Analysis of the content of the summary
- Identifying trends
- Tapping into entrepreneurial opportunities
# Defining the Trend Analyzer Agent
trend_analyzer = Agent(
name="Trend Analyzer",
role="Analyze trends from summaries",
model=anthropic_model,
instructions=["Identify Emerging Trends and Potential Entrepreneurial Opportunities"],
show_tool_calls=True,
markdown=True,
)
- Combine agents into teams:
- Harmonization of workflows
- Ensuring data flows
- Maintaining Contextual Consistency
Multi-agent team setup for # Phidata:
agent_team = Agent(
agents=[news_collector, summary_writer, trend_analyzer],
instructions=[
"First, use DuckDuckGo to search for the latest news articles related to the topic specified by the user." ,
"Then, provide the collected article links to the summary generator." ,
"Important: It is important to ensure that the summary generator receives all article links for reading." ,
"Next, the summary generator will read the articles and prepare a concise summary for each article." ,
"After summarizing, the summaries will be passed to the Trend Analyzer." ,
"Finally, the Trend Analyzer will identify emerging trends and potential entrepreneurial opportunities based on the summaries provided and deliver them in a detailed report, making it easy for any young entrepreneur to capture great value."
],.
show_tool_calls=True,
markdown=True.
)
- Execute the analytics workflow:
- sequential processing
- Ensuring data flows
- Show results
# Step 1: Gather news
news_response = news_collector.run(f "Collect the latest news about {topic}")
articles = news_response.content
# Step 2: Summarize the articles
summary_response = summary_writer.run(f "Summarize the following articles:\n{articles}")
summaries = summary_response.content
# Step 3: Analyzing Trends
trend_response = trend_analyzer.run(f "Analyze the trend from the following summaries: \n{summaries}")
analysis = trend_response.content
# Display results - if further use is required, the following two lines can be uncommented to get the summaries!
# st.subheader("news summary")
# # st.write(summaries)
st.subheader("Trend analysis and potential startup opportunities")
st.write(analysis)
except Exception as e.
st.error(f "An error occurred: {e}")
else: st.error(f "An error occurred: {e}")
st.info("Enter the topic and API key, then click "Generate Analysis" to get started.")
Running the application
Once the code is ready, launch the application.
- In the terminal, navigate to the project folder and run the following command:
streamlit run startup_trends_agent.py
- Streamlit will provide a local URL (usually http://localhost:8501). Open it in your browser, enter your API key, select the area you want to explore, and watch your AI agent do the research for you.
Demonstration of working applications
summarize
In less than 50 lines of code, your AI agent is ready to provide entrepreneurs with actionable insights for trend analysis.
In order to further enhance the functionality, the following aspects can be considered:
- visualization: Trends are presented graphically to make the model clearer and more actionable.
- data filtering: Add advanced filters for users to refine insights based on geographic location, funding size, or technology type.
- coordination: Enable sharing and team discussion features within the app to facilitate deeper utilization of insights.
Continuously experiment and improve to build smarter AI solutions!