A sophisticated FastAPI backend powering real-time AI chat with Stacks blockchain DAO management capabilities.
aibtcdev-backend provides real-time chat functionality with AI agents, comprehensive DAO proposal management, DEX trading integration, agent account operations, and blockchain event processing for the Stacks ecosystem.
- Background
- Features
- Architecture
- Quick Start
- Documentation
- Usage Examples
- Maintainers
- Contributing
- License
aibtcdev-backend bridges AI capabilities with Stacks blockchain technology to create intelligent DAO management experiences. The system provides real-time communication with AI agents that can autonomously interact with DAOs, create and evaluate proposals, execute trades, and manage blockchain accounts.
The platform is designed with a dual-mode architecture:
- Web Server Mode: Handles API requests and real-time WebSocket connections
- Worker Mode: Runs background services including job processing and bot integrations
- Proposal Creation: Automated DAO action proposal generation with AI-enhanced metadata
- Voting Operations: Create, vote on, and veto DAO proposals
- Agent Accounts: Manage agent accounts for autonomous DAO participation
- Contract Approval: Enable agent accounts to interact with specific contracts
- DEX Integration: Automated token purchases on Faktory DEX
- Wallet Management: Multi-network wallet support (mainnet/testnet)
- Faucet Integration: Testnet STX and sBTC token funding
- Slippage Control: Configurable slippage tolerance for trades
- Proposal Recommendations: Generate contextual proposal suggestions based on DAO history
- Comprehensive Evaluation: Multi-faceted AI analysis of proposals with custom prompts
- Metadata Generation: Automatic title, summary, and tag generation for proposals
- Stacks Network: Native support for Stacks blockchain operations
- Transaction Processing: Automated transaction creation and broadcasting
- Event Processing: Webhook-based blockchain event handling
- Multi-Network: Support for both testnet and mainnet configurations
- Tool Discovery: Dynamic tool registration and discovery system
- Multiple Auth: Bearer tokens, API keys, and query parameter authentication
- Social Integration: Twitter/X embedding with CORS proxy support
- Comprehensive API: RESTful endpoints for all operations
Web Server Mode (main.py
):
- FastAPI application with CORS configuration
- WebSocket endpoint for real-time chat (
/chat/ws
) - RESTful API endpoints for tools and webhooks
- Health monitoring and status endpoints
Worker Mode (worker.py
):
- Background job processing and execution
- Telegram bot integration (when enabled)
- System metrics monitoring and alerting
- Standalone service operations
graph TD
A["Frontend/External Services"] --> B["FastAPI Router"]
B --> C["Auth Layer"]
C --> D["Service Layer"]
D --> E["Backend Layer"]
style A fill:#e1f5fe
style B fill:#f3e5f5
style C fill:#fff3e0
style D fill:#e8f5e8
style E fill:#fce4ec
- Python 3.13
- UV (modern Python package manager)
- Bun (for TypeScript tools)
- Git with submodule support
# Clone repository with submodules
git clone <repository-url>
cd aibtcdev-backend
git submodule init && git submodule update --remote
# Install UV (if needed)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Setup environment
uv sync
source .venv/bin/activate
# Configure environment
cp .env.example .env
# Edit .env with your settings
# Install TypeScript tools
cd agent-tools-ts/ && bun install && cd ..
Web Server Mode:
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
Worker Mode:
python -m app.worker
Access the application:
- API:
http://localhost:8000
- Documentation:
http://localhost:8000/docs
- Health Check:
http://localhost:8000/
Comprehensive documentation is available in the docs/
directory:
- API Overview: Complete API endpoint reference
- Authentication: Authentication methods and security
- Configuration: Environment setup and configuration
- Development: Development setup and contribution guide
- CLI Usage: Command-line interface guide for task management
- Supabase Deployments: Automated database migration deployment setup
- API Endpoints: See API Overview for complete endpoint list
- Authentication: See Authentication for auth methods
- Environment Setup: See Configuration for all settings
- CLI Commands: See CLI Usage for task running instructions
const ws = new WebSocket('ws://localhost:8000/chat/ws?token=your_token');
ws.send(JSON.stringify({
type: 'message',
thread_id: 'thread-uuid',
content: 'Hello, AI agent!'
}));
curl -H "Authorization: Bearer your_token" \
http://localhost:8000/tools/available
curl -X POST -H "Authorization: Bearer your_token" \
-H "Content-Type: application/json" \
-d '{"btc_amount": "0.0004", "dao_token_dex_contract_address": "SP..."}' \
http://localhost:8000/tools/faktory/execute_buy
For more detailed examples, see the documentation.
We welcome contributions! Please see our Development Guide for detailed information.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Make your changes with tests
- Format code (
ruff format .
) - Test your changes (
pytest
) - Commit changes (
git commit -m 'Add amazing feature'
) - Push to branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Follow Python code style using
ruff
- Add tests for new features
- Update documentation as needed
- Keep pull requests focused and atomic
- Ensure WebSocket and async code is properly tested
For detailed development setup and workflows, see Development Documentation.
MIT aibtcdev