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
# 设置 Streamlit 应用
st.title("AI 创业趋势分析助手 📈")
st.caption("只需点击一下,获取基于您感兴趣主题的最新趋势分析和创业机会。")
topic = st.text_input("输入您感兴趣的创业领域:")
anthropic_api_key = st.sidebar.text_input("输入 Anthropic API 密钥", type="password")
if st.button("生成分析"):
if not anthropic_api_key:
st.warning("请输入必需的 API 密钥。")
else:
with st.spinner("正在处理您的请求..."):
try:
# 初始化 Anthropic 模型
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
# 定义新闻收集代理 - DuckDuckGo 搜索工具使代理能够从网上搜索信息。
search_tool = DuckDuckGo(search=True, news=True, fixed_max_results=5)
news_collector = Agent(
name="新闻收集器",
role="收集关于指定主题的最新新闻文章",
tools=[search_tool],
model=anthropic_model,
instructions=["收集该主题的最新文章"],
show_tool_calls=True,
markdown=True,
)
- Add a summary generation agent:
- Processing of article content
- Creating succinct summaries
- Retention of key information
# 定义摘要生成代理
news_tool = Newspaper4k(read_article=True, include_summary=True)
summary_writer = Agent(
name="摘要生成器",
role="为收集到的新闻文章生成摘要",
tools=[news_tool],
model=anthropic_model,
instructions=["提供文章的简洁摘要"],
show_tool_calls=True,
markdown=True,
)
- Create a trend analysis agent:
- Analysis of the content of the summary
- Identifying trends
- Tapping into entrepreneurial opportunities
# 定义趋势分析代理
trend_analyzer = Agent(
name="趋势分析器",
role="从摘要中分析趋势",
model=anthropic_model,
instructions=["识别新兴趋势和潜在创业机会"],
show_tool_calls=True,
markdown=True,
)
- Combine agents into teams:
- Harmonization of workflows
- Ensuring data flows
- Maintaining Contextual Consistency
# Phidata 的多代理团队设置:
agent_team = Agent(
agents=[news_collector, summary_writer, trend_analyzer],
instructions=[
"首先,使用 DuckDuckGo 搜索与用户指定主题相关的最新新闻文章。",
"然后,将收集到的文章链接提供给摘要生成器。",
"重要提示:必须确保摘要生成器接收到所有文章链接以供阅读。",
"接下来,摘要生成器将阅读文章并为每篇文章准备简洁的摘要。",
"总结后,摘要将被传递给趋势分析器。",
"最后,趋势分析器将根据提供的摘要,识别新兴趋势和潜在创业机会,并以详细报告形式提供,让任何年轻企业家都能轻松获取巨大价值。"
],
show_tool_calls=True,
markdown=True,
)
- Execute the analytics workflow:
- sequential processing
- Ensuring data flows
- Show results
# 步骤 1:收集新闻
news_response = news_collector.run(f"收集关于 {topic} 的最新新闻")
articles = news_response.content
# 步骤 2:总结文章
summary_response = summary_writer.run(f"总结以下文章:\n{articles}")
summaries = summary_response.content
# 步骤 3:分析趋势
trend_response = trend_analyzer.run(f"从以下摘要中分析趋势:\n{summaries}")
analysis = trend_response.content
# 显示结果 - 如果需要进一步使用,可以取消注释以下两行以获取摘要!
# st.subheader("新闻摘要")
# # st.write(summaries)
st.subheader("趋势分析和潜在创业机会")
st.write(analysis)
except Exception as e:
st.error(f"发生错误:{e}")
else:
st.info("输入主题和 API 密钥,然后点击“生成分析”以开始。")
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!