Skip to content

Staging #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 58 commits into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
e593649
update
human058382928 Apr 5, 2025
4fb68fb
add core proposal tools
human058382928 Apr 5, 2025
11bad63
add smart wallet tools
human058382928 Apr 5, 2025
5589878
remove duplicates
human058382928 Apr 5, 2025
8cef028
Merge pull request #179 from aibtcdev/core-proposal-tools
whoabuddy Apr 7, 2025
fd96d1d
Merge branch 'staging' into smart-wallet-tools
whoabuddy Apr 7, 2025
46eefc6
Merge pull request #180 from aibtcdev/smart-wallet-tools
whoabuddy Apr 7, 2025
f856b19
fix imports
human058382928 Apr 7, 2025
5f4c9c0
feat: add optional memo parameter to dao action proposal tools
whoabuddy Apr 11, 2025
a00b758
fix: update submodule with latest from aibtcdev/agent-tools-ts#131
whoabuddy Apr 11, 2025
bf84df8
add twitter functionality
human058382928 Apr 14, 2025
fb7549f
support multiple collections
human058382928 Apr 14, 2025
38aac62
update
human058382928 Apr 14, 2025
f810847
update dependencies
human058382928 Apr 14, 2025
068e5db
fixes for document processor
human058382928 Apr 14, 2025
b42b29e
Merge pull request #181 from aibtcdev/fix/update-proposal-tooling
human058382928 Apr 14, 2025
a39e398
fix proposals
human058382928 Apr 14, 2025
962cd76
add smart wallet deployer
human058382928 Apr 16, 2025
649c131
rename
human058382928 Apr 16, 2025
e235a1d
feat: Add recent DAO tweets to proposal evaluation
davek-ai Apr 17, 2025
57b2f17
Delete services/runner/tasks/tweet_task.py
davek-ai Apr 17, 2025
e6bea91
update to tweet_task
davek-ai Apr 17, 2025
13061d9
update agent tools
davek-ai Apr 17, 2025
ed1c2b0
Merge pull request #183 from aibtcdev/feature/daoroundup_username
human058382928 Apr 17, 2025
77fc9f0
Merge branch 'staging' into add-smart-wallet-deployer
human058382928 Apr 17, 2025
f47d085
Merge pull request #182 from aibtcdev/add-smart-wallet-deployer
human058382928 Apr 17, 2025
141d944
update to support selecting model
human058382928 Apr 17, 2025
1169267
update for custom model/temperature
human058382928 Apr 17, 2025
3227da9
update
human058382928 Apr 17, 2025
b14f8d9
fix bug
human058382928 Apr 17, 2025
43f6116
update documentation;
human058382928 Apr 18, 2025
3094bcd
update for search ability
human058382928 Apr 19, 2025
abfc5b2
add docs
human058382928 Apr 22, 2025
858f1cf
add treasury balance to the evaluation prompt
human058382928 Apr 22, 2025
c525726
Merge pull request #193 from aibtcdev/searchfunctionality
whoabuddy Apr 24, 2025
99d0b47
attempt;
human058382928 Apr 30, 2025
e4f4d7e
store cost
human058382928 Apr 30, 2025
24141bc
Merge pull request #201 from aibtcdev/split-up
human058382928 Apr 30, 2025
020c392
skip older blocks since it could be redundant
human058382928 May 1, 2025
6a46042
skip older blocks since it could be redundant
human058382928 May 1, 2025
229361c
skip older blocks since it could be redundant
human058382928 May 1, 2025
1680343
skip older blocks since it could be redundant
human058382928 May 1, 2025
6d51cc8
fix evaluation runner
human058382928 May 1, 2025
e2d52a8
fix evaluation runner
human058382928 May 1, 2025
6b0ddf6
fix evaluation runner
human058382928 May 1, 2025
75a39f6
feat: Add DAO-specific tweet filtering to proposal evaluation
davek-ai May 1, 2025
365c570
fix evaluation runner
human058382928 May 1, 2025
0648ad9
fix evaluation runner
human058382928 May 1, 2025
70de715
fix evaluation runner
human058382928 May 1, 2025
529d418
fix evaluation runner
human058382928 May 1, 2025
d7c2c59
fix evaluation runner
human058382928 May 1, 2025
a0a7fd8
fix evaluation runner
human058382928 May 1, 2025
72972c3
fix evaluation runner
human058382928 May 1, 2025
ae412a7
Merge branch 'staging' into fix/x_recent_tweets
human058382928 May 1, 2025
cf2a2b9
Merge pull request #203 from aibtcdev/fix/x_recent_tweets
human058382928 May 1, 2025
01f1705
bug fux
human058382928 May 1, 2025
4d0a00b
add profile_id
human058382928 May 1, 2025
7f2fb29
Merge branch 'main' into staging
human058382928 May 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ AIBTC_ALEX_BASE_URL=https://api.alexgo.io/
AIBTC_VELAR_BASE_URL="https://gateway.velar.network/"

