# Setup guide — Purchase Order Matching Agent

## 1. Install and connect your ERP/AP system

Install the agent and connect it to the system holding POs, receipts, and invoices.

```
pipx install po-match-agent
po-match-agent connect --erp netsuite
po-match-agent doctor
```

## 2. Configure tolerance and cap

Tolerance, the PO+receipt requirement, and the cap are enforced deterministically, not by the model.

```
cp .env.example .env
ANTHROPIC_API_KEY=sk-ant-...
PRICE_TOLERANCE_PCT=5
QTY_TOLERANCE_PCT=0
AUTO_APPROVE_CAP_USD=10000
REQUIRE_PO_AND_RECEIPT=true
```

## 3. Define matching & duplicate rules

Provide the match keys and duplicate-detection rule.

```
# match.yml
match_on: [po_number, line_item, quantity, unit_price]
duplicate_keys: [invoice_number, [vendor, amount, po_number]]
block_payment_on_duplicate: true
```

## 4. Backtest on past invoices

Replay matched/paid invoices to compare the agent's decisions to actual outcomes.

```
po-match-agent backtest --range 90d --explain
# reports match accuracy + any duplicate or over-tolerance approvals (must be 0)
```

## 5. Wire into AP intake

Route incoming invoices to the agent. Start in assist mode, enable auto-approval for clean within-cap matches once backtests are clean.

```
# invoice intake -> POST https://your-host/ap/match (HMAC)
# promote MODE=act for clean three-way matches within the cap
```
