Features: - Multi-platform bot (Slack, Telegram) - Memory system with SQLite FTS - Tool use capabilities (file ops, commands) - Scheduled tasks system - Dynamic model switching (/sonnet, /haiku) - Prompt caching for cost optimization Optimizations: - Default to Haiku 4.5 (12x cheaper) - Reduced context: 3 messages, 2 memory results - Optimized SOUL.md (48% smaller) - Automatic caching when using Sonnet (90% savings) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
11 KiB
Windows 11 Deployment Guide
Complete guide for deploying and testing Ajarbot on Windows 11.
Prerequisites
1. Install Python
Download and install Python 3.8 or higher from python.org:
# Verify installation
python --version
# Should show: Python 3.8+
# Verify pip
pip --version
Important: During installation, check "Add Python to PATH"
2. Get API Keys
You'll need at least one of these:
Claude (Anthropic) - Recommended
- Go to https://console.anthropic.com/
- Create account or sign in
- Navigate to API Keys
- Create new key
- Copy the key (starts with
sk-ant-)
GLM (z.ai) - Optional
- Go to https://z.ai
- Sign up and get API key
Quick Start (5 Minutes)
1. Clone or Navigate to Project
# If you haven't already
cd c:\Users\fam1n\projects\ajarbot
2. Create Virtual Environment (Recommended)
# Create virtual environment
python -m venv venv
# Activate it
.\venv\Scripts\activate
# You should see (venv) in your prompt
3. Install Dependencies
pip install -r requirements.txt
Expected output:
Successfully installed anthropic-0.40.0 requests-2.31.0 watchdog-3.0.0 ...
4. Set Environment Variables
Option A: PowerShell (temporary - current session only)
$env:ANTHROPIC_API_KEY = "sk-ant-your-key-here"
# Optional: GLM
$env:GLM_API_KEY = "your-glm-key-here"
Option B: System Environment Variables (persistent)
- Press
Win + X→ System - Click "Advanced system settings"
- Click "Environment Variables"
- Under "User variables", click "New"
- Variable name:
ANTHROPIC_API_KEY - Variable value:
sk-ant-your-key-here - Click OK
Option C: .env file (recommended for development)
# Create .env file in project root
notepad .env
Add to .env:
ANTHROPIC_API_KEY=sk-ant-your-key-here
GLM_API_KEY=your-glm-key-here
Then install python-dotenv and load it:
pip install python-dotenv
5. Test Basic Agent
python example_usage.py
Expected output:
============================================================
Basic Agent Usage Example
============================================================
[Setup] Initializing agent with Claude...
[Setup] Agent initialized
[Test 1] Basic chat...
Agent: [Response from Claude]
[Test 2] Memory operations...
...
Running Different Examples
Basic Agent with Memory
python example_usage.py
What it does:
- Creates agent with Claude
- Tests basic chat
- Demonstrates memory operations
- Shows task management
Pulse & Brain Monitoring
python example_bot_with_pulse_brain.py
What it does:
- Runs cost-effective monitoring
- Pure Python checks (zero cost)
- Conditional AI calls (only when needed)
- Shows real-time status
Press Ctrl+C to stop
Task Scheduler
python example_bot_with_scheduler.py
What it does:
- Schedules recurring tasks
- Demonstrates cron-like syntax
- Shows task execution
- Runs in background
Press Ctrl+C to stop
Skills Integration
python example_bot_with_skills.py
What it does:
- Loads Claude Code skills
- Allows skill invocation
- Demonstrates preprocessing
- Shows available skills
Multi-Platform Bot (Slack + Telegram)
First, generate configuration:
python bot_runner.py --init
This creates config\adapters.local.yaml
Edit the file:
notepad config\adapters.local.yaml
Add your credentials:
adapters:
slack:
enabled: true
credentials:
bot_token: "xoxb-your-token"
app_token: "xapp-your-token"
telegram:
enabled: true
credentials:
bot_token: "your-bot-token"
Run the bot:
python bot_runner.py
Testing Components
Test Skills System
python test_skills.py
Verifies:
- Skill discovery
- Skill loading
- Preprocessor functionality
Test Scheduler
python test_scheduler.py
Verifies:
- Task scheduling
- Schedule parsing
- Task execution
Running as Windows Service (Production)
Option 1: NSSM (Non-Sucking Service Manager)
Install NSSM:
- Download from https://nssm.cc/download
- Extract to
C:\nssm - Add to PATH or use full path
Create Service:
# Run as Administrator
nssm install Ajarbot "C:\Users\fam1n\projects\ajarbot\venv\Scripts\python.exe"
# Set parameters
nssm set Ajarbot AppParameters "bot_runner.py"
nssm set Ajarbot AppDirectory "C:\Users\fam1n\projects\ajarbot"
# Set environment variables
nssm set Ajarbot AppEnvironmentExtra ANTHROPIC_API_KEY=sk-ant-your-key
# Start service
nssm start Ajarbot
Manage Service:
# Check status
nssm status Ajarbot
# Stop service
nssm stop Ajarbot
# Remove service
nssm remove Ajarbot confirm
Option 2: Task Scheduler (Simpler)
Create scheduled task:
- Open Task Scheduler (
Win + R→taskschd.msc) - Create Basic Task
- Name: "Ajarbot"
- Trigger: "When computer starts"
- Action: "Start a program"
- Program:
C:\Users\fam1n\projects\ajarbot\venv\Scripts\python.exe - Arguments:
bot_runner.py - Start in:
C:\Users\fam1n\projects\ajarbot - Finish
Configure task:
- Right-click task → Properties
- Check "Run whether user is logged on or not"
- Check "Run with highest privileges"
- Triggers tab → Edit → Check "Enabled"
Option 3: Simple Startup Script
Create start_ajarbot.bat:
@echo off
cd /d C:\Users\fam1n\projects\ajarbot
call venv\Scripts\activate
set ANTHROPIC_API_KEY=sk-ant-your-key-here
python bot_runner.py
pause
Add to startup:
- Press
Win + R - Type
shell:startup - Copy
start_ajarbot.batto the folder
Running in Background
Using PowerShell
# Start in background
Start-Process python -ArgumentList "bot_runner.py" -WindowStyle Hidden -WorkingDirectory "C:\Users\fam1n\projects\ajarbot"
# Find process
Get-Process python | Where-Object {$_.CommandLine -like "*bot_runner*"}
# Stop process (get PID first)
Stop-Process -Id <PID>
Using pythonw (No console window)
# Run without console window
pythonw bot_runner.py
Monitoring and Logs
View Logs
By default, Python prints to console. To save logs:
Option 1: Redirect to file
python bot_runner.py > logs\bot.log 2>&1
Option 2: Add logging to code
Create config\logging_config.py:
import logging
from pathlib import Path
log_dir = Path("logs")
log_dir.mkdir(exist_ok=True)
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler(log_dir / "ajarbot.log"),
logging.StreamHandler()
]
)
Then in your scripts:
import logging
logger = logging.getLogger(__name__)
logger.info("Bot started")
Monitor Process
Task Manager:
- Press
Ctrl + Shift + Esc - Details tab
- Find
python.exe - Check CPU/Memory usage
PowerShell:
# Monitor in real-time
while ($true) {
Get-Process python | Select-Object CPU, PM, StartTime
Start-Sleep 5
}
Troubleshooting
"Python is not recognized"
Fix:
- Find Python installation:
C:\Users\fam1n\AppData\Local\Programs\Python\Python3XX - Add to PATH:
- Win + X → System → Advanced → Environment Variables
- Edit PATH, add Python directory
- Add Scripts directory too
"Module not found" errors
# Ensure virtual environment is activated
.\venv\Scripts\activate
# Reinstall dependencies
pip install -r requirements.txt --force-reinstall
"API key not found"
Verify environment variable:
# Check if set
$env:ANTHROPIC_API_KEY
# Should show your key, not empty
If empty, set it again:
$env:ANTHROPIC_API_KEY = "sk-ant-your-key"
Port already in use (for adapters)
If running multiple instances:
# Find process using port
netstat -ano | findstr :PORT_NUMBER
# Kill process
taskkill /PID <PID> /F
Memory workspace errors
# Delete and recreate
Remove-Item -Recurse -Force memory_workspace
python example_usage.py
Firewall blocking (for Slack/Telegram)
- Windows Security → Firewall & network protection
- Allow an app through firewall
- Add Python
- Check both Private and Public
Performance Tips
1. Use SSD for memory_workspace
If you have multiple drives, store memory on SSD:
# In agent.py, modify workspace_path
workspace_path = "D:\fast_storage\ajarbot_memory"
2. Optimize Pulse Interval
For lower CPU usage:
pb = PulseBrain(agent, pulse_interval=300) # 5 minutes instead of 60 seconds
3. Limit Memory Database Size
# In memory_system.py, add retention policy
memory.cleanup_old_entries(days=30)
4. Run with pythonw
# Lower priority, no console
pythonw bot_runner.py
Security Considerations
1. Protect API Keys
Never commit .env or adapters.local.yaml:
# Check .gitignore includes:
echo ".env" >> .gitignore
echo "config/*.local.yaml" >> .gitignore
2. Use Windows Credential Manager
Store API keys securely:
import keyring
# Store key
keyring.set_password("ajarbot", "anthropic_key", "sk-ant-...")
# Retrieve key
api_key = keyring.get_password("ajarbot", "anthropic_key")
Install keyring:
pip install keyring
3. Run with Limited User
Create dedicated user account:
- Settings → Accounts → Family & other users
- Add account → "Ajarbot Service"
- Run service as this user (limited permissions)
Development Workflow
1. Development Mode
# Activate venv
.\venv\Scripts\activate
# Run with auto-reload (install watchdog)
pip install watchdog[watchmedo]
# Monitor and restart on changes
watchmedo auto-restart --directory=. --pattern=*.py --recursive -- python bot_runner.py
2. Testing Changes
# Quick syntax check
python -m py_compile agent.py
# Run tests
python test_skills.py
python test_scheduler.py
3. Code Formatting
# Install black
pip install black
# Format code
black .
Next Steps
- Test locally: Run
example_usage.pyto verify setup - Configure adapters: Set up Slack or Telegram
- Customize: Edit pulse checks, schedules, or skills
- Deploy: Choose service option (NSSM, Task Scheduler, or Startup)
- Monitor: Check logs and system resources
Quick Reference
Start Bot
.\venv\Scripts\activate
python bot_runner.py
Stop Bot
Ctrl + C
View Logs
type logs\bot.log
Check Status
python bot_runner.py --health
Update Dependencies
pip install -r requirements.txt --upgrade
Need Help?
- Check main documentation
- Review troubleshooting section
- Check Windows Event Viewer for service errors
- Run examples to isolate issues