defi-agents

๐Ÿ”„ Complete Development Workflow

Comprehensive guide to the entire agent lifecycle: from creation โ†’ translation โ†’ build โ†’ deployment


๐Ÿ“‹ Table of Contents


Overview

This repository uses an automated workflow that takes agent definitions and:

  1. โœ… Translates them to 18 languages
  2. โœ… Builds a CDN-ready index
  3. โœ… Deploys to GitHub Pages
  4. โœ… Preserves custom domains automatically

Key Principle: Submit in English, everything else is automatic.


Quick Reference

For Contributors

# 1. Create agent
echo '{ ... }' > src/my-agent.json

# 2. Submit PR
git add src/my-agent.json
git commit -m "feat: Add My Agent"
git push

# Done! CI handles translation + deployment

For Maintainers

# Setup
git clone https://github.com/yourusername/defi-agents
cd defi-agents
bun install
echo "OPENAI_API_KEY=sk-xxx" > .env

# Development cycle
bun run format # Translate agents
bun run build  # Build public index
bun run test   # Validate everything

# Deploy (automatic on push to main)
git push origin main

Architecture

Directory Structure

defi-agents/
โ”œโ”€โ”€ CNAME                          # Your custom domain (optional)
โ”œโ”€โ”€ .env                           # Local environment variables (gitignored)
โ”‚   โ””โ”€โ”€ OPENAI_API_KEY=sk-xxx
โ”‚
โ”œโ”€โ”€ src/                           # ๐Ÿ“ Agent source files (English only)
โ”‚   โ”œโ”€โ”€ agent-1.json
โ”‚   โ”œโ”€โ”€ agent-2.json
โ”‚   โ””โ”€โ”€ sperax-dashboard.json
โ”‚
โ”œโ”€โ”€ locales/                       # ๐ŸŒ 18-language translations (auto-generated)
โ”‚   โ”œโ”€โ”€ agent-1/
โ”‚   โ”‚   โ”œโ”€โ”€ index.json             # en-US (default)
โ”‚   โ”‚   โ”œโ”€โ”€ index.zh-CN.json       # Chinese
โ”‚   โ”‚   โ”œโ”€โ”€ index.es-ES.json       # Spanish
โ”‚   โ”‚   โ””โ”€โ”€ ... (18 total)
โ”‚   โ””โ”€โ”€ agent-2/
โ”‚       โ””โ”€โ”€ ... (18 files)
โ”‚
โ”œโ”€โ”€ public/                        # ๐Ÿš€ Build output (gitignored, generated)
โ”‚   โ”œโ”€โ”€ CNAME                      # Copied from root during build
โ”‚   โ”œโ”€โ”€ index.json                 # Main agent index
โ”‚   โ”œโ”€โ”€ index.zh-CN.json           # Localized indexes
โ”‚   โ”œโ”€โ”€ agent-1.json               # Individual agents
โ”‚   โ”œโ”€โ”€ agent-1.zh-CN.json         # Localized agents
โ”‚   โ””โ”€โ”€ schema/
โ”‚       โ””โ”€โ”€ speraxAgentSchema_v1.json
โ”‚
โ”œโ”€โ”€ .github/workflows/
โ”‚   โ””โ”€โ”€ release.yml                # CI/CD automation
โ”‚
โ””โ”€โ”€ scripts/
    โ”œโ”€โ”€ commands/
    โ”‚   โ”œโ”€โ”€ format.ts              # Translation engine
    โ”‚   โ””โ”€โ”€ build.ts               # Build engine
    โ””โ”€โ”€ builders/
        โ””โ”€โ”€ agent-builder.ts       # Includes CNAME copy logic

Data Flow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    DEVELOPMENT CYCLE                         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

1. CREATE AGENT
   โ””โ”€ Write src/agent-name.json (English only)

