Skip to content

Integration Guide

Clasper is an agent runtime that works alongside your backend SaaS application. It doesn’t replace your backend — it extends it with AI agent capabilities while your backend remains the source of truth for all data.

The core idea: Your backend sends messages to Clasper, Clasper calls an LLM, and the agent’s response may include API calls back to your backend to read/write data. This bidirectional relationship is what makes agents useful.

A typical deployment runs 5 processes that work together:

┌─────────────────────────────────────────────────────────────────────────────┐
│ INFRASTRUCTURE │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Frontend │ │ Database │ │ Redis │ │
│ │ (SvelteKit) │ │ (PostgreSQL) │ │ (Queue) │ │
│ └──────┬───────┘ └──────▲───────┘ └──────▲───────┘ │
│ │ │ │ │
│ │ HTTP │ SQL │ Jobs │
│ ▼ │ │ │
│ ┌──────────────────────────────┴────────────────────────┴──────┐ │
│ │ Backend API │ │
│ │ (FastAPI :8000) │ │
│ │ • REST endpoints • Mission Control • Auth/Sessions │ │
│ └──────────────────────────────┬───────────────────────────────┘ │
│ │ │
│ ┌───────────────────────┼───────────────────────┐ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Worker │ │ Clasper │◀────────│ Dispatcher │ │
│ │ (Celery) │ │ Daemon │ │ (Poller) │ │
│ │ │ │ (:8081) │ │ │ │
│ │ • Async │ │ │ │ • Polls │ │
│ │ tasks │ │ • Agent │ │ undelivered│ │
│ │ • School │ │ runtime │ │ notifs │ │
│ │ analysis │ │ • LLM calls │ │ • Forwards │ │
│ └─────────────┘ │ • Skills │ │ to daemon │ │
│ │ └──────┬──────┘ └─────────────┘ │
│ │ │ │
│ │ │ API calls │
│ │ ▼ │
│ │ ┌─────────────┐ │
│ │ │ OpenAI │ │
│ │ │ (LLM API) │ │
│ │ └─────────────┘ │
│ │ │
└─────────────────────────────────────────────────────────────────────────────┘

Process summary:

ProcessPortCommandPurpose
Backend API8000make devREST API, Mission Control, auth
Worker-make dev-workerAsync tasks (Celery)
Frontend5173npm run devWeb UI
Clasper Daemon8081make devAgent runtime, LLM orchestration
Dispatcher-npm run dispatcherNotification delivery loop

This is the key concept to understand: Clasper and your backend have a bidirectional relationship.

┌──────────────────────────────────────────────────────────────────────────┐
│ │
│ ┌─────────────┐ ┌─────────────┐ │
│ │ Your │ ────── (1) sends message ──▶ │ Clasper │ │
│ │ Backend │ │ Daemon │ │
│ │ │ ◀─ (2) agent calls APIs ──── │ │ │
│ │ │ │ │ │
│ │ • Database │ │ • Stateless│ │
│ │ • Users │ ◀─ (3) dispatcher polls ──── │ • LLM calls│ │
│ │ • Tasks │ │ • Skills │ │
│ │ • Notifs │ │ │ │
│ └─────────────┘ └─────────────┘ │
│ │
└──────────────────────────────────────────────────────────────────────────┘
  1. Backend → Clasper: Your backend sends user messages to Clasper via POST /api/agents/send. The payload includes user_id, session_key, and the message.

  2. Clasper → OpenAI → Backend: Clasper loads the workspace config (AGENTS.md, souls, skills), builds a system prompt, calls OpenAI, and the agent’s response may include API calls back to your backend (Mission Control).

  3. Clasper → Backend (writes): The agent can create tasks, post messages, create documents, etc. by calling your backend’s Mission Control APIs. Clasper mints a short-lived JWT for these calls.

  4. Backend → Clasper (dispatcher): The dispatcher polls your backend for undelivered notifications and forwards them to the Clasper daemon, triggering agent responses.

Clasper doesn’t store user data, conversation history, or tasks. Your backend is the source of truth:

WhatWhere it lives
User accounts, sessionsBackend database
Conversation historyBackend database (or passed in messages[])
Tasks, documents, activityBackend (Mission Control tables)
Agent personas, rulesWorkspace files (in your backend repo)
LLM executionClasper (stateless, just routes requests)

This means:

  • You can run multiple Clasper instances behind a load balancer
  • No sticky sessions needed
  • If Clasper restarts, nothing is lost (state is in your backend)

To integrate with Clasper, your backend needs Mission Control APIs:

EndpointPurpose
POST /api/mission-control/tasksCreate tasks
GET /api/mission-control/tasksList tasks
POST /api/mission-control/messagesPost messages
POST /api/mission-control/documentsCreate documents
GET /api/mission-control/notificationsGet notifications
POST /api/mission-control/dispatch/undeliveredFor dispatcher

See Control Plane Contract for the full API spec.

