Skip to content

About

No description or website provided.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

2 Commits

Folders and files

Repository files navigation

TaskMaster C2

Command and Control center for distributed AI agent orchestration. Manages heterogeneous hardware clusters, syncs Ollama configurations, and intelligently routes AI inference tasks based on real-time resource availability.

License Python React Docker


πŸš€ Initial Startup & Installation

To get TaskMaster running on your local machine or server, use the interactive setup script. This script automatically handles Python virtual environments, Node.js packages, and .env generation.

  1. Clone the repository:
    git clone https://github.com/YOUR_ORG/TaskMaster.git
    cd TaskMaster
  2. Run the interactive setup installer:
    # On Windows
    setup_installer.bat
    During setup, the script will automatically generate a secure 32-character API_KEY for you and prompt you to wire up Cloudflared.
  3. Launch the development environment:
    run_dev.bat
    This starts the FastAPI backend (port 8000) and the React frontend (port 5173) simultaneously.

🌐 Wiring up Cloudflare (External Access)

If you are deploying TaskMaster to production via Docker, you likely want to securely expose the dashboard and API to the internet so remote agents can connect. We use Cloudflare Zero Trust Tunnels to achieve this without exposing your server's IP.

  1. Go to your Cloudflare Zero Trust Dashboard -> Networks -> Tunnels.
  2. Click Create a tunnel (Select Cloudflared). Name it TaskMaster.
  3. In the Public Hostname Page, create two routes:
    • dashboard.example.com -> HTTP://nginx:80
    • api.example.com -> HTTP://taskmaster_api:8000
  4. Copy your unique Tunnel Token.
  5. When running setup_installer.bat, answer Y when asked if you want to configure a Cloudflare Tunnel, and paste your token.
  6. Run docker compose up -d --build. Your tunnel is now active!

πŸ–₯ Interface & Capabilities

TaskMaster features a modern, responsive React dashboard that gives you full visibility into your AI cluster:

  • Live Agent Registry: View all connected worker nodes. See their OS, uptime, and available AI skills.
  • Hardware Telemetry: Real-time graphs showing CPU utilization, RAM usage, and GPU VRAM availability across your entire fleet.
  • Task Queue Monitoring: Watch tasks as they flow through the system. See which tasks are queued, which are actively processing, and exactly which agent claimed them.
  • Model Synchronization: Ensure all your agents have the correct local Ollama models installed remotely.

🧠 The Request Lifecycle (Routing Architecture)

TaskMaster's core innovation is its intelligent routing engine. It acts as the brain of your distributed AI cluster, ensuring tasks are sent to the hardware best equipped to handle them.

Step-by-Step Flow:

  1. Submission: A user or external application sends a REST POST request to TaskMaster containing the prompt, preferred model (e.g., llama3), and required skills (e.g., basic_chat).
  2. Filtering (Matching): TaskMaster instantly filters the live registry of connected agents, discarding any nodes that are offline, lack the required skills, or don't have the requested model installed.
  3. Scoring: The remaining eligible agents are scored based on real-time hardware telemetry:
    • GPU VRAM Available (Highest Weight)
    • CPU Load (Low load preferred)
    • System RAM Available
  4. Execution: The highest-scoring agent is assigned the task via a persistent WebSocket connection. The agent queries its local Ollama instance and processes the inference.
  5. Return: The agent sends the final generated text back to TaskMaster, which instantly relays the result back to the original requester.
User ──(POST /api/task/submit)──► TaskMaster
                                     β”‚ (Scores agents)
                                     β–Ό
Agent A (Offline)   Agent B (No VRAM)   Agent C (Idle RTX 4090)
                                            β”‚
                                    (Runs inference via Ollama)
                                            β”‚
User ◄──(Relays final result)────── TaskMaster ◄──(POST /api/task/result)

API Reference

All endpoints except / and /api/status require the X-API-Key header.

Public Endpoints

