Metadata-Version: 2.4
Name: factory-agent
Version: 0.1.0
Summary: Factory — AI engineer that picks up tickets and ships code
Project-URL: Homepage, https://github.com/ajsai47/factory
Project-URL: Repository, https://github.com/ajsai47/factory
Project-URL: Issues, https://github.com/ajsai47/factory/issues
Author: AJ Green
License: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Keywords: agent,ai,autonomous,coding,linear
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development
Requires-Python: >=3.11
Requires-Dist: click>=8.1.0
Requires-Dist: deepagents>=0.4.3
Requires-Dist: httpx>=0.25.0
Requires-Dist: langchain-anthropic>1.1.0
Requires-Dist: langchain>=1.2.9
Requires-Dist: langgraph-sdk>=0.1.0
Requires-Dist: langgraph>=1.0.8
Requires-Dist: langsmith>=0.7.1
Requires-Dist: markdownify>=1.2.2
Requires-Dist: pyyaml>=6.0
Requires-Dist: rich>=13.0.0
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
Requires-Dist: pytest>=7.0.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Provides-Extra: server
Requires-Dist: cryptography>=41.0.0; extra == 'server'
Requires-Dist: fastapi>=0.104.0; extra == 'server'
Requires-Dist: langchain-daytona>=0.0.3; extra == 'server'
Requires-Dist: langchain-modal>=0.0.2; extra == 'server'
Requires-Dist: langchain-openai==1.1.10; extra == 'server'
Requires-Dist: langchain-runloop>=0.0.3; extra == 'server'
Requires-Dist: langgraph-cli[inmem]>=0.4.12; extra == 'server'
Requires-Dist: psycopg2-binary>=2.9.0; extra == 'server'
Requires-Dist: pyjwt>=2.8.0; extra == 'server'
Requires-Dist: uvicorn>=0.24.0; extra == 'server'
Description-Content-Type: text/markdown

<p align="center">
  <h1 align="center">Factory</h1>
  <p align="center">
    <strong>Your AI engineer. Assign a ticket, get a PR.</strong>
  </p>
  <p align="center">
    <a href="https://pypi.org/project/factory-agent/"><img src="https://img.shields.io/pypi/v/factory-agent.svg?style=flat-square" alt="PyPI"></a>
    <a href="https://github.com/ajsai47/factory/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/ajsai47/factory/ci.yml?style=flat-square&label=CI" alt="CI"></a>
    <a href="https://opensource.org/licenses/Apache-2.0"><img src="https://img.shields.io/badge/License-Apache_2.0-blue.svg?style=flat-square" alt="License"></a>
    <a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.11+-blue.svg?style=flat-square" alt="Python"></a>
  </p>
</p>

---

Factory is an autonomous coding agent that takes a Linear ticket and delivers a pull request — code, tests, review, security scan, and all. Five specialized AI agents collaborate in a pipeline that learns from every run.

```bash
pip install factory-agent
factory init          # 60-second setup wizard
factory run GHO-42    # ticket in, PR out
```

That's it. Go review your PR.

---

## How it works

When you run `factory run`, five agents execute a structured pipeline:

```
                         ┌─────────────────────┐
                         │      factory run     │
                         └──────────┬──────────┘
                                    │
                         ┌──────────▼──────────┐
                         │    Atlas (opus)      │
                         │    Orchestrator      │
                         │    Plans the work,   │
                         │    never writes code │
                         └──────────┬──────────┘
                                    │
              ┌─────────────────────┼─────────────────────┐
              │                     │                      │
   ┌──────────▼──────────┐  ┌──────▼───────┐  ┌──────────▼──────────┐
   │   Scout (sonnet)    │  │              │  │   Cipher (haiku)    │
   │   Read-only recon   │  │   Builder    │  │   Security scan     │
   │   Finds files,      │  │   (opus)     │  │   OWASP top 10,     │
   │   maps patterns,    │  │              │  │   injection,        │
   │   gathers context   │  │   Writes     │  │   secrets, auth     │
   └──────────┬──────────┘  │   code &     │  └──────────┬──────────┘
              │              │   tests      │              │
              └──────────►  │              │  ◄────────────┘
                            └──────┬───────┘
                                   │
                          ┌────────▼────────┐
                          │  Lens (haiku)   │
                          │  Quality gate   │
                          │                 │
                          │  APPROVE ──────────► commit & open PR
                          │                 │       │
                          │  REJECT ───┐    │       ▼
                          └────────────┘    │   Linear comment
                                │           │   with result
                                ▼           │
                          Back to Builder   │
                          (max 2 retries)   │
                                            │
```