Clasper requires a Mission Control-compatible backend. Configure the connection:

Terminal window
# Required
BACKEND_URL=http://localhost:8000
AGENT_JWT_SECRET=your-secret-matching-backend
AGENT_JWT_ALGORITHM=HS256 # default

The daemon posts to these Mission Control endpoints:

  • POST /api/mission-control/messages - Agent messages
  • POST /api/mission-control/documents - Agent documents (plans, reports)
  • GET /api/mission-control/tasks - Task lookup
  • POST /api/mission-control/tasks - Task creation

Point clasper to your project’s workspace folder:

Terminal window
# Relative or absolute path
CLASPER_WORKSPACE=./workspace
CLASPER_WORKSPACE=/path/to/project/agent-config
# Default task title (optional)
CLASPER_DEFAULT_TASK=Agent Thread

For production projects, keep the workspace config in your backend repo (not in clasper). This keeps agent behavior version-controlled with the APIs the agents call.

Example directory structure:

your-backend/
├── app/ # Backend code
├── agent-config/ # Clasper workspace config
│ ├── workspace/ # ← Set CLASPER_WORKSPACE to this
│ │ ├── AGENTS.md # Operating rules
│ │ ├── IDENTITY.md # Agent names/branding
│ │ ├── HEARTBEAT.md # Heartbeat checklist
│ │ ├── souls/ # Per-agent personalities
│ │ │ ├── lead.md
│ │ │ ├── researcher.md
│ │ │ └── writer.md
│ │ └── skills/ # API usage instructions
│ │ └── task-management/SKILL.md
│ └── README.md
└── ...

Running clasper for a project:

Terminal window
# From clasper directory
CLASPER_WORKSPACE=/path/to/your-backend/agent-config/workspace make dev

See docs/examples/multi-agent/ for a complete example workspace.

See Workspace Configuration for workspace file specifications.

Clasper can optionally select relevant skill instructions and memory chunks based on the user request. This reduces token usage without hiding the skill catalog.

Terminal window
CLASPER_SMART_CONTEXT=true
CLASPER_SMART_CONTEXT_MAX_SKILLS=5
CLASPER_SMART_CONTEXT_MAX_MEMORY=3
CLASPER_SMART_CONTEXT_MAX_TOKENS=0
CLASPER_EMBEDDING_PROVIDER=none # none | local | openai
CLASPER_EMBEDDING_MODEL=Xenova/all-MiniLM-L6-v2

The dispatcher polls the backend for undelivered notifications and forwards them to the daemon:

Terminal window
# Must match backend INTERNAL_API_TOKEN
INTERNAL_API_TOKEN=your-internal-token
# Daemon URL (where dispatcher sends notifications)
AGENT_DAEMON_URL=http://localhost:8081
# Optional daemon auth key
AGENT_DAEMON_API_KEY=

Run the dispatcher:

Terminal window
npm run dispatcher

The daemon resolves tasks in priority order:

  1. task_id in request - Use this specific task (backend-owned)
  2. task_title in request - Find or create task with this title
  3. CLASPER_DEFAULT_TASK env var - Fallback default

This enables flexible patterns:

  • Backend-owned: Backend creates tasks, passes task_id to clasper
  • Clasper-owned: Clasper auto-creates tasks with task_title or default

POST /api/agents/send

{
"user_id": "uuid",
"session_key": "user:{userId}:agent",
"message": "Generate a plan for the project.",
"task_title": "Project Planning",
"metadata": {
"kickoff_plan": true,
"kickoff_note": "Draft a concise 3-step plan."
}
}

With backend-owned task:

{
"user_id": "uuid",
"session_key": "user:{userId}:agent",
"message": "Continue working on this task.",
"task_id": "existing-task-uuid"
}
┌─────────┐ ┌─────────┐ ┌─────────┐
│ Backend │────▶│ Clasper │────▶│ OpenAI │
│ │ │ Daemon │ │ │
└─────────┘ └─────────┘ └─────────┘
│ │
│ X-Internal-Token (dispatcher)
│ X-Agent-Daemon-Key (optional)
│ │
│ ▼
│ ┌─────────────┐
│◀────────│ Agent JWT │──── X-Agent-Token
│ │ (minted by │
│ │ clasper) │
│ └─────────────┘
Terminal window
USER_ID=user-uuid AGENT_ROLE=agent npm run heartbeat
Terminal window
STANDUP_TIMEZONE=UTC npm run standup
  1. Clone clasper to your dev environment
  2. Create a workspace folder in your project repo:
    your-project/
    └── agent-config/
    ├── AGENTS.md
    ├── SOUL.md
    └── souls/
    └── specialist.md
  3. Configure clasper:
    Terminal window
    CLASPER_WORKSPACE=/path/to/your-project/agent-config
    CLASPER_DEFAULT_TASK=Your Project Task
    BACKEND_URL=http://your-backend:8000
  4. Start clasper: npm run dev