Method Path Description
GET / Health check β€” confirms API is running
GET /api/status Cluster status (agent counts, total RAM, GPU count, queue depth)

Agent Endpoints

Method Path Description
POST /api/heartbeat Agent sends hardware metrics (every 5s)
POST /api/config/sync?agent_id=<id> Agent pulls its Ollama configuration
POST /api/task/result Agent reports completed task results

Dashboard & Task Endpoints

Method Path Description
GET /api/agents List all registered agents with status
POST /api/task/submit Submit a task for intelligent routing
GET /api/task/history Last 200 task events
WS /ws/dashboard?key=<api_key> Real-time WebSocket feed

Example: Submit a Task

curl -X POST http://localhost/api/task/submit \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_API_KEY" \
  -d '{
    "task_id": "task-001",
    "template": "chat",
    "parameters": {"prompt": "Explain quantum computing"},
    "required_skills": ["basic_chat"],
    "requires_gpu": false,
    "preferred_model": "llama3"
  }'

Example: Agent Heartbeat

curl -X POST http://localhost/api/heartbeat \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_API_KEY" \
  -d '{
    "agent_id": "workstation-01",
    "os_info": "Windows 10",
    "hardware": {
      "cpu_percent": 15.2,
      "ram_total_mb": 32768,
      "ram_used_mb": 12500,
      "disk_total_mb": 512000,
      "disk_free_mb": 350000,
      "gpu_available": true,
      "gpu_details": [{
        "id": 0, "name": "RTX 4070",
        "load": 5.0, "memoryTotal": 12288,
        "memoryUsed": 1024, "memoryFree": 11264,
        "temperature": 42
      }]
    },
    "skills": ["basic_chat", "summarize"],
    "models": ["llama3:latest", "mistral:latest"]
  }'

WebSocket Protocol

Connect to /ws/dashboard?key=YOUR_API_KEY to receive real-time updates:

// Initial state snapshot (sent on connect)
{
  "type": "initial_state",
  "agents": { ... },
  "system_status": { ... },
  "task_history": [ ... ]
}

// Agent heartbeat update (sent every 5s per agent)
{
  "type": "agent_update",
  "agents": { ... },
  "system_status": { ... }
}

// Task lifecycle event
{
  "type": "task_event",
  "task_id": "task-001",
  "agent_id": "workstation-01",
  "status": "routed"
}

Secrets & Configuration

Environment Variables

Variable Default Description
API_KEY changeme-taskmaster-secret Shared authentication key for all API requests
HOST 0.0.0.0 Backend bind address
PORT 8000 Backend bind port
CORS_ORIGINS http://localhost:5173,... Allowed frontend origins (comma-separated)
AGENT_TIMEOUT_SECONDS 30 Seconds before an agent is marked offline
CLOUDFLARE_TUNNEL_TOKEN (empty) Cloudflare tunnel token for external access

Agent-Specific Variables

Variable Default Description
TASKMASTER_URL http://127.0.0.1:8000 URL of the TaskMaster API server
AGENT_ID (hostname) Unique identifier for this agent
API_KEY changeme-taskmaster-secret Must match the server's API_KEY
AGENT_SKILLS basic_chat Comma-separated skill tags
HEARTBEAT_INTERVAL 5 Seconds between heartbeats
OLLAMA_URL http://127.0.0.1:11434 Local Ollama API endpoint
CALLBACK_PORT 9000 Port for receiving task callbacks

Frontend Variables

Variable Default Description
VITE_API_URL (empty) Backend API URL (empty = use dev proxy)
VITE_WS_URL (empty) WebSocket URL (empty = auto-detect)
VITE_API_KEY changeme-taskmaster-secret Dashboard API key

GitHub Sync

# Auto-commit and push with timestamp
python git_sync.py

# Custom commit message
python git_sync.py "Added GPU scheduling improvements"

Authentication uses Windows Credential Manager (pre-configured via git config credential.helper manager).


