# Multi-Model Audit Reference

Session-specific patterns for running parallel local-model audits, built from a streaming-app backend audit session (May 2026).

## Prompt Structure (templates)

### Web Research Context File (`/tmp/audit_web_research.md`)

Compile from browser research before launching models:

```markdown
# Web Research Context

## Real-Debrid API
- Base: https://api.real-debrid.com/rest/1.0/
- Auth: Bearer token OR auth_token query param
- Rate: 250 req/min, 429 on exceed
- Key endpoints: /unrestrict/link (POST), /torrents/addMagnet (POST), etc.
- Public client ID for open-source apps: X245A4XAIBGVM
- NO /torrents/instantAvailability in official docs (check if undocumented)

## Stremio Addon Protocol
- 4 resources: manifest, catalog, meta, stream
- Stream response: { streams: [{ url, infoHash, fileIdx, name, ... }] }
- No built-in auth — API key must pass via config or URL param

## Jackett vs Prowlarr
- Jackett: Older, Torznab API, manual indexer config
- Prowlarr: Newer, integrates with Sonarr/Radarr, syncs indexers
- Torrentio uses its own custom scraper, not Jackett/Prowlarr
```

### Full Audit Prompt Template

```python
prompt = f"""You are a senior software architect doing a DEEP ARCHITECTURE AUDIT.
Read actual source files from disk. Be specific with file:line references.
This is running alongside other model audits — find UNIQUE insights others miss.

## WEB RESEARCH CONTEXT
{web_context}

## THE PROJECT
Location: ~/.hermes/projects/streaming-app/
HEAD: a09fdd2
Architecture: FastAPI, 6 DDD modules, 377 tests
Status: Stremio stream endpoint is PLACEHOLDER (needs debrid wire-up)

## YOUR MANDATE — ALL 5 PHASES

### PHASE 1: STREMIO STREAM WIRE-UP (The #1 Gap)
Read these files from disk:
- app/modules/addons/infrastructure/addon_provider.py (get_streams lines 167-193)
- app/modules/addons/application/interfaces.py
- app/modules/streaming/application/use_cases.py
...
Answer: What EXACTLY changes file-by-file?

### PHASE 2: CODE QUALITY & ARCHITECTURE
...
### PHASE 3: KEY ARCHITECTURAL GAP
...
### PHASE 4: COMPETITIVE GAPS
...
### PHASE 5: OPTIMIZATION & NEW APPROACHES

## OUTPUT FORMAT
Organize by PHASE (1-5). Include file:line references. Prioritized action list at end.
"""
```

### Second-Opinion Prompt Pattern

When a prior model already produced a report, ask the next model to critique it:

```python
prompt = f"""You are doing a SECOND OPINION deep audit. A prior model already produced a report.
Your job is to IMPROVE on it — find what it missed, got wrong, or was shallow on.

## WHAT THE FIRST AUDIT CLAIMED (verify each claim):
- "TMDB client is synchronous" → ACTUALLY verify by reading the source
- "Missing circuit breakers" → Check if ProviderCooldown already exists
- "Account lookup has race conditions" → Verify async session safety

For each claim: read the actual file, state whether it's correct or wrong, and why.

## READ THESE FILES TO VERIFY:
- app/modules/metadata/infrastructure/tmdb_client.py
- app/modules/streaming/infrastructure/account_lookup.py
- app/modules/streaming/infrastructure/provider_cooldown.py
...
"""
```

## Parallel Launch Script

Save as `/tmp/run_audit.py` for each model run:

```python
#!/usr/bin/env python3
import json, subprocess, sys

model = sys.argv[1]
outfile = sys.argv[2]

# Load web research context
with open("/tmp/audit_web_research.md") as f:
    web_context = f.read()

prompt = f"..."  # Full prompt with web_context embedded

result = subprocess.run(
    ["curl", "-s", "-X", "POST", "http://localhost:9292/v1/chat/completions",
     "-H", "Content-Type: application/json",
     "-d", json.dumps({
         "model": model,
         "messages": [
             {"role": "system", "content": "System prompt here..."},
             {"role": "user", "content": prompt}
         ],
         "temperature": 0.2,
         "max_tokens": 16384
     })],
    capture_output=True, text=True, timeout=300
)

with open(outfile, "w") as f:
    if result.returncode == 0:
        data = json.loads(result.stdout)
        content = data["choices"][0]["message"]["content"]
        f.write(content)
    else:
        f.write(f"ERROR: {result.stderr}")
```

Launch in parallel:

```bash
cd /tmp && python3 run_audit.py qwen3.6-35b /tmp/audit_3.6_35b.md &
python3 run_audit.py qwen3-coder-30b /tmp/audit_coder_30b.md &
python3 run_audit.py gemma-4-26b /tmp/audit_gemma.md &
wait
```

Or via Hermes terminal background:

```python
terminal(background=true, command="cd /tmp && python3 run_audit.py gemma-4-26b /tmp/audit_gemma.md")
terminal(background=true, command="cd /tmp && python3 run_audit.py qwen3.5-opus14 /tmp/audit_opus14.md")
terminal(background=true, command="cd /tmp && python3 run_audit.py qwen3.6-mtp /tmp/audit_mtp.md")
```

## Cross-Reference Template

After all audits complete, produce a consolidated report:

| Dimension | Model A | Model B | Model C |
|-----------|---------|---------|---------|
| Phase 1 wire-up approach | ... | ... | ... |
| Phase 2 correctness | ❌ claimed X wrong | ✅ corrected | ✅ agreed with B |
| Unique insight | ... | ... | ... |
| Priority list | P0: ..., P1: ... | ... | ... |

Label consensus items as **«consensus»** and conflicts as **«needs human judgment»**.

## Known Pitfalls from This Session

- **First audit was shallow** — Qwen3-Coder-30B made generic pro/con tables and misjudged the TMDB client (called it sync when it uses httpx.AsyncClient). Always verify factual claims before acting.
- **Second audit (3.6-35B) was substantially better** — found the real architectural gap the first missed (Stremio protocol is anonymous — no user context for debrid account selection). This is the kind of insight parallel audits are good for.
- **Models hallucinate file paths** — one model referenced lines that didn't exist. Always `cat` the file to verify.
- **Don't wait for sequential results** — the user will say "now do it with another model" instead of your preferred parallel approach. Launch all at once.
