BettaFish: The Revolutionary Multi-Agent Sentiment Analysis System That's Transforming Public Opinion Monitoring
A step-by-step technical tutorial on BettaFish, the open-source multi-agent sentiment analysis system. Covers introduction, architecture, setup, usage, and real-world applications.
Introduction: Breaking Through Information Echo Chambers
In today's digital landscape, understanding public sentiment has become crucial for businesses, researchers, and decision-makers. BettaFish (微舆) emerges as a groundbreaking multi-agent sentiment analysis system that promises to "break information echo chambers, restore the true nature of public opinion, predict future trends, and assist decision-making."
With over 13,600+ GitHub stars and active development, BettaFish represents a significant advancement in AI-powered sentiment analysis, offering capabilities that go far beyond traditional monitoring tools.
What Makes BettaFish Revolutionary?
BettaFish stands out from conventional sentiment analysis tools through six key innovations:
1. AI-Driven Comprehensive Monitoring
The system deploys AI crawler clusters that operate 24/7, covering 30+ mainstream social media platforms including Weibo, Xiaohongshu (Little Red Book), Douyin, Kuaishou, and international platforms. It doesn't just capture trending content—it dives deep into millions of user comments to capture authentic public voices.
2. Composite Analysis Engine Beyond LLMs
Rather than relying solely on large language models, BettaFish integrates five specialized professional agents with fine-tuned models and statistical middleware. This multi-model collaborative approach ensures analysis depth, accuracy, and multi-dimensional perspectives.
3. Powerful Multimodal Capabilities
The system transcends text limitations by analyzing video content from platforms like Douyin and Kuaishou, while precisely extracting structured multimodal information cards (weather, calendar, stock data) from modern search engines.
4. Agent "Forum" Collaboration Mechanism
BettaFish assigns unique toolsets and thinking patterns to different agents, introducing a debate moderator model that facilitates "forum-style" chain-of-thought discussions. This prevents single-model limitations and homogenization, fostering higher-quality collective intelligence.
5. Seamless Public-Private Data Integration
The platform analyzes public sentiment while providing secure interfaces for integrating internal business databases, breaking down data silos for comprehensive "external trends + internal insights" analysis.
6. Lightweight and Highly Extensible Framework
Built with pure Python modular design, BettaFish offers lightweight, one-click deployment with clear code structure that allows developers to easily integrate custom models and business logic.
System Architecture: A Multi-Agent Ecosystem
BettaFish employs a sophisticated four-agent architecture, each specialized for different aspects of sentiment analysis:
Core Agents
- Insight Agent: Private database mining for deep sentiment data analysis
- Media Agent: Multimodal content analysis with advanced multimedia processing capabilities
- Query Agent: Precise information search with domestic and international web search capabilities
- Report Agent: Intelligent report generation with built-in templates and multi-round generation
Complete Analysis Workflow
A typical BettaFish analysis follows this comprehensive process:
- User Query: Flask main application receives the analysis request
- Parallel Startup: Three agents begin working simultaneously
- Initial Analysis: Each agent uses specialized tools for overview searching
- Strategy Development: Agents develop segmented research strategies based on initial results
- Iterative Forum Collaboration: Multiple rounds of deep research guided by forum moderator
- Result Integration: Report Agent collects all analysis results and forum content
- Report Generation: Dynamic template selection and multi-round final report generation
Getting Started: Installation and Setup
System Requirements
- Operating System: Windows, Linux, or macOS
- Python Version: 3.9 or higher
- Package Manager: Conda (Anaconda/Miniconda) or uv
- Database: MySQL (local or cloud service)
- Memory: Minimum 2GB RAM recommended
Step 1: Environment Setup
Create a Python environment using Conda:
# Create conda environment
conda create -n bettafish python=3.11
conda activate bettafishOr using uv for faster package management:
# Create uv environment
uv venv --python 3.11Step 2: Clone and Install Dependencies
# Clone the repository
git clone https://github.com/666ghj/BettaFish.git
cd BettaFish
# Install dependencies
pip install -r requirements.txt
# Or using uv for faster installation
uv pip install -r requirements.txtStep 3: Install Playwright Browser Drivers
# Install browser drivers for web scraping
playwright install chromiumStep 4: Configuration Setup
Copy the example environment file and configure your settings:
# Copy environment template
cp .env.example .envEdit the .env file with your configuration:
# MySQL Database Configuration
DB_HOST = "localhost"
DB_PORT = 3306
DB_USER = "your_username"
DB_PASSWORD = "your_password"
DB_NAME = "your_db_name"
DB_CHARSET = "utf8mb4"
# LLM Configuration (OpenAI-compatible APIs)
# Insight Agent
INSIGHT_ENGINE_API_KEY = "your_api_key"
INSIGHT_ENGINE_BASE_URL = "https://api.moonshot.cn/v1"
INSIGHT_ENGINE_MODEL_NAME = "kimi-k2-0711-preview"
# Media Agent
MEDIA_ENGINE_API_KEY = "your_api_key"
MEDIA_ENGINE_BASE_URL = "https://api.openai.com/v1"
MEDIA_ENGINE_MODEL_NAME = "gpt-4"
# Query Agent
QUERY_ENGINE_API_KEY = "your_api_key"
QUERY_ENGINE_BASE_URL = "https://api.anthropic.com/v1"
QUERY_ENGINE_MODEL_NAME = "claude-3-sonnet"
# Report Agent
REPORT_ENGINE_API_KEY = "your_api_key"
REPORT_ENGINE_BASE_URL = "https://api.openai.com/v1"
REPORT_ENGINE_MODEL_NAME = "gpt-4"Step 5: Database Initialization
Initialize the local database:
# Navigate to MindSpider directory
cd MindSpider
# Initialize the project
python main.py --setupLaunching BettaFish: Multiple Deployment Options
Complete System Launch (Recommended)
# Activate your environment
conda activate bettafish
# Launch the main application
python app.pyAccess the complete system at http://localhost:5000
Individual Agent Launch
You can also run individual agents for specific tasks:
# Launch Query Engine
streamlit run SingleEngineApp/query_engine_streamlit_app.py --server.port 8503
# Launch Media Engine
streamlit run SingleEngineApp/media_engine_streamlit_app.py --server.port 8502
# Launch Insight Engine
streamlit run SingleEngineApp/insight_engine_streamlit_app.py --server.port 8501Web Scraping System
The MindSpider crawler system can be used independently:
# Navigate to crawler directory
cd MindSpider
# Run topic extraction (get trending news and keywords)
python main.py --broad-topic
# Run complete crawler workflow
python main.py --complete --date 2024-01-20
# Run deep sentiment crawling for specific platforms
python main.py --deep-sentiment --platforms xhs dy wbAdvanced Configuration and Customization
Integrating Different LLM Models
BettaFish supports any OpenAI-compatible API. Here's an example of integrating different providers:
from openai import OpenAI
# Example: Using SiliconFlow API
client = OpenAI(
api_key="your_api_key",
base_url="https://api.siliconflow.cn/v1"
)
response = client.chat.completions.create(
model="Qwen/Qwen2.5-72B-Instruct",
messages=[
{'role': 'user', 'content': "Analyze market opportunities for reasoning models"}
],
)
complete_response = response.choices[0].message.content
print(complete_response)Custom Sentiment Analysis Models
BettaFish includes multiple sentiment analysis approaches:
1. Multilingual Sentiment Analysis
cd SentimentAnalysisModel/WeiboMultilingualSentiment
python predict.py --text "This product is amazing!" --lang "en"2. Fine-tuned Qwen3 Model
cd SentimentAnalysisModel/WeiboSentiment_SmallQwen
python predict_universal.py --text "这次活动办得很成功"3. BERT-based Fine-tuned Model
cd SentimentAnalysisModel/WeiboSentiment_Finetuned/BertChinese-Lora
python predict.py --text "这个产品真的很不错"Custom Business Database Integration
Integrate your business data with BettaFish:
# InsightEngine/tools/custom_db_tool.py
class CustomBusinessDBTool:
"""Custom business database query tool"""
def __init__(self):
self.connection_config = {
'host': config.BUSINESS_DB_HOST,
'port': config.BUSINESS_DB_PORT,
'user': config.BUSINESS_DB_USER,
'password': config.BUSINESS_DB_PASSWORD,
'database': config.BUSINESS_DB_NAME,
}
def search_business_data(self, query: str, table: str):
"""Query business data"""
# Implement your business logic
pass
def get_customer_feedback(self, product_id: str):
"""Get customer feedback data"""
# Implement customer feedback query logic
passReal-World Applications and Use Cases
Brand Reputation Monitoring
BettaFish excels at comprehensive brand sentiment analysis. For example, a complete analysis of "Wuhan University reputation" demonstrates the system's capability to:
- Monitor mentions across 30+ social media platforms
- Analyze sentiment trends over time
- Identify key opinion leaders and influencers
- Generate actionable insights for reputation management
Crisis Management and Early Warning
The system's predictive capabilities make it valuable for:
- Early detection of potential PR crises
- Monitoring competitor sentiment
- Tracking industry trends and public opinion shifts
- Government policy impact assessment
Market Research and Consumer Insights
Businesses can leverage BettaFish for:
- Product launch sentiment tracking
- Customer satisfaction analysis
- Market positioning research
- Competitive intelligence gathering
Docker Deployment for Production
For production environments, BettaFish supports Docker deployment:
# docker-compose.yml
version: '3.8'
services:
bettafish:
build: .
ports:
- "5000:5000"
environment:
- DB_HOST=mysql
- DB_USER=root
- DB_PASSWORD=password
depends_on:
- mysql
mysql:
image: mysql:8.0
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=bettafish
volumes:
- mysql_data:/var/lib/mysql
volumes:
mysql_data:# Deploy with Docker Compose
docker-compose up -dPerformance Optimization and Scaling
Configuration Tuning
Optimize performance by adjusting key parameters:
# QueryEngine/utils/config.py
class Config:
max_reflections = 2 # Reflection rounds
max_search_results = 15 # Maximum search results
max_content_length = 8000 # Maximum content length
# MediaEngine/utils/config.py
class Config:
comprehensive_search_limit = 10 # Comprehensive search limit
web_search_limit = 15 # Web search limit
# InsightEngine/utils/config.py
class Config:
default_search_topic_globally_limit = 200 # Global search limit
default_get_comments_limit = 500 # Comment retrieval limit
max_search_results_for_llm = 50 # Max results for LLMSentiment Analysis Model Configuration
# InsightEngine/tools/sentiment_analyzer.py
SENTIMENT_CONFIG = {
'model_type': 'multilingual', # Options: 'bert', 'multilingual', 'qwen'
'confidence_threshold': 0.8, # Confidence threshold
'batch_size': 32, # Batch processing size
'max_sequence_length': 512, # Maximum sequence length
}Future Development and Roadmap
The BettaFish team has ambitious plans for the platform's evolution:
Predictive Analytics Enhancement
Currently, BettaFish completes two of the "three axes" of sentiment analysis: input requirements and detailed analysis. The missing piece is prediction capability. The development team is working on:
- Time Series Models: For trend prediction based on historical data
- Graph Neural Networks: For understanding relationship dynamics
- Multimodal Fusion: Combining text, image, and video signals for prediction
- Real-time Trend Analysis: Leveraging extensive topic heat data collected over time
Beyond Sentiment Analysis
The ultimate goal is to transform BettaFish into a universal data analysis engine that can drive various business scenarios. With simple modifications to agent toolsets and prompts, the system can become:
- Financial market analysis systems
- Healthcare trend monitoring
- Educational sentiment tracking
- Political opinion analysis
Community and Contribution
Getting Involved
BettaFish welcomes contributions from the community:
- GitHub Repository: https://github.com/666ghj/BettaFish
- Issue Reporting: Use GitHub Issues for bug reports and feature requests
- Discussions: Join community discussions for support and ideas
- Pull Requests: Contribute code improvements and new features
Development Guidelines
- Follow PEP8 coding standards
- Include comprehensive tests for new features
- Update documentation for changes
- Use clear commit messages in English or Chinese
Conclusion: The Future of Sentiment Analysis
BettaFish represents a significant leap forward in sentiment analysis technology. By combining multi-agent architecture, advanced AI capabilities, and comprehensive data integration, it offers unprecedented insights into public opinion and market sentiment.
Whether you're a researcher studying social trends, a business monitoring brand reputation, or a developer building the next generation of AI applications, BettaFish provides the tools and framework to break through information echo chambers and gain genuine insights into public sentiment.
The project's commitment to open-source development, combined with its modular architecture and extensive customization options, makes it an ideal platform for both learning and production deployment.
Ready to transform your approach to sentiment analysis? Start with BettaFish today and join the growing community of developers and researchers pushing the boundaries of AI-powered public opinion monitoring.
For more expert insights and tutorials on AI and automation, visit us at decisioncrafters.com.