production-rag-assistant
AGENTS.md61 starsChanged 57 days agoMITView on GitHub
Single-app Streamlit project. No monorepo, no packages. GitHub Actions (.github/workflows/ci.yml) runs on PRs targeting main: CI runs fast tests only (slow embedder tests marked @pytest.mark.slow are skipped). No coverage gate on PRs — keep ≥70% locally with the command above before pushing. - Never push directly to main — branch protection enforces this. Every change goes through a PR branch, even one-line doc fixes. - Branch names: type/short-slug — feat/, fix/, chore/, ci/, docs/, refactor/, test/. - Commits: Conventional Commits…
- Reads credentials
- Installs packages
- Commits and pushes
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
28 rules. About 1 is common, 19 are distinctive, and 8 are very specific to this project.
≈1
Common · estimate
Many files like this have a rule of this kind.
≈19
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 58
No coverage gate on PRs — keep ≥70% locally with the command above before pushing.
- Distinctive: line 63
Every change goes through a PR branch, even one-line doc fixes.
- Very specific: line 69
Never commit: .env, data/ outputs, venv/, keys/tokens.
- Very specific: line 74
Run ruff check src tests app.py eval alembic + the fast test command green locally before push (keep coverage ≥70%).
- Distinctive: line 81
Keep diffs under ~400 lines.
- Common: line 83
No PR before local code review: Before opening: read your own git diff main...HEAD line by line — kill debug prints, dead code, secrets, …
- Distinctive: line 91
Scalability: keep code and architecture modular and scalable.
- Distinctive: line 95
Simple over complex: if a solution needs more than one abstraction layer, you're overcomplicating it.
- Distinctive: line 101
Never swallow exceptions: every caught error must be logged or re-raised.
- Distinctive: line 103
Graceful degradation: if a non-critical dependency (Langfuse) is down, log and continue — never block core queries.
- Very specific: line 117
Test files use inconsistent naming: some test_*.py, some *_test.py.
- Distinctive: line 121
Don't swap the stack (Groq / LangChain / Chroma / Streamlit) without updating the PLAN.md Locked decisions table first.
- Distinctive: line 123
Don't hardcode workspace-specific logic (legal vs academic) into the pipeline — workspace profiles live in prompt config (PLAN PR-4).
- Very specific: line 125
Don't run irreversible actions (force-push, git push --delete, wiping data/, resetting ChromaDB, pushing to main) without explicit …
- Distinctive: line 127
Don't polish the Streamlit UI before the underlying service/pipeline is proven by tests — service layer first (PLAN PR-0 → PR-6 order).
- Very specific: line 129
Don't hardcode API keys or endpoints — env vars via src/config.py only.
- Distinctive: line 130
Don't keep long-lived feature branches — rebase on main frequently.
- Distinctive: line 131
Don't leave TODO comments without a linked PLAN.md ticket (PR-0…PR-7).
- Distinctive: line 132
Don't write clever one-liners that sacrifice readability.
- Distinctive: line 133
Don't over-engineer — start simple, iterate when constraints demand it.
- Distinctive: line 134
Don't write tests just to "make it pass" — write tests to verify correctness.
- Distinctive: line 135
If the code is good, tests pass automatically.
- Very specific: line 137
Never loosen test assertions to pass: If a test fails, fix the code — not the test.
- Distinctive: line 139
Never skip tests without explicit user request.
- Distinctive: line 141
MUST tell the user: (1) which variable, (2) current value, (3) new value, (4) why.
- Very specific: line 143
Never make cosmetic changes to pass time: No import reordering, no refactoring working code, no try/except → contextlib.suppress swaps …
- Distinctive: line 145
Every change must have a functional purpose.
- Very specific: line 146
Don't add new direct src.* imports to app.py — go through RAGService.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md
Build & Test Entrypoints
# Run app
streamlit run app.py
# Lint (same as CI)
ruff check src tests app.py eval alembic
# Local test gate (CI runs the same tests WITHOUT the coverage gate)
pytest tests/ -v -m "not slow" --cov=src --cov-report=term-missing --cov-fail-under=70
# Run all tests (including slow embedder tests, no coverage gate)
pytest tests/ -v
# Run evaluation (requires GROQ_API_KEY + pre-ingested docs in ChromaDB)
python3 eval/eval_runner.pySystem Architecture
Single-app Streamlit project. No monorepo, no packages.
app.py # Streamlit UI entrypoint
src/
config.py # Centralized config, reads .env, validates at startup
ingestion/ # PDF → chunks → embeddings → ChromaDB
retrieval/ # BM25 + vector search → RRF fusion → cross-encoder rerank
generation/ # Citation prompt builder + Groq LLM call + Pydantic validation
db/ # ChromaDB client (LangChain Chroma wrapper)
monitoring/ # Langfuse tracing (optional, fails silently if unconfigured)
eval/ # Ragas evaluation runner
tests/ # Pytest suiteRuntime Invariants
- Python 3.12 required.
asyncio_mode = autoin pytest.ini. - GROQ_API_KEY is the only required env var. App crashes at startup without it.
- ChromaDB stores vectors in
data/chroma/. Data dirs are gitignored. - BM25 index is rebuilt in-memory from ChromaDB chunks on each app start or PDF upload. Not persisted separately.
- Cross-encoder reranker (
ms-marco-MiniLM-L-6-v2) runs on CPU. Accounts for ~72% of query latency (~10s of ~14s total). - Citation validation is Pydantic-enforced: every answer must contain
[SOURCE N]patterns or it raisesValidationError. - Langfuse is optional. Traces are skipped silently when keys are absent.
- Eval dataset lives at
data/eval_dataset.json. Results saved toresults.json.
Continuous Integration Contract
GitHub Actions (.github/workflows/ci.yml) runs on PRs targeting main:
- lint —
pip install ruff==0.15.10→ruff check src tests app.py eval alembic - test —
pip install -r requirements.txt→pytest tests/ -v -m "not slow" --cov-fail-under=0
CI runs fast tests only (slow embedder tests marked @pytest.mark.slow are skipped).
No coverage gate on PRs — keep ≥70% locally with the command above before pushing.
Version-Control Hygiene & Branch Discipline
- Never push directly to
main— branch protection enforces this. Every change goes through a PR branch, even one-line doc fixes. - Branch names:
type/short-slug—feat/,fix/,chore/,ci/,docs/,refactor/,test/. - Commits: Conventional Commits —
type: subject, lowercase imperative, ≤50 chars. Body only when the "why" isn't obvious from the subject (see existingci:commits). - One concern per branch. No mixed refactor + feature work.
- Never commit:
.env,data/outputs,venv/, keys/tokens. Pre-push secret scan must be empty:git log -p | grep -iE "sk-[a-zA-Z0-9]{20,}|pk_live_[a-zA-Z0-9]{10,}|ghp_[a-zA-Z0-9]{20,}|gsk_[a-zA-Z0-9]{20,}|AKIA[0-9A-Z]{16}" - Resolve conflicts inside the feature branch. No
merge:conflict-fix commits on main. - Squash-merge PRs, then delete the head branch. Clean up stale branches after merge.
- Run
ruff check src tests app.py eval alembic+ the fast test command green locally before push (keep coverage ≥70%).
Change Review Protocol (PR Contract)
- PR title = Conventional Commit (becomes the squash subject on main).
- Body sections: What/Why · Changes (bullets) · Test plan (commands run + results) · Screenshots if UI · Risk/rollback if breaking.
- Keep diffs under ~400 lines; split larger work. PLAN.md breakdown = one PR = one phase.
- Link the PLAN.md ticket (PR-0…PR-7) when applicable.
- No PR before local code review. Before opening: read your own
git diff main...HEADline by line — kill debug prints, dead code, secrets, stray files. CI review comes after local self-review, never instead of it. - Draft PR = WIP; mark ready before requesting review.
Software Quality Attributes
- Scalability: keep code and architecture modular and scalable.
- Modular architecture: each component is a separate unit with a clear interface.
- Clean, readable code: prioritize clarity over cleverness — code is read more than written.
- Production-focused: handle errors, log meaningfully, fail loudly; every line should be production-ready.
- Simple over complex: if a solution needs more than one abstraction layer, you're overcomplicating it.
Logging & Error-Handling Contract
- Structured logging:
loguruwith context fields — no rawprintstatements. - Log levels:
ERROR(needs attention),WARNING(degraded state),INFO(business events),DEBUG(dev detail). - Never swallow exceptions: every caught error must be logged or re-raised. Silent failures are bugs.
- Fail fast on startup: crash immediately when required env vars are missing (
Config.validate()). - Graceful degradation: if a non-critical dependency (Langfuse) is down, log and continue — never block core queries.
- Error responses: return structured error objects to callers — never stack traces or raw exceptions.
- Retry with backoff: exponential backoff for external API calls (Groq failover chain). Don't hammer a failing service.
Container Orchestration
docker-compose.yml runs ChromaDB + the Streamlit app. The app container reads CHROMA_HOST=chromadb to connect to the compose service. Locally, CHROMA_MODE=local uses persistent file storage.
Operational Pitfalls
src/ingestion/embedder.pyloadsall-MiniLM-L6-v2on CPU. First run downloads the model (~90MB).src/retrieval/cross_encoder.pylazily loads the reranker model. First query is slow.- The Streamlit app stores uploaded PDFs in
data/raw/and rebuilds BM25 on every upload. load_all_chunks()reads every document from ChromaDB. With large corpora this is expensive.- Test files use inconsistent naming: some
test_*.py, some*_test.py. Onlytest_*pattern files are auto-discovered by pytest.
Engineering Guardrails (Prohibited Patterns)
- Don't swap the stack (Groq / LangChain / Chroma / Streamlit) without updating the PLAN.md Locked decisions table first.
- Don't hardcode workspace-specific logic (legal vs academic) into the pipeline — workspace profiles live in prompt config (PLAN PR-4); the engine stays shared.
- Don't run irreversible actions (force-push,
git push --delete, wipingdata/, resetting ChromaDB, pushing tomain) without explicit confirmation. - Don't polish the Streamlit UI before the underlying service/pipeline is proven by tests — service layer first (PLAN PR-0 → PR-6 order).
- Don't hardcode API keys or endpoints — env vars via
src/config.pyonly. - Don't keep long-lived feature branches — rebase on
mainfrequently. - Don't leave TODO comments without a linked PLAN.md ticket (PR-0…PR-7).
- Don't write clever one-liners that sacrifice readability.
- Don't over-engineer — start simple, iterate when constraints demand it.
- Don't write tests just to "make it pass" — write tests to verify correctness. If the code is good, tests pass automatically. Focus on edge cases, error paths, and failure modes — not happy-path-only green checks.
- Never loosen test assertions to pass. If a test fails, fix the code — not the
test. Never change
assert X in resulttoassert X in result or Y in result. Never skip tests without explicit user request. - Never edit
.env/.env.*without explanation first. Before touching one you MUST tell the user: (1) which variable, (2) current value, (3) new value, (4) why. Wait for explicit approval. - Never make cosmetic changes to pass time. No import reordering, no refactoring
working code, no
try/except→contextlib.suppressswaps unless the user asks. Every change must have a functional purpose. - Don't add new direct
src.*imports toapp.py— go throughRAGService;src/stays framework-free (no Streamlit imports belowapp.py).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

