Migrate to Claude Agent SDK framework (v0.2.0)

BREAKING CHANGE: Replaced FastAPI server wrapper with direct Claude Agent SDK integration

## Major Changes

### Architecture
- **OLD:** Bot → FastAPI Server → claude-code-sdk → Claude
- **NEW:** Bot → Claude Agent SDK → Claude (Pro subscription OR API)
- Eliminated HTTP server overhead
- Single-process architecture

### LLM Backend (llm_interface.py)
- Implemented Claude Agent SDK as DEFAULT mode
- Added three-mode architecture:
  - agent-sdk (default) - Uses Pro subscription
  - direct-api - Pay-per-token Anthropic API
  - legacy-server - Backward compat with old setup
- Created async/sync bridge using anyio
- Preserved all existing functionality (17 tools, memory, scheduling)

### Dependencies (requirements.txt)
- Replaced: claude-code-sdk → claude-agent-sdk>=0.1.0
- Added: anyio>=4.0.0 for async bridging
- Removed: fastapi, uvicorn (no longer needed for default mode)

### New Files
- ajarbot.py - Unified launcher with pre-flight checks
- run.bat - Windows one-command launcher (auto-setup)
- pyproject.toml - Python package metadata
- MIGRATION.md - Upgrade guide from old setup
- AGENT_SDK_IMPLEMENTATION.md - Technical documentation
- QUICK_REFERENCE_AGENT_SDK.md - Quick reference card
- test_agent_sdk.py - Comprehensive test suite

### Updated Documentation
- CLAUDE_CODE_SETUP.md - Rewritten for Agent SDK
- README.md - Updated quick start for new default
- .env.example - Added AJARBOT_LLM_MODE configuration

### Deleted Files
- claude_code_server.py - Replaced by agent-sdk integration
- heartbeat.py - Superseded by scheduled_tasks.py
- pulse_brain.py - Unused in production

## Migration Path

Old setup:
1. Start FastAPI server: python claude_code_server.py
2. Start bot: python bot_runner.py
3. Set USE_CLAUDE_CODE_SERVER=true

New setup:
1. Run: run.bat (or python ajarbot.py)
   - That's it! Single command.

## Benefits

 Zero API costs (uses Claude Pro subscription)
 Simplified deployment (no separate server)
 Single-command launch (run.bat)
 Faster response times (no HTTP overhead)
 All functionality preserved (17 tools, memory, adapters)
 Backward compatible (old env vars still work)

## Compatibility

- Python 3.10+ required
- Node.js required (for Claude Code CLI bundled with SDK)
- Windows 11 tested and optimized
- All existing tools, memory system, and adapters unchanged

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-15 10:03:11 -07:00
parent a8665d8c72
commit ce2c384387
8 changed files with 1813 additions and 16 deletions

View File

@@ -26,9 +26,7 @@ A lightweight, cost-effective AI agent framework for building proactive bots wit
## Quick Start
**For detailed setup instructions**, see **[SETUP.md](SETUP.md)** - includes API key setup, configuration, and troubleshooting.
### 30-Second Quickstart
### Option 1: Agent SDK (Recommended - Uses Pro Subscription)
```bash
# Clone and install
@@ -36,18 +34,39 @@ git clone https://vulcan.apophisnetworking.net/jramos/ajarbot.git
cd ajarbot
pip install -r requirements.txt
# Configure (copy examples and add your API key)
cp .env.example .env
cp config/scheduled_tasks.example.yaml config/scheduled_tasks.yaml
# Authenticate with Claude CLI (one-time setup)
claude auth login
# Add your Anthropic API key to .env
# ANTHROPIC_API_KEY=sk-ant-...
# Configure adapters
cp .env.example .env
cp config/adapters.example.yaml config/adapters.local.yaml
# Edit config/adapters.local.yaml with your Slack/Telegram tokens
# Run
python example_usage.py
run.bat # Windows
python ajarbot.py # Linux/Mac
```
**Windows users**: Run `quick_start.bat` for automated setup
### Option 2: API Mode (Pay-per-token)
```bash
# Clone and install
git clone https://vulcan.apophisnetworking.net/jramos/ajarbot.git
cd ajarbot
pip install -r requirements.txt
# Configure
cp .env.example .env
# Edit .env and add:
# AJARBOT_LLM_MODE=api
# ANTHROPIC_API_KEY=sk-ant-...
# Run
run.bat # Windows
python ajarbot.py # Linux/Mac
```
**See [CLAUDE_CODE_SETUP.md](CLAUDE_CODE_SETUP.md)** for detailed setup and mode comparison.
### Model Switching Commands
@@ -347,11 +366,18 @@ ajarbot/
### Environment Variables
```bash
# Required
# LLM Mode (optional - defaults to agent-sdk)
export AJARBOT_LLM_MODE="agent-sdk" # Use Pro subscription
# OR
export AJARBOT_LLM_MODE="api" # Use pay-per-token API
# Required for API mode only
export ANTHROPIC_API_KEY="sk-ant-..."
# Optional
# Optional: Alternative LLM
export GLM_API_KEY="..."
# Adapter credentials (stored in config/adapters.local.yaml)
export AJARBOT_SLACK_BOT_TOKEN="xoxb-..."
export AJARBOT_SLACK_APP_TOKEN="xapp-..."
export AJARBOT_TELEGRAM_BOT_TOKEN="123456:ABC..."