Project Structure

TaskMaster/
β”œβ”€β”€ backend/                  # FastAPI API server
β”‚   β”œβ”€β”€ main.py               # Application entry point & routes
β”‚   β”œβ”€β”€ models.py             # Pydantic data schemas
β”‚   β”œβ”€β”€ router.py             # Agent registry & task routing engine
β”‚   β”œβ”€β”€ config.py             # Settings loaded from .env
β”‚   β”œβ”€β”€ websocket_manager.py  # Real-time WebSocket connection manager
β”‚   β”œβ”€β”€ cert_manager.py       # mTLS certificate generation
β”‚   β”œβ”€β”€ requirements.txt      # Python dependencies
β”‚   β”œβ”€β”€ Dockerfile            # Backend container image
β”‚   └── .env.example          # Environment variable template
β”œβ”€β”€ frontend/                 # React (Vite) dashboard
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.jsx           # Main dashboard component
β”‚   β”‚   β”œβ”€β”€ index.css         # Design system & styles
β”‚   β”‚   └── main.jsx          # React entry point
β”‚   β”œβ”€β”€ Dockerfile            # Multi-stage build β†’ nginx
β”‚   β”œβ”€β”€ package.json          # Node dependencies
β”‚   └── .env.example          # Frontend env template
β”œβ”€β”€ agent/                    # Deployable agent for worker nodes
β”‚   β”œβ”€β”€ agent.py              # Core heartbeat & task loop
β”‚   β”œβ”€β”€ hardware_monitor.py   # CPU/RAM/GPU/Disk telemetry
β”‚   β”œβ”€β”€ ollama_manager.py     # Local Ollama API interface
β”‚   β”œβ”€β”€ requirements.txt      # Python dependencies
β”‚   β”œβ”€β”€ setup_installer.bat   # Windows setup script
β”‚   └── setup_installer.sh    # Linux setup script + systemd
β”œβ”€β”€ nginx/                    # Reverse proxy configuration
β”‚   └── nginx.conf            # API proxy + WebSocket + static files
β”œβ”€β”€ cloudflared/              # Cloudflare tunnel config
β”‚   └── config.yml            # Tunnel routing rules
β”œβ”€β”€ docker-compose.yml        # Production container orchestration
β”œβ”€β”€ .env.example              # Root environment template
β”œβ”€β”€ .gitignore                # Version control exclusions
β”œβ”€β”€ build.bat                 # Windows build script
β”œβ”€β”€ run_dev.bat               # Windows development launcher
β”œβ”€β”€ git_sync.py               # Automated GitHub push utility
β”œβ”€β”€ todo.txt                  # Project progress tracker
└── README.md                 # This file

Integration Guide

Using TaskMaster from Another Project

TaskMaster exposes a standard REST API. To integrate from any language:

import requests

TASKMASTER_URL = "http://your-server:80"
API_KEY = "your-api-key"
HEADERS = {"X-API-Key": API_KEY, "Content-Type": "application/json"}

# Check cluster health
status = requests.get(f"{TASKMASTER_URL}/api/status").json()
print(f"Online agents: {status['online_agents']}, GPUs: {status['total_gpu_count']}")

# Submit an inference task
task = {
    "task_id": "my-app-001",
    "template": "chat",
    "parameters": {"prompt": "Translate 'hello' to French"},
    "required_skills": ["basic_chat"],
    "preferred_model": "llama3"
}
result = requests.post(f"{TASKMASTER_URL}/api/task/submit", json=task, headers=HEADERS).json()
print(f"Task routed to: {result.get('agent_id', 'queued')}")

Webhook / Callback Pattern

When an agent completes a task, it POSTs the result back to /api/task/result. You can poll /api/task/history to check for completion, or connect via the WebSocket to receive real-time task_event messages.


License

Licensed under the MIT License. See LICENSE for more information.

About

No description or website provided.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages