Skip to content

Autonomous AI agent that builds and operates SaaS products

Notifications You must be signed in to change notification settings

nxtlvlrob/agent-framework

Repository files navigation

Comet Apps Agent Framework

Autonomous AI agent that builds and operates SaaS products using the SaaS Boilerplate.

Introduction

The Agent Framework is a Dockerized orchestration system that uses Claude Code (Anthropic's coding agent) to autonomously build, review, and deploy full-stack SaaS applications β€” from an empty repo to a live product.

What it does

You give it a one-line description like "Build a habit tracker with streaks and a calendar heatmap", and the framework takes it from there. It spins up a Docker container, clones a production-ready SaaS Boilerplate, initializes a structured Knowledge Template for memory and state, then runs through a multi-role pipeline β€” Initiator β†’ Planner β†’ Developer β†’ Reviewer β†’ Marketer β†’ Deployer β€” cycling Claude Code with role-specific prompts until the product is built and deployed.

How it works

The framework is built around three core ideas:

  1. Role-based prompting β€” Instead of one massive prompt, the agent assumes distinct roles (planner, developer, reviewer, etc.), each with focused instructions and responsibilities. The orchestrator automatically selects the right role based on the project's current phase.

  2. Knowledge-driven state β€” The agent reads and writes to a .knowledge/ directory inside the project repo. This structured store (JSON files for context, work items, decisions, and metrics) acts as persistent memory across cycles, so the agent always knows what it's done, what's next, and why decisions were made. The knowledge structure is initialized from the Knowledge Template.

  3. Boilerplate-first development β€” Every product starts from the SaaS Boilerplate, which provides authentication (Clerk), database (MongoDB), payments (Stripe), UI (Tailwind + shadcn/ui), and deployment (Vercel) out of the box. The agent extends this foundation rather than building from scratch, so it can focus on product-specific features.

The ecosystem

This repo is one piece of a three-part system:

Repository Purpose
Agent Framework (this repo) Orchestration engine β€” Docker container, role prompts, state machine, Claude Code integration
SaaS Boilerplate Product template β€” Next.js 15, Clerk, MongoDB, Stripe, Tailwind, shadcn/ui
Knowledge Template Agent memory β€” structured JSON store for context, work tracking, decisions, and metrics

The framework clones the boilerplate to create a new product repo, initializes the knowledge template inside it, then iteratively builds features until the product is deployed to Vercel.

Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     Agent Container                              β”‚
β”‚                                                                  β”‚
β”‚  1. Initialize/clone project repository                          β”‚
β”‚  2. Load knowledge from .knowledge/                              β”‚
β”‚  3. Read role-specific instructions                              β”‚
β”‚  4. Run Claude Code to execute tasks                             β”‚
β”‚  5. Update .knowledge/ with progress                             β”‚
β”‚  6. Commit and push changes                                      β”‚
β”‚                                                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Project Repository                   SaaS Boilerplate (fork)
       β”‚                                     β”‚
       β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚  β”‚
       β–Ό  β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  Product Instance                     β”‚
β”‚                                                       β”‚
β”‚  /project/                                            β”‚
β”‚  β”œβ”€β”€ .knowledge/          ← Agent memory & state     β”‚
β”‚  β”‚   β”œβ”€β”€ context/                                     β”‚
β”‚  β”‚   β”œβ”€β”€ work/                                        β”‚
β”‚  β”‚   β”œβ”€β”€ decisions/                                   β”‚
β”‚  β”‚   └── metrics/                                     β”‚
β”‚  β”‚                                                    β”‚
β”‚  β”œβ”€β”€ app/                 ← Next.js routes           β”‚
β”‚  β”œβ”€β”€ components/          ← React components         β”‚
β”‚  β”œβ”€β”€ lib/                 ← Utilities & DB           β”‚
β”‚  β”œβ”€β”€ config/              ← Plans & settings         β”‚
β”‚  └── CLAUDE.md            ← Agent instructions       β”‚
β”‚                                                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Quick Start

Prerequisites

  • Docker installed
  • Anthropic API key with Claude Code access
  • (Optional) GitHub token for pushing changes

Option 1: Local Mode (Quick Testing)

Uses mounted volumes - good for development and testing.

# Set your API key
export ANTHROPIC_API_KEY=sk-ant-...

# Or create .env file
echo "ANTHROPIC_API_KEY=sk-ant-..." > .env

# Build and run
docker compose build
docker compose up

# Check output
ls -la output/
cd output && npm install && npm run dev

Option 2: GitHub Mode (Full Autonomy)

Clones repos from GitHub and pushes changes back.

# Create .env with all variables
cat > .env << EOF
ANTHROPIC_API_KEY=sk-ant-...
GITHUB_TOKEN=ghp_...
PROJECT_NAME=my-saas-product
PROJECT_BRANCH=main
KNOWLEDGE_TEMPLATE=your-org/knowledge-template
EOF

# Run
docker compose --profile github up

Running the Full Pipeline

Smart Orchestration (Recommended)

Run the full pipeline inside a single Docker container - no external scripts needed:

# Set up your .env file first, then:
ORCHESTRATE_MODE=smart \
BUILD_TASK="Build a habit tracker app" \
docker compose up --build

Or add to your .env:

ORCHESTRATE_MODE=smart
BUILD_TASK="Build a habit tracker with streaks and calendar heatmap"
MAX_CYCLES=25
MAX_DEV_CYCLES=6
REVIEW_EVERY=3

Then just:

docker compose up --build

The container will:

  1. Set up the project repo and knowledge store (once)
  2. Run the orchestration loop internally
  3. Cycle through roles based on phase until complete
  4. Exit when done or stuck

GitHub Actions (Cloud Deployment)

Run the agent in the cloud using GitHub Actions - no local Docker required:

# 1. Set up secrets in GitHub (Settings β†’ Secrets β†’ Actions):
#    - ANTHROPIC_API_KEY
#    - GH_PAT (Personal Access Token with repo scope)
#    - VERCEL_TOKEN (optional, for deployments)

# 2. Trigger via GitHub UI:
#    Actions β†’ πŸ€– Run Comet Agent β†’ Run workflow β†’ Fill form

# 3. Or trigger via API:
curl -X POST \
  -H "Authorization: token $GITHUB_TOKEN" \
  -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/YOUR_USER/cometapps/actions/workflows/run-agent.yml/dispatches \
  -d '{
    "ref": "main",
    "inputs": {
      "project_name": "habit-tracker",
      "build_task": "Build a habit tracker with streaks",
      "orchestrate_mode": "smart"
    }
  }'