# AI Services
OPENAI_MODEL_NAME="gpt-4o"
OPENAI_MODEL_NAME="gpt-4.1"
OPENAI_API_KEY="sk-proj-your-api-key-here"
# For local model deployment
# OPENAI_API_BASE="http://localhost:5000"
Expand Down Expand Up @@ -81,6 +81,15 @@ AIBTC_DAO_PROPOSAL_CONCLUDE_RUNNER_ENABLED=false
AIBTC_DAO_PROPOSAL_CONCLUDE_RUNNER_INTERVAL_SECONDS=60
AIBTC_DAO_PROPOSAL_CONCLUDE_RUNNER_WALLET_ID="your-wallet-id"

# Step 6:
AIBTC_DAO_PROPOSAL_EVALUATION_RUNNER_ENABLED=false
AIBTC_DAO_PROPOSAL_EVALUATION_RUNNER_INTERVAL_SECONDS=60

# Step 6: Process agent account deployments
AIBTC_AGENT_ACCOUNT_DEPLOY_RUNNER_ENABLED=false
AIBTC_AGENT_ACCOUNT_DEPLOY_RUNNER_INTERVAL_SECONDS=60
AIBTC_AGENT_ACCOUNT_DEPLOY_RUNNER_WALLET_ID="your-wallet-id"

# =============================================================================
# Social Media Integration
# =============================================================================
Expand Down
284 changes: 153 additions & 131 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

## Overview

aibtcdev-backend is a FastAPI-based backend service that provides API endpoints for chat functionality, tools, and webhooks. It integrates with various external services including OpenAI, Twitter, Telegram, and blockchain-related APIs.
aibtcdev-backend is a sophisticated FastAPI-based backend service that powers AI-driven interactions with Bitcoin and Stacks blockchain technologies. The service provides:

1. Real-time chat functionality with AI agents via WebSocket
2. Automated DAO management and monitoring
3. Social media integration (Twitter, Telegram, Discord)
4. Blockchain interaction capabilities (Stacks, Bitcoin)
5. Market data analysis and reporting
6. Document processing and vector search capabilities

The system is designed to be modular, scalable, and easily configurable through environment variables.

## Disclaimer

Expand All @@ -11,59 +20,84 @@ aibtc.dev is not liable for any lost, locked, or mistakenly sent funds. This is
## Prerequisites

