# AgenTeam

Adversarial agent team orchestration for [OpenCode](https://opencode.ai).

The orchestrator coordinates a planner, tiered coders, and a hostile code reviewer through a strictly enforced workflow: **triage → plan → execute → adversarial review → done**.

Every task is reviewed by an adversary agent before it can be marked complete. The reviewer is designed to find problems, not confirm correctness. This catches bugs, missing tests, and security holes that the coding agent misses.

## Quick Start

> **Run inside your project directory.** AgenTeam creates project-scoped config and state.
> It detects common project markers (`package.json`, `pyproject.toml`, `Cargo.toml`, `.git`) and warns if none are found.

```bash
cd your-project
npx agenteam init
```

The setup wizard will:
1. Read your configured models from OpenCode
2. Ask which to use for smart and cheap tiers
3. Ask whether to enable semantic memory
4. Create `agenteam.config.json` and `.agenteam/` state
5. Register the plugin globally

Then start OpenCode and press **Tab** to switch to the **orchestrator** agent.

## Reconfigure

```bash
npx agenteam config
```

Re-runs the model selection wizard on an existing project. Restart OpenCode to apply.

## Uninstall

```bash
cd your-project
npx agenteam uninstall
```

Removes all AgenTeam artifacts from the current project:
- `.agenteam/` directory (state, logs, memory index)
- `agenteam.config.json`
- `.agenteam/` entry from `.gitignore`
- Plugin registration from `~/.config/opencode/opencode.json`

## How It Works

### Workflow

```
Request → Triage → Plan → Execute → Adversary Review → Done
```

1. **Triage** — Deterministic scoring (0 tokens). Analyzes file count, LOC, imports, risk keywords. Classifies as simple/complex.
2. **Plan** — Complex tasks get a DAG of tasks from the planner. You confirm before execution starts.
3. **Execute** — Tasks run in parallel when possible. Coder agents implement, run lint, write tests.
4. **Adversary Review** — A hostile reviewer checks every task for bugs, missing tests, and correctness. The review gate is mechanically enforced — tasks cannot complete without passing.
5. **Done** — All tasks pass review, state is finalized.

### Agents

| Agent | Tier | Role |
|-------|------|------|
| **orchestrator** | smart | Coordinates workflow. Never writes code. |
| **planner** | smart | Generates task DAGs from complex requests. |
| **coder** | cheap | Simple tasks: scaffolding, boilerplate, tests. |
| **coder-hard** | smart | Complex tasks: architecture, integrations, algorithms. |
| **adversary** | smart | Hostile code review. Finds bugs, missing tests, security holes. |

### Two-Tier Model System

AgenTeam uses two model tiers to balance cost and quality:

- **Smart** — Used for the orchestrator, planner, complex coding, and adversary review. Needs strong reasoning.
- **Cheap** — Used for simple coding tasks. Fast and cheap.

The wizard picks the right model for each tier from your OpenCode providers.

### Adversarial Review

Every task goes through adversarial review before completion. This is enforced mechanically by the review gate — the orchestrator cannot mark a task as done until the adversary passes it.

The adversary agent:
- Reviews the git diff of changes
- Checks for bugs, missing error handling, type issues, security holes
- Verifies tests exist and actually test the right thing
- Defaults to failing — only passes if it genuinely finds no issues

### Memory (optional)

When enabled, AgenTeam stores product and technical decisions across sessions using local vector search. No external APIs — everything stays in `.agenteam/memory/`.

- Relevant past decisions are auto-injected after triage
- Query manually with `agenteam_memory(query)` for detailed lookups

First run downloads the embedding model (~22MB, cached after).

## Configuration

Config lives in `agenteam.config.json` at your project root. Created by the wizard, but you can edit it directly:

```json
{
  "models": {
    "cheap": "groq/llama-3.1-8b",
    "smart": "anthropic/claude-sonnet-4-20250514"
  },
  "limits": {
    "max_review_retries": 3,
    "escalation": "smart"
  },
  "triage": {
    "simple_max_files": 2,
    "risk_keywords": ["refactor", "migrate", "security", "auth", "database", "schema", "deploy", "infrastructure"]
  },
  "review": {
    "lint_command": null,
    "always_adversary": true
  },
  "adversary_model": "smart",
  "memory": {
    "enabled": true,
    "embedding_model": "Xenova/all-MiniLM-L6-v2",
    "max_auto_results": 5,
    "max_auto_tokens": 100,
    "similarity_threshold": 0.7,
    "auto_inject_on_triage": true
  }
}
```

### Key Settings

| Setting | Default | Description |
|---------|---------|-------------|
| `models.cheap` | — | Model for simple tasks (coder). Set by wizard. |
| `models.smart` | — | Model for complex tasks. Set by wizard. |
| `review.always_adversary` | `true` | Require adversary review for all tasks |
| `adversary_model` | `"smart"` | Which model tier the adversary uses |
| `memory.enabled` | `false` | Enable semantic memory across sessions |
| `limits.max_review_retries` | `3` | Max retry attempts before escalation |
| `triage.risk_keywords` | [...] | Keywords that trigger `risk: "high"` |

### Model Requirements

- **Smart model** needs strong reasoning for planning, complex coding, and code review
- **Cheap model** should be fast for straightforward tasks
- Both must be configured as `provider/model` format in OpenCode (e.g. `anthropic/claude-sonnet-4-20250514`)

## CLI Commands

```
npx agenteam init       Setup wizard (run in project directory)
npx agenteam config     Re-run model configuration
npx agenteam uninstall  Remove all AgenTeam files from this project
npx agenteam enable     Register plugin globally
npx agenteam disable    Remove plugin globally
```

## Project Files

```
your-project/
├── agenteam.config.json    # Project config (created by wizard)
├── .agenteam/              # Runtime state (gitignored)
│   ├── state.json          # Current workflow state
│   ├── log.jsonl           # Event log
│   ├── debug.jsonl         # Verbose debug trace
│   └── memory/             # Vector index + content (if enabled)
```

## Development

```bash
git clone https://github.com/aitorch/agenteam.git
cd agenteam
npm install
npm run typecheck
```

Test with: `ocx oc -p agenteam`

## License

MIT