Every agent has a single responsibility and constrained permissions. Scout and Lens are read-only — they can't modify your code. Builder writes but doesn't orchestrate. Atlas orchestrates but doesn't write. This separation prevents the failure modes of single-agent systems.

## Quickstart

### 1. Install

```bash
pip install factory-agent
```

### 2. Configure

```bash
factory init
```

Interactive wizard that:
- Validates your Anthropic API key
- Authenticates your GitHub PAT against the API
- Verifies your Linear API key
- Auto-detects your repo from `git remote`

Config is saved to `.factory/config.yaml` (auto-gitignored).

### 3. Run

```bash
# Process a single ticket
factory run https://linear.app/your-team/issue/TEAM-123

# Or just use the identifier
factory run TEAM-123
```

### 4. Watch (continuous mode)

```bash
# Poll Linear every 5 minutes, auto-process new tickets
factory watch

# Custom interval
factory watch --interval 120
```

## CLI Reference

```
factory init                    Interactive setup wizard
factory run <ticket>            Process a single Linear ticket
factory watch [--interval N]    Continuously poll and process tickets
factory status                  Show recent runs
factory status --costs          Show cost breakdown
factory status --patterns       Show learned patterns
```

## Memory: The agent that learns

Factory doesn't start from scratch every time. A persistent memory layer tracks what works and what doesn't across runs:

| Store | What it captures |
|-------|-----------------|
| **Patterns** | Weighted approaches — successful strategies get boosted, failures get suppressed. Injected into future prompts automatically. |
| **Observations** | Facts about your codebase gathered during runs — file structure, conventions, test patterns. |
| **Runs** | Full execution history with timing, token usage, and outcomes. |
| **Transitions** | Agent-to-agent handoff trace for debugging pipeline behavior. |

Run 1 might take 8 minutes. By run 10, the agent knows your codebase conventions, your test patterns, and which approaches work — and it's faster.

```bash
# See what the agent has learned
factory status --patterns
```

## Architecture

```
┌──────────────┐     ┌──────────────┐     ┌──────────────┐
│  Linear API  │────▶│   Factory    │────▶│   GitHub     │
│  (tickets)   │     │   Pipeline   │     │   (PRs)      │
└──────────────┘     └──────┬───────┘     └──────────────┘
                            │
                     ┌──────▼───────┐
                     │   Memory     │
                     │   (SQLite)   │
                     │              │
                     │  Patterns    │
                     │  Observations│
                     │  Run history │
                     └──────────────┘
```

**Agent stack**: Built on [LangGraph](https://github.com/langchain-ai/langgraph) with Claude (Opus, Sonnet, Haiku) via the Anthropic API. Each agent runs in a sandboxed environment with controlled tool access.

**Cost model**: Opus for planning and implementation (where quality matters), Haiku for review and security (where speed matters), Sonnet for analysis (balance of both). A typical ticket costs $2-8 depending on complexity.

## Configuration

`.factory/config.yaml`:

```yaml
anthropic_api_key: sk-ant-...
github_token: ghp_...
linear_api_key: lin_api_...

repo:
  owner: your-org
  name: your-repo

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

# Optional — all have sensible defaults
model: anthropic:claude-opus-4-6
max_tokens_per_run: 500000
max_daily_runs: 20
max_daily_cost: 50.0
```

Environment variables override config values: `ANTHROPIC_API_KEY`, `GITHUB_TOKEN`, `LINEAR_API_KEY`.

## Cost controls

Factory enforces spending limits so you don't wake up to a surprise bill:

| Control | Default | Description |
|---------|---------|-------------|
| `max_daily_runs` | 20 | Maximum pipeline runs per day |
| `max_daily_cost` | $50 | Maximum estimated spend per day |
| `max_tokens_per_run` | 500K | Token cap per individual run |

Budget checks run before each pipeline execution. If a limit is hit, the run is blocked with a clear message.

```bash
# Monitor spending
factory status --costs
```

## Self-hosting

Factory can also run as a LangGraph server for webhook-driven, always-on usage:

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

The `[server]` extra adds FastAPI, uvicorn, and cloud sandbox providers (Daytona, Modal, Runloop). This mode accepts inbound webhooks from Linear, Slack, and GitHub for fully automated ticket processing.

See [INSTALLATION.md](INSTALLATION.md) for Docker Compose and Fly.io deployment.

## Development

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

## License

Apache 2.0 — see [LICENSE](LICENSE).

Built on [Open SWE](https://github.com/langchain-ai/open-swe) by LangChain, Inc. (MIT). See [NOTICE](NOTICE) for attribution.