- Python 3.13
- [Bun](https://bun.sh/) (for running TypeScript scripts)
- [Bun](https://bun.sh/) (for TypeScript tools)
- Git
- Conda (recommended for development) or Docker

## Features

- FastAPI-based REST API
- WebSocket support for real-time communication
- Integration with multiple external services:
- Supabase for database and storage
- OpenAI for AI capabilities
- Twitter API for social media integration
- Telegram Bot API
- Blockchain APIs (Hiro, Alex, Velar)
- Market data APIs (LunarCrush, CMC)
- Background task scheduling system
- CORS support for multiple frontend environments
- Comprehensive logging system
- Workflow automation for tweet analysis and generation
- Node.js and npm (for agent tools)

## Project Structure

The project is organized into several key directories:

- `api/`: Contains API endpoint definitions
- `chat.py`: WebSocket chat endpoints
- `tools.py`: Available tools endpoints
- `webhooks.py`: Webhook handling endpoints

- `backend/`: Database abstraction and models
- `abstract.py`: Abstract base classes for database operations
- `factory.py`: Factory pattern for database backend creation
- `models.py`: Data models
- `supabase.py`: Supabase-specific implementation

- `services/`: Core business logic and integrations
- `bot.py`: Telegram bot integration
- `chat.py`: Chat handling services
- `daos.py`: DAO processing services
- `schedule.py`: Scheduling services
- `startup.py`: Application startup and shutdown services
- `twitter.py`: Twitter integration services
- `workflows/`: Workflow implementations
- `base.py`: Base workflow classes
- `react.py`: ReAct workflow implementation
- `tweet_analysis.py`: Tweet analysis workflow
- `tweet_generator.py`: Tweet generation workflow

- `tools/`: Tool implementations for agent use

- `lib/`: Shared utilities and libraries
```
aibtcdev-backend/
├── api/ # FastAPI endpoint definitions
│ ├── chat.py # WebSocket chat endpoints
│ ├── tools.py # Tool endpoints
│ ├── webhooks.py # Webhook handlers
│ └── dependencies.py # API dependencies
├── services/ # Core business logic
│ ├── workflows/ # Workflow implementations
│ ├── runner/ # Background task runners
│ ├── webhooks/ # Webhook processors
│ ├── discord/ # Discord integration
│ ├── chat.py # Chat service
│ ├── daos.py # DAO operations
│ ├── schedule.py # Task scheduling
│ ├── startup.py # App lifecycle management
│ ├── twitter.py # Twitter integration
│ ├── bot.py # Telegram bot
│ └── websocket.py # WebSocket management
├── backend/ # Database and storage
├── tools/ # AI agent tools
├── lib/ # Shared utilities
├── tests/ # Test suite
├── docs/ # Documentation
├── examples/ # Usage examples
└── agent-tools-ts/ # TypeScript-based agent tools
```

- `agent-tools-ts/`: TypeScript tools for agent integration
## Key Features

### 1. AI Chat System
- Real-time WebSocket-based chat
- AI agent integration with OpenAI
- Context-aware conversations
- Document-based knowledge integration
- Vector search capabilities

### 2. DAO Management
- Automated DAO deployment monitoring
- Proposal creation and tracking
- Vote processing
- Automated conclusion handling
- Tweet generation for DAO events

### 3. Social Media Integration
- Twitter automation and monitoring
- Telegram bot integration
- Discord notifications
- Automated content generation
- Social engagement tracking

### 4. Blockchain Integration
- Stacks blockchain interaction
- Bitcoin network monitoring
- Multiple API integrations:
- Hiro
- Alex
- Velar
- Platform API

### 5. Market Analysis
- LunarCrush integration
- CoinMarketCap data processing
- Market trend analysis
- Automated reporting

### 6. Background Processing
- Scheduled task management
- Event-driven processing
- Multi-threaded task execution
- Failure recovery and retry logic

## Installation

Expand All @@ -83,93 +117,61 @@ git submodule update --remote
cp .env.example .env
```

2. Configure the following key sections in your `.env` file:
- Core Application Settings
- Database Configuration (Supabase)
- External API Endpoints & Keys
- Task Scheduling Configuration
- Social Media Integration
- Additional Tools & Services
2. Configure your environment variables by following the [Configuration Guide](CONFIG.md)

### 3. Development Setup (Conda Recommended)

1. Install Miniconda:
```bash
# On macOS
# Install Miniconda
brew install miniconda

# Initialize conda
conda init "$(basename "${SHELL}")"
# Restart your terminal
```

2. Create and activate the environment:
```bash
# Create and activate environment
conda create --name aibackend python=3.12
conda activate aibackend
```

3. Install dependencies:
```bash
# Install dependencies
pip install -r requirements.txt
```

4. Set up TypeScript tools:
```bash
# Set up TypeScript tools
cd agent-tools-ts/
bun install
cd ..
```

### 4. Alternative: Docker Setup
### 4. Docker Setup

```bash
docker build -t aibtcdev-backend .
docker run -p 8000:8000 --env-file .env aibtcdev-backend
```

## API Endpoints

The service exposes the following endpoints:
## API Documentation

### Chat Endpoints (`/chat`)
- `/chat/ws` - WebSocket endpoint for real-time chat communication
- Supports message history retrieval
- Real-time message processing
- Supports agent-based conversations
- Maintains thread-based chat history
### WebSocket Endpoints (`/chat`)
- `/chat/ws`: Real-time chat communication
- Supports message history
- AI agent integration
- Context management
- Document processing

### Tools Endpoints (`/tools`)
- `/tools/available` - Get list of available tools and their descriptions
- Returns tool information including:
- Tool ID and name
- Description
- Category
- Required parameters
### Tool Endpoints (`/tools`)
- `/tools/available`: Available tool listing
- `/tools/execute`: Tool execution endpoint
- Custom tool integration support

### Webhook Endpoints (`/webhooks`)
- `/webhooks/chainhook` - Handle blockchain-related webhook events
- `/webhooks/github` - Process GitHub webhook events
- `/webhooks/chainhook`: Blockchain event processing
- `/webhooks/github`: GitHub integration
- `/webhooks/discord`: Discord notifications

### Bot Endpoints (`/bot`)
- `/bot/telegram/test` - Test Telegram bot integration
- Send test messages to verified users
- Requires user profile verification

All endpoints require proper authentication and most endpoints use profile verification middleware to ensure secure access to the API.

For detailed API documentation including request/response schemas, visit `/docs` when running the server.

## Configuration

The application uses a hierarchical configuration system defined in `config.py`, including:

- DatabaseConfig: Supabase connection settings
- TwitterConfig: Twitter API integration settings
- TelegramConfig: Telegram bot settings
- SchedulerConfig: Background task scheduling
- APIConfig: External API endpoints and keys
- NetworkConfig: Network-specific settings (testnet/mainnet)
- `/bot/telegram`: Telegram bot integration
- User verification and management
- Command processing

## Development

Expand All @@ -179,45 +181,65 @@ The application uses a hierarchical configuration system defined in `config.py`,
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
```

### Background Tasks
### Code Style

The application includes several background tasks that can be enabled/disabled via environment variables:
- Schedule synchronization
- DAO processing pipeline
- Tweet generation and posting
- Social media integration tasks
- Tweet analysis workflows
The project uses ruff for code formatting and linting. Configuration is in `ruff.toml`.

### Testing

```bash
pytest tests/
```

## Dependencies
### Documentation

Key dependencies include:
- APScheduler: For scheduling background tasks
- FastAPI: Web framework
- LangChain & LangGraph: For AI agent workflows
- OpenAI: For AI capabilities
- Supabase: For database and storage
- python-twitter-v2: For Twitter integration
- python-telegram-bot: For Telegram integration
API documentation is available at `/docs` when running the server.

## Contributing

1. Branch protection is enabled on `main`
2. Auto-deployment is configured for updates
3. Pull requests require one approval
4. Please ensure all tests pass before submitting a PR
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Run tests
5. Submit a pull request

Guidelines:
- Follow the Python code style guide
- Add tests for new features
- Update documentation as needed
- Keep pull requests focused and atomic

## Troubleshooting

### OpenAI Rate Limits
- Check your current tier limits at https://platform.openai.com/settings/organization/limits
- TPM (Tokens Per Minute) limits:
- Tier 1: 200,000 TPM
- Tier 2: 2,000,000 TPM
### Common Issues

## License
1. OpenAI Rate Limits
- Check limits at https://platform.openai.com/settings/organization/limits
- TPM (Tokens Per Minute) limits:
- Tier 1: 200,000 TPM
- Tier 2: 2,000,000 TPM

[License Information]
2. WebSocket Connection Issues
- Check network connectivity
- Verify authentication tokens
- Check server logs for details

3. Database Connection Issues
- Verify Supabase credentials
- Check network access to database
- Verify connection string format

## Support

[Support Information]
For support:
1. Check the documentation
2. Search existing issues
3. Create a new issue with:
- Clear description
- Steps to reproduce
- Expected vs actual behavior
- Environment details

## License

[License Information]
2 changes: 1 addition & 1 deletion agent-tools-ts
Submodule agent-tools-ts updated 186 files
Loading