See .github/README.md for full documentation on GitHub Actions workflows.

Example output:

🎯 [ORCHESTRATOR] Cycle 1 of 20
   Phase: new β†’ Role: initiator
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🎭 Running: INITIATOR
...

🎯 [ORCHESTRATOR] Cycle 2 of 20
   Phase: initialized β†’ Role: planner
...

🎯 [ORCHESTRATOR] Cycle 5 of 20
   Phase: building β†’ Role: developer
...

Phase State Machine

The orchestrator reads .knowledge/context/current.json and routes based on phase:

Phase Next Role Description
new INITIATOR Fresh project
initialized PLANNER Needs task breakdown
planned / building DEVELOPER Build features (multiple cycles)
reviewed / needs_fixes DEVELOPER Address review feedback
ready_for_staging MARKETER Update marketing pages first
(after marketer) DEPLOYER Then deploy to staging
deployment_failed DEVELOPER Fix deployment issues
staged / deployed βœ“ DONE Success!
blocked βœ— ABORT Something went wrong

Full Pipeline:

INITIATOR β†’ PLANNER β†’ DEVELOPER (Γ—N) β†’ REVIEWER β†’ DEVELOPER (fixes)
    β†’ MARKETER β†’ DEPLOYER β†’ βœ“ DONE

Single Role Mode

Run just one role (original behavior):

# Run a specific role
AGENT_ROLE=developer docker compose up --build

# Or for deployment only
AGENT_ROLE=deployer docker compose up --build

Helper Scripts (for local development)

These scripts run on your host machine and call docker compose repeatedly:

# Interactive - prompts y/n before each role
./orchestrate.sh my-project "Build a TODO app"

# Continuous development loop
./auto-cycle.sh my-project

How It Works

Agent Roles

The framework supports different operational modes:

Role Purpose Trigger
initiator Project setup from template New projects only
planner Strategic planning, prioritization After init
developer Build features, fix bugs, write code Main work loop
reviewer Code review, quality checks Every N dev cycles
marketer Update landing page & marketing copy Before deployment
deployer Vercel setup, branch promotions When ready for staging

Git Branching Strategy

The agent uses a three-branch release workflow:

release/dev     β†’    release/stage    β†’    release/prod
(Agent works)        (Auto-promoted)       (Human-only)
Branch Who Controls Vercel Environment
release/dev Agent (all roles) Preview
release/stage DEPLOYER role Preview (staging alias)
release/prod Human only Production

Use the helper script for branch management:

./git-workflow.sh status            # Show branch status
./git-workflow.sh promote-to-staging # Merge dev β†’ stage
./git-workflow.sh create-prod-pr    # Create PR for production

Knowledge-Driven Development

The agent reads from and writes to .knowledge/ to maintain state:

.knowledge/
β”œβ”€β”€ context/
β”‚   β”œβ”€β”€ project.json      # Project definition
β”‚   β”œβ”€β”€ objectives.json   # Goals and metrics
β”‚   └── current.json      # Current focus
β”œβ”€β”€ work/
β”‚   β”œβ”€β”€ backlog.json      # Future tasks
β”‚   β”œβ”€β”€ in-progress.json  # Active work
β”‚   └── completed.json    # Done (changelog)
β”œβ”€β”€ decisions/
β”‚   └── log.jsonl         # Decision history
└── metrics/
    └── latest.json       # Health metrics

⚠️ Important: The .knowledge/ directory is initialized from knowledge-template but all commits go to the project repository. The template's .git is removed after cloning to prevent accidental pushback. Never push changes to knowledge-template.

Build-in-Public Integration

