agentleFS
LeostrukaLeostruka/devin-bundle/skills/agentic-rag/SKILL.md

agentic-rag

Skill0 starsChanged 3 months agoMITView on GitHub

Use when implementing an agentic RAG product in a target project (support desk, knowledge assistant, evidence-gated Q&A). Playbook for the retrieve -> decision-gate -> answer-or-escalate architecture with multimodal index and human-review loop. Builds the system; does not answer questions with it.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 5 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Keep the three context sources distinct in storage metadata and in the generator system prompt:

    line 37
  2. Distinctive:

    Never call the generation model when the gate fails.

    line 47
  3. Very specific:

    No silent rerank or gate fallback: inspect stream status events (RERANKING_FAILED, SUMMARIZATION_FAILED) and verify the rerank/gate stage …

    line 63
  4. Distinctive:

    No auto-submit/auto-send to end users without rep confirmation.

    line 88
  5. Distinctive:

    No figure-level extraction (full-page PNG only.

    line 89
  6. Distinctive:

    No unbounded retry loops, no answer on sub-threshold evidence.

    line 91

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Agentic RAG (evidence-gated Q&A)

Overview

Implementation playbook for the agentic RAG support-desk architecture (source: Daily Dose of DS "Jev-powered Agentic RAG" walkthrough). The system retrieves evidence, asks a decision model whether the evidence is sufficient, answers with citations when it is, and escalates to a human ticket when it is not. Human replies feed back into the index.

Five slots, stack-agnostic:

SlotReference choiceSwappable with
BackendInsForge OSS (Postgres+pgvector, auth, storage, edge functions, realtime, model gateway)Supabase / plain Postgres+pgvector + functions
EmbeddingsEmbeddingGemma 2 (multimodal, 768-dim, text+image same space)Any text embedder if corpus is text-only
Decision modelLaya multilingual (Convai Innovations; 322M BERT-style encoder, Apache 2.0, self-host, free; this bundle already ships laya-tools/layad and the implement-laya skill)Free/open: Kev 9B, Jeeves 9B, Strands Decider 2B, open-weight d1-3B/d1-omni-600M. Paid optional: Jev or hosted d1/d1-ultra (Choice/Score/Noul API, text+image). Last resort: LLM-judge with strict JSON schema
GeneratorVision-capable LLM through a model gateway, model id in secretsAny cited-generation capable model
HostingOne L4 (~7.2 GB both models); SIE for multi-model single-GPU servingAny GPU host or managed endpoint

Architecture selector (when to use what)

Corpus & workloadPatternWhy
Static corpus <200k tokens (~500 pages), low churnPrompt context + prompt caching (no RAG)Zero retrieval infra or chunk-boundary loss
Single-source docs + per-user chat historyLinear RAG + cross-encoder rerankerOne vector search (top-20) + reranker (max_results = 5); predictable latency
High-stakes Q&A, multi-source (docs/SQL/API), support deskAgentic RAG (this playbook)Decision gate blocks ungrounded generation, allows 1 wider retry, and escalates to human with feedback loop

Context separation (Conversation vs. Memory vs. RAG)

Keep the three context sources distinct in storage metadata and in the generator system prompt:

PatternWhat it storesMetadata / scopePrompt rule
Conversation storageLast $N$ verbatim turns (e.g. 6)Passed in Context arrayResolves follow-ups ("how do I do that in Docker?") that lack semantic overlap
Long-term user memoryEarlier turns or extracted user factskind = conversation, user_id from auth principalAttribute to the user only when kind = conversation
External knowledge (RAG)Shared corpus chunks + page PNGskind = document, title, url, pageTechnical facts only; never attribute document examples to the caller

Iron rules

  1. Never call the generation model when the gate fails. Escalation is a first-class output, not an error.
  2. Thresholds live in a DB/config table, separate for text and image candidates; tuning must never require a deploy.
  3. Log every gate decision (candidates, scores, verdict) to decision_log before answering or escalating.
  4. Index each page twice: ~220-word text chunks AND a rendered page PNG, both tagged with the page number. Merge candidates by page.
  5. Answers must cite page numbers and return thumbnails/excerpts when the channel supports it. The generator answers only from supplied evidence.
  6. One wider retry max before ticketing: widen top-k/filters once, never loop.
  7. Human actions stay human: reps write replies, customer receives email. "Save to knowledge" re-indexes the Q&A pair as a new chunk.
  8. Tenant and user isolation via RLS / authenticated principal (ClaimsPrincipal / JWT): never accept user_id or session_id from the request body, and escape or parameterize all metadata filters.
  9. No silent rerank or gate fallback: inspect stream status events (RERANKING_FAILED, SUMMARIZATION_FAILED) and verify the rerank/gate stage actually ran; enforce max_results cut even when reranking is off.
  10. End-to-end stream deadline and reasoning token budget: HttpClient.Timeout only covers response headers on streamed replies; link a request-wide deadline across history load + stream read + turn store, and size gen_token_budget (e.g. >=2048) so reasoning models do not exhaust budget on thinking tokens.

Phase route

GateNameExit condition
P0IntakeCorpus shape (docs, pages, languages), tenancy model, answer channels, threshold starting values, human-review SLA defined in .devin notes or issue.
G1Data modelTables for documents, chunks (vector dim per embedder), conversations, tickets, decision_log, thresholds; tenant-scoped RLS verified with two-tenant test.
G2Index pipelineUpload -> storage -> job -> per-page text chunks + page PNG -> embed both -> persist with page tags; deterministic doc IDs + async ingestion status polling (COMPLETED/FAILED); 20-page PDF indexes in <1 min.
G3Query pipeline + gateEmbed question (+attached image) -> dual search (text, image) -> merge by page -> decision model rerank+answerability -> thresholds -> answer w/ citations OR one wider retry OR ticket. Gate unit-tested above/below threshold and on stage failure.
G4Human loopTicket appears realtime with question + rejected candidates + scores; rep reply emails customer; save-to-knowledge re-indexes.
G5EvalHeld-out Q&A set: retrieval ranking (hit@1, hit@3, MRR), gate precision/recall, citation correctness, escalation rate, and split p50/p95 latency (retrieval vs. rerank/gate vs. LLM generation) reported; thresholds tuned from data.

Acceptance criteria

  • Query with sufficient evidence: answer + page citations + decision_log row.
  • Query with insufficient evidence: single wider retry, then ticket with candidate scores visible to the rep; generation model never called.
  • Rep reply reaches customer by email; save-to-knowledge makes the same question retrievable.
  • Threshold change in DB alters gate behavior without a deploy.

Non-goals

  • No auto-submit/auto-send to end users without rep confirmation.
  • No figure-level extraction (full-page PNG only; vector diagrams lose captions otherwise).
  • No unbounded retry loops, no answer on sub-threshold evidence.

Integration notes

  • data-analyst/research skills can reuse the gate pattern for evidence sufficiency before answering.
  • On this bundle host, extensions/voicebox (tts) + asr can add voice to the desk frontend; optional, not part of the core pipeline.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.