2. TRANSLATE (bun run format)
   โ”œโ”€ Validate JSON schema
   โ”œโ”€ Generate missing fields (category, examples)
   โ”œโ”€ Call OpenAI API (GPT-4)
   โ”œโ”€ Translate to 18 languages
   โ””โ”€ Create locales/agent-name/*.json (18 files)

3. BUILD (bun run build)
   โ”œโ”€ Merge src + locales
   โ”œโ”€ Generate public index files
   โ”œโ”€ Copy CNAME to public/ (if exists)
   โ””โ”€ Create CDN-ready distribution

4. DEPLOY (automatic on push)
   โ”œโ”€ GitHub Actions triggers
   โ”œโ”€ Runs format โ†’ build
   โ”œโ”€ Deploys public/ to gh-pages branch
   โ””โ”€ GitHub Pages serves at your domain

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                      LIVE WEBSITE                            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
   https://yourdomain.com/index.json
   โ””โ”€ Agents available in 18 languages

Full Workflow

Step 1: Create Agent Source

Create a new agent in src/:

# Create agent file
touch src/my-defi-agent.json
{
  "author": "your-github-username",
  "config": {
    "systemRole": "You are a DeFi expert specializing in...",
    "openingMessage": "Hello! I can help you with...",
    "openingQuestions": ["What's the best yield strategy?", "How do I minimize impermanent loss?"]
  },
  "createdAt": "2024-12-21",
  "examples": [
    {
      "role": "user",
      "content": "Explain DeFi yield farming"
    },
    {
      "role": "assistant",
      "content": "Yield farming is..."
    }
  ],
  "homepage": "https://github.com/nirholas/AI-Agents-Library",
  "identifier": "my-defi-agent",
  "meta": {
    "title": "My DeFi Agent",
    "description": "Expert DeFi advisor for yield optimization",
    "avatar": "๐ŸŒพ",
    "tags": ["defi", "yield", "optimization"],
    "category": "trading"
  },
  "schemaVersion": 1
}

Step 2: Run Translation

# Set API key (first time only)
echo "OPENAI_API_KEY=sk-your-key" > .env

# Run translation
bun run format

What happens:

Output:

locales/
  my-defi-agent/
    โ”œโ”€โ”€ index.json        # en-US (default)
    โ”œโ”€โ”€ index.ar.json     # Arabic
    โ”œโ”€โ”€ index.zh-CN.json  # Simplified Chinese
    โ””โ”€โ”€ ... (18 total)

Step 3: Build Public Index

bun run build

What happens:

Output:

public/
  โ”œโ”€โ”€ CNAME                    # Your custom domain
  โ”œโ”€โ”€ index.json               # Main index (en-US)
  โ”œโ”€โ”€ index.zh-CN.json         # Chinese index
  โ”œโ”€โ”€ my-defi-agent.json       # Your agent (en-US)
  โ”œโ”€โ”€ my-defi-agent.zh-CN.json # Your agent (Chinese)
  โ””โ”€โ”€ ... (58 agents ร— 18 languages = 1,044 files)

Step 4: Test Locally (Optional)

# Serve locally to test
npx serve public

# Open http://localhost:3000/index.json

Step 5: Commit and Push

# Add source + translations
git add src/ locales/

# Commit (do NOT add public/ - it's gitignored)
git commit -m "feat: Add My DeFi Agent"

# Push to trigger CI/CD
git push origin main

Step 6: Automatic Deployment

GitHub Actions automatically:

  1. โœ… Runs bun run format (translates)
  2. โœ… Runs bun run build (builds)
  3. โœ… Deploys public/ to gh-pages branch
  4. โœ… GitHub Pages serves your site

Live in ~5 minutes at:


Local Development

First-Time Setup

# 1. Clone repository
git clone https://github.com/yourusername/defi-agents
cd defi-agents

# 2. Install dependencies
bun install

# 3. Configure OpenAI API key
echo "OPENAI_API_KEY=sk-xxx" > .env

Development Commands

# Format & translate agents
bun run format

# Build public distribution
bun run build

# Run tests
bun run test

# Validate translations
bun run i18n:validate

# Clean invalid translations
bun run i18n:clean

# Lint markdown docs
bun run lint:md

# Format all code
bun run prettier

# Full release pipeline (format + build + update README)
bun run awesome

Typical Development Loop

# 1. Create or edit agent
vim src/my-agent.json

# 2. Translate
bun run format

# 3. Build
bun run build

# 4. Test
bun run test

# 5. Commit
git add src/ locales/
git commit -m "feat: Add my agent"

# 6. Push (triggers CI/CD)
git push origin main

CI/CD Pipeline

GitHub Actions Workflow

File: .github/workflows/release.yml

Triggers: Every push to main branch

Steps:

  1. Checkout - Fetch repository
  2. Install Bun - Setup runtime
  3. Install Dependencies - bun install
  4. Run Tests - Validate agents
  5. Format & Translate - bun run format (uses OPENAI_API_KEY secret)
  6. Update README - bun run awesome
  7. Lint & Prettier - Code formatting
  8. Commit Changes - Auto-commit translations
  9. Deploy to GitHub Pages - Deploy public/ to gh-pages branch

Required Secrets

Set in Repository Settings โ†’ Secrets and variables โ†’ Actions:

Build Process Details

The build step (bun run build) calls agent-builder.ts which:

  1. Builds Schema
    • Generates JSON schema from Zod definitions
    • Writes to schema/ and public/schema/
  2. Builds Agents (for each of 18 languages)
    • Reads src/*.json (English source)
    • Reads locales/agent-name/index.[locale].json
    • Merges source + translation
    • Writes to public/agent-name.[locale].json
  3. Generates Indexes (for each of 18 languages)
    • Collects all agents
    • Extracts metadata
    • Calculates tag frequencies
    • Writes to public/index.[locale].json
  4. Copies CNAME
    • Checks if CNAME exists in root
    • Copies to public/CNAME (if exists)
    • Ensures custom domain persists

Code Reference: scripts/builders/agent-builder.ts

run = async () => {
  this.buildSchema(); // Generate schema
  await this.buildFullLocaleAgents(); // Build all languages
  this.copyCNAME(); // Copy CNAME
};

Domain Management

Option 1: Use Default GitHub Pages Domain

For: Personal projects, testing, forks

# Delete CNAME file
rm CNAME
git add CNAME
git commit -m "Use default GitHub Pages domain"
git push

Your site: https://username.github.io/defi-agents/

Option 2: Use Custom Domain

For: Production, branded deployments

# 1. Update CNAME file
echo "yourdomain.com" > CNAME
git add CNAME
git commit -m "Set custom domain"
git push

# 2. Configure DNS (in your domain registrar)
# Add CNAME record: yourdomain.com โ†’ username.github.io

# 3. Enable HTTPS in GitHub
# Settings โ†’ Pages โ†’ Enforce HTTPS (after DNS propagates)

Your site: https://yourdomain.com/

CNAME Handling Details

Why it works:

  1. CNAME file is stored in repository root
  2. Build process (agent-builder.ts) copies it to public/CNAME
  3. GitHub Actions deploys public/ directory (including CNAME)
  4. GitHub Pages reads CNAME and serves site at custom domain

For forks:

Implementation: scripts/builders/agent-builder.ts

copyCNAME = () => {
  const cnamePath = resolve(root, 'CNAME');
  const publicCNAMEPath = resolve(publicDir, 'CNAME');

  if (existsSync(cnamePath)) {
    copyFileSync(cnamePath, publicCNAMEPath);
    Logger.success('CNAME ๆ–‡ไปถๅทฒๅคๅˆถๅˆฐ public ็›ฎๅฝ•');
  }
};

For Contributors

Submitting a New Agent

  1. Fork the repository
  2. Create agent: src/your-agent.json
  3. Submit PR (translation happens in CI)

You do NOT need to:

CI will automatically:

PR Review Process

  1. Maintainer reviews src/your-agent.json
  2. If approved, PR is merged to main
  3. CI runs format + build + deploy
  4. Agent appears at marketplace within 5 minutes

For Fork Maintainers

Initial Setup

# 1. Fork on GitHub
# Click "Fork" button

# 2. Clone your fork
git clone https://github.com/yourusername/defi-agents
cd defi-agents

# 3. Set up custom domain (optional)
echo "yourdomain.com" > CNAME
# Or delete CNAME for default GitHub Pages URL

# 4. Configure GitHub secrets
# Go to Settings โ†’ Secrets โ†’ Actions
# Add: OPENAI_API_KEY

# 5. Enable GitHub Pages
# Settings โ†’ Pages โ†’ Source: gh-pages branch

# 6. Push to trigger first deployment
git add CNAME # or git rm CNAME
git commit -m "Configure domain"
git push origin main

Maintaining Your Fork

Keep agents in sync with upstream:

# Add upstream remote
git remote add upstream https://github.com/nirholas/defi-agents

# Sync with upstream
git fetch upstream
git merge upstream/main

# Rebuild with your agents
bun run format
bun run build

# Push
git push origin main

Add your own agents:

# Create agent
vim src/my-custom-agent.json

# Commit and push (CI handles rest)
git add src/my-custom-agent.json
git commit -m "feat: Add my custom agent"
git push origin main

Summary

Complete Lifecycle:

Developer โ†’ Create agent.json โ†’ Push to GitHub
                โ†“
         GitHub Actions CI/CD
                โ†“
    format (translate to 18 languages)
                โ†“
    build (generate public index + copy CNAME)
                โ†“
    deploy (push to gh-pages branch)
                โ†“
         GitHub Pages CDN
                โ†“
    Live at your domain in 18 languages

Key Files:

Key Commands:



Questions? Open an issue or check the FAQ.


Alternative: Vercel Deployment

If GitHub Actions are disabled or you prefer Vercelโ€™s features (CORS control, analytics, rate limiting):

Quick Setup

  1. Import to Vercel: vercel.com/new
  2. Configure build:
    • Build Command: bun run build
    • Output Directory: public
  3. Add environment variable: OPENAI_API_KEY
  4. Deploy!

Manual Local Build for Vercel

# Install
bun install

# Translate agents (requires OpenAI API key)
export OPENAI_API_KEY=sk-your-key
bun run format

# Build
bun run build

# Or use the convenience script
./scripts/local-release.sh

When to Use Vercel vs GitHub Pages

Use Case Recommendation
GitHub Actions enabled GitHub Pages (automatic)
GitHub Actions disabled Vercel
Need CORS control Vercel
Need rate limiting Vercel
Need analytics Vercel
Simple, free hosting Either works

See Deployment Guide for complete details.