The knowledge structure powers the boilerplate's Build in Public dashboard:

  • CurrentFocus widget shows context/current.json
  • TaskBoard displays work/*.json
  • DecisionFeed streams decisions/log.jsonl
  • Changelog page renders work/completed.json
  • MetricsPanel shows metrics/latest.json

This creates transparency for users and accountability for the agent.

Environment Variables

Core

Variable Required Description
ANTHROPIC_API_KEY Yes Your Anthropic API key
GITHUB_TOKEN For GitHub mode Personal access token with repo scope
PROJECT_NAME For GitHub mode Repository name (auto-prefixed with agent-)
KNOWLEDGE_TEMPLATE No GitHub repo with knowledge template
BUILD_TASK No Override task to execute
AGENT_ROLE No Role to run (default: developer)
LOG_FORMAT No json for raw output

Branching

Variable Default Description
PROJECT_BRANCH release/dev Development branch (agent works here)
STAGING_BRANCH release/stage Staging branch (pre-production)
PRODUCTION_BRANCH release/prod Production branch (human-controlled)
AUTO_MERGE_TO_STAGING false Auto-merge dev→stage when ready

Vercel Deployment

Variable Required Description
VERCEL_TOKEN For deployments Vercel API token
VERCEL_TEAM_ID For teams Team ID (optional for personal accounts)
VERCEL_ORG_ID For teams Organization ID
AUTO_SETUP_VERCEL No Auto-create Vercel project on init

Using the SaaS Boilerplate

Every product starts from the SaaS Boilerplate, which provides:

Pre-Built Features

  • βœ… Next.js 15 with App Router
  • βœ… Clerk Authentication
  • βœ… MongoDB with connection pooling
  • βœ… Stripe/Clerk Billing (subscriptions)
  • βœ… Tailwind CSS + shadcn/ui
  • βœ… Zod validation
  • βœ… Rate limiting
  • βœ… Sentry monitoring

Established Patterns

The boilerplate has strict conventions:

// API routes follow this pattern
export async function POST(request: NextRequest) {
  // 1. Authenticate
  const authResult = await authenticateRequest(request);
  if (!authResult) return unauthorizedResponse();
  
  // 2. Validate with Zod
  const validation = validateBody(schema, body);
  if (!validation.success) return errorResponse(validation.error);
  
  // 3. Check subscription limits
  const { allowed } = await checkFeatureLimit(userId, 'todos');
  if (!allowed) return errorResponse('Limit reached', 403);
  
  // 4. Execute and respond
  return NextResponse.json<ApiResponse<T>>({ success: true, data });
}

Adding Features

When extending the boilerplate:

  1. Types β†’ lib/types.ts
  2. Validation β†’ lib/validation/schemas.ts
  3. Collection β†’ lib/mongodb.ts
  4. API Routes β†’ app/api/{feature}/route.ts
  5. Components β†’ components/features/{feature}/
  6. Plan Limits β†’ config/plans.ts

Directory Structure

agent-framework/
β”œβ”€β”€ Dockerfile           # Container with Claude Code CLI
β”œβ”€β”€ entrypoint.sh        # Main execution script
β”œβ”€β”€ docker-compose.yml   # Local and GitHub modes
β”œβ”€β”€ env.example          # Example environment variables
β”œβ”€β”€ smart-orchestrate.sh # ⭐ State-based intelligent orchestration
β”œβ”€β”€ run-full-cycle.sh    # Simple fixed-sequence pipeline
β”œβ”€β”€ orchestrate.sh       # Interactive multi-role orchestration
β”œβ”€β”€ auto-cycle.sh        # Continuous development loop
β”œβ”€β”€ git-workflow.sh      # Branch management helper
β”œβ”€β”€ roles/               # Role-specific prompts
β”‚   β”œβ”€β”€ developer.txt
β”‚   β”œβ”€β”€ planner.txt
β”‚   β”œβ”€β”€ reviewer.txt
β”‚   β”œβ”€β”€ initiator.txt
β”‚   └── deployer.txt     # Vercel & branch promotions
β”œβ”€β”€ config/              # Configuration files
β”œβ”€β”€ output/              # Local mode output (gitignored)
β”œβ”€β”€ CLAUDE.md            # Agent coding standards
└── README.md

Creating a GitHub Token

  1. Go to GitHub β†’ Settings β†’ Developer settings β†’ Personal access tokens
  2. Generate new token (classic)
  3. Select scopes: repo (full control of private repositories)
  4. Copy the token to your .env file

Roadmap

  • Basic Claude Code integration
  • GitHub repository management
  • Knowledge store initialization
  • Role-based prompting
  • Release branch workflow (dev β†’ stage β†’ prod)
  • Deployer role for promotions
  • Vercel integration preparation
  • End-to-end automated pipeline (run-full-cycle.sh)
  • Continuous development cycles (auto-cycle.sh)
  • Scheduled runs (cron, GitHub Actions)
  • Multi-project orchestration (matrix workflows)
  • Vercel API integration (auto-setup)
  • Self-update mechanism
  • Cost tracking and budgets

Related Documentation


Part of the Comet Apps ecosystem β€” Autonomous AI agents building and operating SaaS products.

About

Autonomous AI agent that builds and operates SaaS products

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published