Skip to content

ajsai47/factory

Repository files navigation

  ███████╗ █████╗  ██████╗████████╗ ██████╗ ██████╗ ██╗   ██╗
  ██╔════╝██╔══██╗██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗╚██╗ ██╔╝
  █████╗  ███████║██║        ██║   ██║   ██║██████╔╝ ╚████╔╝
  ██╔══╝  ██╔══██║██║        ██║   ██║   ██║██╔══██╗  ╚██╔╝
  ██║     ██║  ██║╚██████╗   ██║   ╚██████╔╝██║  ██║   ██║
  ╚═╝     ╚═╝  ╚═╝ ╚═════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═╝   ╚═╝

Ticket in. PR out. That's it.

Five AI agents. One pipeline. Zero babysitting.

PyPI CI License Python


pip install factory-agent
factory init
factory run GHO-42
# go review your PR >>>

Factory is an autonomous coding agent. Give it a Linear ticket — it reads your codebase, writes the implementation, adds tests, reviews its own work, runs a security scan, opens a PR, and comments back on Linear. Five specialized agents, each with constrained permissions, collaborating in a pipeline that gets smarter with every run.


The Pipeline

  ╔══════════════════════════════════════════════════════════════════╗
  ║                        factory run TEAM-42                      ║
  ╚════════════════════════════════╦═════════════════════════════════╝
                                   ║
                                   ▼
                    ┌──────────────────────────────┐
                    │         ATLAS  ◈  opus       │
                    │         ─────────────         │
                    │    Orchestrator. Plans the    │
                    │    work, delegates tasks,     │
                    │    never writes a line of     │
                    │    code. Ever.                │
                    └──────────────┬───────────────┘
                                   │
                 ┌─────────────────┼─────────────────┐
                 │                 │                  │
                 ▼                 ▼                  ▼
  ┌─────────────────────┐ ┌──────────────┐ ┌─────────────────────┐
  │  SCOUT  ◈  sonnet   │ │   BUILDER    │ │  CIPHER  ◈  haiku   │
  │  ───────────────     │ │   ◈  opus    │ │  ───────────────     │
  │  Read-only recon.    │ │   ────────   │ │  Security scan.      │
  │  Maps your codebase, │ │   The only   │ │  OWASP top 10,       │
  │  finds patterns,     │ │   agent that │ │  injection vectors,  │
  │  gathers context.    │ │   writes     │ │  leaked secrets,     │
  │                      │ │   code.      │ │  auth bypasses.      │
  │  🔒 read-only        │ │              │ │                      │
  └──────────┬──────────┘ │   Implements, │ │  🔒 read-only        │
             │            │   tests,      │ └──────────┬──────────┘
             └──────────► │   verifies.   │ ◄──────────┘
                          └──────┬───────┘
                                 │
                        ┌────────▼────────┐
                        │  LENS  ◈  haiku │
                        │  ──────────     │
                        │  Quality gate.  │
                        │                 │        ┌──────────────┐
                        │  APPROVE ───────────────►│  Open PR +   │
                        │                 │        │  Comment on  │
                        │  REJECT ──┐     │        │  Linear      │
                        └───────────┘     │        └──────────────┘
                              │           │
                              ▼           │
                        Retry Builder     │
                        (max 2x)          │

Why five agents instead of one? Single-agent systems fail in predictable ways — they lose context mid-task, skip tests, or introduce security holes because one model is doing everything. Factory enforces separation of concerns at the agent level. Scout can't modify code. Builder can't skip review. Lens can't be sweet-talked into approving bad code. Each agent does one thing well.


Quickstart

01 Install

pip install factory-agent

02 Configure

factory init

60-second interactive wizard:

  ┌─────────────────────────────────────────────┐
  │              Factory Setup                   │
  ├─────────────────────────────────────────────┤
  │                                              │
  │  1/4  Anthropic API Key ··········· ✓ Valid  │
  │  2/4  GitHub PAT ·················· ✓ Auth'd │
  │  3/4  Linear API Key ·············· ✓ Auth'd │
  │  4/4  Repository ·· Detected: org/repo  ✓   │
  │                                              │
  │  Config saved to .factory/config.yaml        │
  └─────────────────────────────────────────────┘

03 Run

# Full URL or just the identifier — both work
factory run https://linear.app/your-team/issue/TEAM-123
factory run TEAM-123

04 Watch (autonomous mode)

# Poll Linear every 5 minutes, process new tickets automatically
factory watch

# Custom interval
factory watch --interval 120

