Agent Mode Tutorialยถ

Master autonomous code generation with SRBN.

Overviewยถ

Agent Mode lets Perspt autonomously write, test, and verify code using the Stabilized Recursive Barrier Network (SRBN) engine.

Prerequisitesยถ

  • Perspt v0.5.0+ installed

  • API key for a capable model (GPT-5.2, Claude Opus 4.5 recommended)

  • Python 3.9+ (for LSP integration)

Basic Usageยถ

# Simple task
perspt agent "Create a Python calculator"

# With workspace
perspt agent -w ./my-project "Add unit tests"

# Auto-approve all
perspt agent -y "Refactor error handling"

Step-by-Step Exampleยถ

Letโ€™s create a Python calculator:

Step 1: Start the Agentยถ

mkdir calculator-demo && cd calculator-demo
perspt agent "Create a Python calculator with add, subtract, multiply, divide operations. Include type hints and a comprehensive test suite."

Step 2: Watch the SRBN Loopยถ

The agent will:

  1. Sheafify: Decompose into subtasks

    {
      "nodes": [
        {"id": 1, "description": "Create Calculator class"},
        {"id": 2, "description": "Add arithmetic methods"},
        {"id": 3, "description": "Write unit tests"}
      ]
    }
    
  2. Speculate: Generate code for each node

  3. Verify: Check with LSP and tests

    V(x) = 1.0ยทV_syn + 0.5ยทV_str + 2.0ยทV_log
    V_syn = 0 (no LSP errors)
    V_str = 0.1 (clean structure)
    V_log = 0 (all tests pass)
    V(x) = 0.05 < ฮต (stable!)
    
  4. Commit: Record in ledger

Step 3: Review Changesยถ

When prompted, review the generated code:

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚  Review Changes                                     โ”‚
โ•žโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ก
โ”‚  + calculator.py   (new file, 45 lines)            โ”‚
โ”‚  + test_calculator.py (new file, 62 lines)         โ”‚
โ”‚                                                     โ”‚
โ”‚  [y] Approve  [n] Reject  [d] View Diff            โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Step 4: Check Resultsยถ

# View generated files
ls -la
# calculator.py
# test_calculator.py

# Run tests
python -m pytest test_calculator.py -v

Model Tier Configurationยถ

Use specialized models for different SRBN phases:

perspt agent \
  --architect-model gpt-5.2 \
  --actuator-model claude-opus-4.5 \
  --verifier-model gemini-3-pro \
  --speculator-model gemini-3-flash \
  "Build a REST API"

Tier

Purpose

Recommendation

Architect

Task decomposition

Deep reasoning (GPT-5.2)

Actuator

Code generation

Strong coding (Claude)

Verifier

Stability check

Fast analysis (Gemini Pro)

Speculator

Branch prediction

Ultra-fast (Gemini Flash)

Energy Tuningยถ

Customize the Lyapunov energy weights:

# Prioritize test passing (higher ฮณ)
perspt agent --energy-weights "1.0,0.5,3.0" "Add tests"

# Prioritize type safety (higher ฮฑ)
perspt agent --energy-weights "2.0,0.5,1.0" "Add type hints"

Execution Modesยถ

Mode

Behavior

cautious

Prompt for approval on every change

balanced

Prompt when complexity > K (default)

yolo

Auto-approve everything (dangerous!)

perspt agent --mode cautious "Modify database schema"

Complexity Thresholdยถ

Control when to prompt for approval:

# Approve up to 3 files without prompting
perspt agent -k 3 "Refactor module"

# Always prompt (k=0)
perspt agent -k 0 "Any task"

Cost and Step Limitsยถ

# Maximum $5 cost
perspt agent --max-cost 5.0 "Large refactor"

# Maximum 10 iterations
perspt agent --max-steps 10 "Iterative improvement"

Managing Sessionsยถ

# Check status
perspt status

# Abort current
perspt abort

# Resume interrupted
perspt resume

Change Trackingยถ

# View history
perspt ledger --recent

# Rollback
perspt ledger --rollback abc123

# Statistics
perspt ledger --stats

LLM Logging and Debuggingยถ

Enable LLM request logging for debugging:

# Log all LLM requests to database
perspt agent --log-llm "Debug task"

# Defer tests until sheaf validation (faster iteration)
perspt agent --defer-tests "Rapid prototyping"

View logged requests:

# Interactive TUI viewer
perspt logs --tui

# Most recent session
perspt logs --last

# Usage statistics
perspt logs --stats

Best Practicesยถ

  1. Start small: Test with simple tasks first

  2. Use workspace: Always specify -w for clarity

  3. Set limits: Use --max-cost and --max-steps

  4. Review carefully: Check diffs before approving

  5. Use tiers: Match models to task requirements

  6. Track changes: Use perspt ledger regularly

Troubleshootingยถ

Agent stuck in retry loop:

  • Check LSP is working: ty check file.py

  • Lower stability threshold: --stability-threshold 0.5

  • Reduce energy weights for less strict verification

High energy despite clean code:

  • Check test failures: pytest -v

  • Review LSP diagnostics

  • Adjust weights: --energy-weights "0.5,0.5,1.0"

See Alsoยถ