A sophisticated multi-agent system for natural language business intelligence queries that generates SQL using Monte Carlo Tree Search (MCTS) algorithm without requiring RAG (Retrieval-Augmented Generation).
ChatBI is an intelligent BI system that transforms natural language queries into actionable business insights through a coordinated multi-agent workflow. The system uses advanced MCTS algorithms for SQL generation and orchestrates multiple specialized agents to deliver comprehensive business reports.
Planner Agent β SQL Agent β Coder Agent β Reporter Agent
- π― Planner Agent: Orchestrates the entire workflow, breaks down tasks, and coordinates agent execution
- ποΈ SQL Agent: Converts natural language to SQL using MCTS-based AlphaSQL algorithm
- π» Coder Agent: Implements data processing, analysis, and visualization solutions
- π Reporter Agent: Generates comprehensive BI reports with insights and recommendations
- π File Agent: Handles file operations (create, read, write, exists)
- π Browser Agent: Web browsing and content extraction capabilities
- π§ MCP Agent: Model Context Protocol integration for external tool access
- π Research Agent: Literature review and research synthesis (Research domain)
- No RAG required - direct natural language to SQL conversion
- MCTS algorithm ensures optimal query generation
- Supports complex business logic and multi-table joins
- Business Intelligence: Data querying, reporting, and visualization
- Research: Literature review and academic research synthesis
- Vision: Image analysis and optometry applications
- Automatic task decomposition and dependency management
- Parallel agent execution for efficiency
- Error handling and recovery mechanisms
- Snapshot-based state management
- Automated data visualization generation
- Statistical analysis and trend identification
- Business metrics interpretation
- Professional report generation
- Python 3.8+
- Docker (for sandboxed execution)
- OpenAI API key or compatible LLM endpoint
# Clone the repository
git clone <repository-url>
cd chatbi
# Install dependencies with poetry
poetry install
# Or with pip
pip install -r requirements.txt- Copy and configure the settings:
cp config.toml.example config.toml- Edit
config.tomlwith your LLM credentials:
[llm]
model = "gpt-4"
api_key = "your-api-key"
base_url = "https://api.openai.com/v1"
[agent.runtime]
parallel_nums = 3
retry = 3# Run the interactive CLI
python main.py --domain BI
# Or programmatically
from chatbi.agent.planner import PlannerAgent
from chatbi.llms.llm import LLM
from chatbi.config.configure import Configure
llm = LLM(Configure.config.llm.model, Configure.config.llm.api_key)
planner = PlannerAgent(llm=llm, domain="BI")
# Execute a BI query
result = await planner.process("Show me the total sales by region for Q4")"What's the percentage of users with guest role?"
"Show total revenue by product category this quarter"
"Create a visualization of user growth over time"
"Analyze customer churn rate by demographics"
"What do recent papers say about AI in education?"
"Find datasets about urban pollution"
"Research the latest developments in renewable energy"
The SQL generation uses a sophisticated MCTS approach:
- Divide: Decompose complex queries into sub-questions
- Conquer: Generate pseudo-SQL for each component
- Combine: Recursively assemble the complete query
- Validate: Execute and verify query correctness
Agents communicate through:
- Memory System: Persistent conversation history
- Dependency Management: Result passing between agents
- Tool Integration: Shared file system and execution environment
- Isolated Docker containers for safe code execution
- Automatic resource cleanup
- Cross-agent file sharing
chatbi/
βββ agent/ # Core agent implementations
β βββ base.py # Base agent class and interfaces
β βββ planner.py # Orchestration and planning
β βββ coder.py # Code generation and execution
β βββ reporter.py # Report generation
β βββ BI/ # Domain-specific agents
βββ alphasql/ # SQL generation engine
β βββ algorithm/mcts/ # MCTS implementation
β βββ prompt/ # SQL generation prompts
βββ llms/ # LLM integrations
βββ memory/ # Conversation persistence
βββ tool/ # Agent tools (file, bash, etc.)
βββ sandbox/ # Execution environments
βββ prompt/ # Agent system prompts
Extend the system with custom domain dialects:
class CustomDomainDialect(DomainDialect):
async def rewrite_goal(self, agent, goal):
# Transform goals for your domain
return transformed_goal
async def get_extra_system_rules(self):
# Add domain-specific rules
return additional_rulesAdd custom tools through MCP:
{
"name": "custom_tool",
"description": "Your tool description",
"parameters": {
"type": "object",
"properties": {
"param": {"type": "string"}
}
}
}# Run all tests
pytest
# Run specific agent tests
pytest tests/test_coder_agent.py
pytest tests/test_reporter_agent.py
# Run with coverage
pytest --cov=chatbiThe system tracks comprehensive metrics:
- Token usage and costs per agent
- Execution time per workflow step
- SQL query success rates
- Agent error rates and recovery