Set it and forget it. Factory picks up tickets and ships PRs while you sleep.


CLI

  Usage: factory <command> [options]

  Commands:
    init                     Configure API keys and repo (interactive)
    run <ticket>             Process a single Linear ticket → PR
    watch [--interval N]     Poll Linear continuously, auto-process tickets
    status                   Show recent pipeline runs
    status --costs           Show token usage and spend breakdown
    status --patterns        Show what the agent has learned

Memory

Factory gets smarter over time. A persistent memory layer records what works and what fails, then injects those learnings into future runs.

  Run 1    ███████████████████████████████████░░░░░  8 min
  Run 5    █████████████████████████░░░░░░░░░░░░░░  6 min
  Run 10   ███████████████████░░░░░░░░░░░░░░░░░░░  4 min
           ↑ same codebase, same complexity — agent learned the patterns
Layer What it learns
Patterns Weighted strategies — wins get boosted, failures get suppressed. Auto-injected into future prompts.
Observations Codebase facts — file structure, naming conventions, test framework, import patterns.
Runs Full execution history — timing, token usage, outcomes, agent transitions.
factory status --patterns

#  0.85  pytest + conftest fixtures for DB tests  (12W/2L)
#  0.72  Use existing API client in lib/api/       (8W/1L)
# -0.40  Direct SQL queries in route handlers      (1W/4L)

Architecture

  ┌─────────────┐         ┌──────────────────┐         ┌─────────────┐
  │             │         │                  │         │             │
  │   Linear    │────────►│     Factory      │────────►│   GitHub    │
  │   ticket    │         │     pipeline     │         │   PR        │
  │             │         │                  │         │             │
  └─────────────┘         └────────┬─────────┘         └─────────────┘
                                   │
                          ┌────────▼─────────┐
                          │     Memory       │
                          │     ┄┄┄┄┄┄       │
                          │  SQLite (local)  │
                          │  Postgres (prod) │
                          └──────────────────┘

  Models:
    ◈ opus    → Atlas, Builder     (planning + code — quality matters)
    ◈ sonnet  → Scout              (analysis — balance of speed + depth)
    ◈ haiku   → Lens, Cipher       (review + security — speed matters)

  Cost per ticket: ~$2–8 depending on complexity

Built on LangGraph + Claude (Anthropic API). Each agent runs sandboxed with constrained tool access.


Configuration

.factory/config.yaml — created by factory init, auto-gitignored:

# API Keys
anthropic_api_key: sk-ant-...
github_token: ghp_...
linear_api_key: lin_api_...

# Repository
repo:
  owner: your-org
  name: your-repo

# Linear team
linear:
  team_id: your-team-uuid
  team_name: YourTeam

# Guardrails (all optional, sensible defaults)
model: anthropic:claude-opus-4-6
max_tokens_per_run: 500000      # 500K token cap per run
max_daily_runs: 20              # max pipeline runs per day
max_daily_cost: 50.0            # max spend per day (USD)

Environment variables override config: ANTHROPIC_API_KEY, GITHUB_TOKEN, LINEAR_API_KEY.


Cost Controls

Factory won't surprise you with a bill. Spending limits are enforced before every run:

  ┌──────────────────────┬──────────┬────────────────────────────────┐
  │ Control              │ Default  │ What it does                   │
  ├──────────────────────┼──────────┼────────────────────────────────┤
  │ max_daily_runs       │ 20       │ Hard cap on runs per day       │
  │ max_daily_cost       │ $50      │ Estimated spend ceiling (USD)  │
  │ max_tokens_per_run   │ 500K     │ Token budget per pipeline run  │
  └──────────────────────┴──────────┴────────────────────────────────┘
factory status --costs
#  Today's runs: 7
#  Input tokens: 142,000
#  Output tokens: 38,000
#  Estimated cost: $12.40

Self-Hosting

For always-on, webhook-driven operation:

pip install "factory-agent[server]"
SANDBOX_TYPE=local langgraph dev

The [server] extra adds FastAPI, uvicorn, and cloud sandbox providers (Daytona, Modal, Runloop). Accepts inbound webhooks from Linear, Slack, and GitHub.

See INSTALLATION.md for Docker Compose and Fly.io deployment.


Development

git clone https://github.com/ajsai47/factory.git
cd factory
pip install -e ".[dev,server]"
pytest  # 71 tests

Apache 2.0 — see LICENSE

Built on Open SWE by LangChain (MIT) — see NOTICE

About

Factory: Multi-agent autonomous coding pipeline

Resources

License

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages