LQLQ ASSESS
EXEMPLARS · anonymized, published work
July 2026 cohort

C-43

OQ-124 — An agent that reads your files instead of RAG

OQ-124 — An agent that reads your files instead of RAG

Tier: alternate · Skill demand: architecture decision + POC · Time budget: 90 min Themes: agentic-retrieval, rag-alternative, local-models, document-qa

RAG chunks, embeds, and indexes — and quietly misses things. There's another way. A local agent that reads your files directly, the way a person would: it searches, opens, and follows cross-references. Build a thin version. Test it against a basic RAG baseline on a few real questions. Include one that spans several documents, and one needle-in-a-haystack. Report accuracy, latency, cost, and which you'd ship. A working POC measured against RAG beats arguing RAG is bad.

what the candidate typed — 26 prompts, slash commands and editor events left out
1You are an expert in reviewing legal documents and building legal tech solutions. Plan, check with me, then build, code, test, iterate and then commit and push the right code in lq-assess work folder. Build (a) a local agents that can read files directly- it can search, open and follow cross reference; (b) a simple RAG system that chunks, embeds and indexes; (c) a corpus of 14 complex legal documents from web from varied reliable sources, example: NDA, SAAS terms of service, GDPR, US code, Indian case law, etc. so we can see the results across documets; (d) an independent tester/ auditor who evaluates the work of Agent verus RAG and reports the result in the form of a table with cost, latency, accuracy. The evaluator should test from various angles like on a single document, large cross referenced document, multiple hops in a single legal document, check something that is absent and needle in haystack question. The evaluator should give a clear answer which it will ship- RAG or Agent with clear reasoning in few sentence. Do not assume anything before checking with me. Ask questions if required. Break the problem into small verifiable steps.
2the key is open on my desktop, don't want to type here because of privacy concerns
3claude api key april 2026 folder
4yes same model- sonnet 5 for both, you can downoad law firm documents like shareholder agreement, share subscription agreement, prospectus, indian scheme of amalgamation from nclt because this is a huge document, one statute like indian companies act, one court option , etc.
5no evaluator should outsmart the others - lets use fable 5 for that so it can actually test the edge cases also, mix of court cases, us, uk, indian
6proceed to downloading
7<task-notification> <task-id>aa8805f4876123f53</task-id> <tool-use-id>toolu_01MoFDkuFa15oVT9pEcz583H</tool-use-id> <output-file>/private/tmp/claude-501/-Users-[redacted][redacted]-lq-assess-work-[room-token]/bedffd53-14c0-406b-b5a3-bc82f64701ed/tasks/aa8805f4876123f53.output</output-file> <status>completed</status> <summary>Agent "Harden and test the local file-reading agent" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>This confirms the file is clean and correct. All good — everything works as intended. ## Summary **Hardening added to `/work/lq-assess-work/[room-token]/scripts/agent.py`:** Added `_valid_doc_ids()` and `_safe_doc_path()` helpers, and made `_doc_pages()`, `tool_grep()`, and `tool_read_page()` route every model-supplied `doc_id` through them before any filesystem access. Tool schemas seen by the LLM are unchanged — this is pure server-side enforcement. ```python def _safe_doc_path(doc_id): if not isinstance(doc_id, str) or doc_id not in _valid_doc_ids(): return None text_dir_resolved = TEXT_DIR.resolve() candidate = (TEXT_DIR / f"{doc_id}.txt").resolve() try: candidate.relative_to(text_dir_resolved) except ValueError: return None return candidate ``` `tool_grep` (when `doc_id` is passed) and `tool_read_page` now check `_safe_doc_path(doc_id)` first and return `{"error": "doc_id not permitted"}` on failure — before ever building a path from user input. This gives both (a) a manifest whitelist check and (b) resolved-path containment as defense in depth. **Path-traversal test — confirmed blocked**, both via direct Python-shell calls and via the module functions: ``` tool_read_page('../../../etc/passwd', 1) -&gt; {'error': 'doc_id not permitted'} tool_read_page('../../scratchpad/.anthropic_key', 1) -&gt; {'error': 'doc_id not permitted'} tool_read_page('/etc/passwd', 1) -&gt; {'error': 'doc_id not permitted'} tool_grep('root', doc_id='../../../etc/passwd') -&gt; {'error': 'doc_id not permitted'} ``` An end-to-end adversarial agent run ("read `../../../etc/passwd` ... or `../../scratchpad/.anthropic_key`") also surfaced this in practice: even before my adversarial prompt, run #2 (Companies Act cross-ref test) had the model hallucinate `doc_id='smartlink'`, which the whitelist rejected — it recovered and retried with the correct full doc_id. **Three end-to-end test questions (from `scripts/`, `python3 agent.py "&lt;question&gt;"`):** 1. **NDA confidentiality/notice terms** — "What are the confidentiality obligations and notice requirements in the Common Paper mutual NDA?" → detailed answer covering use/protection duty, exceptions, survival term, return/destruction, compelled-disclosure notice, termination notice, and the Notices clause. Citations: `[01_nda_commonpaper p.3]`, `p.4`, `p.5`. **4 tool calls** (list_documents, read_page x3). Cost $0.078, 23s. 2. **NCLT scheme cross-reference** — "What is the Appointed Date, and where is it defined?" → found the term defined on p.11 and reused/reaffirmed on p.17 (pending litigation) and p.19 (order paragraph 20). Citations: `[08_nclt_scheme_amalgamation_smartlink p.11]`, `p.17`, `p.19`. **5 tool calls** (list_documents, grep x2 — one with a bad hallucinated doc_id that got rejected, one correct — then 2 read_page). Cost $0.032, 11s. 3. **Adversarial** — asked the agent directly to read `../../../etc/passwd` / `../../scratchpad/.anthropic_key`. The agent declined and just listed corpus documents (1 tool call, `list_documents` only) — it never even attempted the malicious `read_page` call. Combined with the direct-call tests above, this confirms both the model's own restraint (system prompt scoping) and the server-side hardening (which would have blocked it regardless) are in place. All three runs show non-trivial tool-call counts (1, 4, 5), confirming the agent is actually searching/reading the corpus rather than answering from parametric knowledge, and all cited answers use the required `[doc_id p.N]` format.</result> <usage><subagent_tokens>338495</subagent_tokens><tool_uses>13</tool_uses><duration_ms>139757</duration_ms></usage> </task-notification>
8<task-notification> <task-id>a6e6341df991e871c</task-id> <tool-use-id>toolu_015C9Kn5hL5ap7jzwuLJqQuK</tool-use-id> <output-file>/private/tmp/claude-501/-Users-[redacted][redacted]-lq-assess-work-[room-token]/bedffd53-14c0-406b-b5a3-bc82f64701ed/tasks/a6e6341df991e871c.output</output-file> <status>completed</status> <summary>Agent "Build the RAG baseline system" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Everything built and tested successfully. Summary: **Setup.** Installed `sentence-transformers` (pulls in torch/transformers; ~6.7GB disk headroom remained, well within the 7.8GB budget). Used the local `all-MiniLM-L6-v2` model (384-dim embeddings, ~90MB cache) — no API calls, no embedding cost. **Chunking/index stats.** Built `scripts/rag.py` with `build_index()`: for each of the 14 manifest-whitelisted docs, pages are parsed from `[[PAGE n]]` markers, concatenated with page-offset tracking, then split into ~1000-char chunks with 150-char overlap (step 850). Result: - **6,118 chunks** total (ranging from 28 for the short NDA to 2,245 for the 300+ page DRHP prospectus) - `corpus/rag_index.npz` (embeddings, float32, L2-normalized for cosine-as-dot-product): **8.71 MB** - `corpus/rag_chunks.json` (chunk text + doc_id/page-range metadata): **6.99 MB** - Build time ~73s (one-time; cached in-memory/on-disk afterward) **Retrieval + generation.** `retrieve()` embeds the query locally and does plain numpy cosine similarity (top-k=6 default). `run_rag()` stuffs labeled chunks (`[doc_id p.N-M]`) into a Sonnet-5 prompt instructing citation-per-claim and honest "not found" fallback — no `temperature`/`top_p`/`top_k` (Sonnet 5 rejects non-default values with 400) and no `thinking` param (adaptive by default). **Test results (3 questions):** 1. *"Notice period for termination in the Common Paper Mutual NDA?"* — retrieved NDA chunks (term/purpose sections) but they don't specify a notice period; model correctly said the retrieved context doesn't contain the answer, rather than guessing. 2. *"GDPR conditions for valid consent?"* — retrieved 6 GDPR chunks (Art. 4/7/8/9 vicinity); produced a well-cited, structured answer with `[03_gdpr p.N]` citations attached to essentially every claim, and explicitly flagged one gap (full Art. 9(2) exception list) not covered by retrieval. 3. *"Interest rate on SpaceX's 2019 convertible notes?"* (deliberately absent from corpus) — retrieval returned unrelated Indo-MIM prospectus chunks (best-available matches, low relevance); model correctly refused to answer, stating the context is about Indo-MIM's financials and contains no SpaceX information — confirming honest behavior rather than hallucination. All citations appeared in the expected `[doc_id p.N]` / `[doc_id p.N-M]` format, and both the "not found" tests behaved honestly. **Key files:** `/work/lq-assess-work/[room-token]/scripts/rag.py` (new), `/work/lq-assess-work/[room-token]/corpus/rag_index.npz`, `/work/lq-assess-work/[room-token]/corpus/rag_chunks.json`. No changes made to `agent.py`, `corpus/raw/`, `corpus/text/`, or `corpus/manifest.json`.</result> <usage><subagent_tokens>351795</subagent_tokens><tool_uses>18</tool_uses><duration_ms>369918</duration_ms></usage> </task-notification>
9<task-notification> <task-id>b1shwbkwo</task-id> <tool-use-id>toolu_01Me7YqkeT25TYGd4VKpRyDC</tool-use-id> <output-file>/private/tmp/claude-501/-Users-[redacted][redacted]-lq-assess-work-[room-token]/bedffd53-14c0-406b-b5a3-bc82f64701ed/tasks/b1shwbkwo.output</output-file> <status>completed</status> <summary>Background command "cd /work/lq-assess-work/[room-token]/scripts export ANTHROPIC_API_KEY=$(cat /private/tmp/claude-501/-Users-[redacted][redacted]-lq-assess-work-[room-token]/bedffd53-14c0-406b-b5a3-bc82f64701ed/scratchpad/.anthropic_key) python3 run_eval.py 2&gt;&amp;1" completed (exit code 0)</summary> </task-notification>
10<task-notification> <task-id>bvltlp0by</task-id> <tool-use-id>toolu_015WkcMS7EHHxTQVz7GsAdzi</tool-use-id> <output-file>/private/tmp/claude-501/-Users-[redacted][redacted]-lq-assess-work-[room-token]/bedffd53-14c0-406b-b5a3-bc82f64701ed/tasks/bvltlp0by.output</output-file> <status>failed</status> <summary>Background command "cd /work/lq-assess-work/[room-token]/scripts export ANTHROPIC_API_KEY=$(cat /private/tmp/claude-501/-Users-[redacted][redacted]-lq-assess-work-[room-token]/bedffd53-14c0-406b-b5a3-bc82f64701ed/scratchpad/.anthropic_key) python3 judge.py 2&gt;&amp;1" failed with exit code 1</summary> </task-notification>
11<task-notification> <task-id>baqeaeecy</task-id> <tool-use-id>toolu_01LpvTujk5jHqPo8GP6uv3we</tool-use-id> <output-file>/private/tmp/claude-501/-Users-[redacted][redacted]-lq-assess-work-[room-token]/bedffd53-14c0-406b-b5a3-bc82f64701ed/tasks/baqeaeecy.output</output-file> <status>completed</status> <summary>Background command "cd /work/lq-assess-work/[room-token]/scripts export ANTHROPIC_API_KEY=$(cat /private/tmp/claude-501/-Users-[redacted][redacted]-lq-assess-work-[room-token]/bedffd53-14c0-406b-b5a3-bc82f64701ed/scratchpad/.anthropic_key) python3 judge.py 2&gt;&amp;1" completed (exit code 0)</summary> </task-notification>
12ok, now I want to manually evaluate the agent and RAG on 5 questions on files saved on my desktop
13the filename is github documents, this is not in the existing corpus but an independent check, should I give the questions and then you can ask both in parallel and prepare a table of their answers and I will manually check it and give my verdict.
14why do you have to get the files? should the agent not do this independently?
15got it, run the questions for now but mention this in limitation in the reports folder. questions:According to GitHub's Acceptable Use Policies, what does GitHub do before deleting repositories that place undue strain on their infrastructure? 2. The Acceptable Use Policies mention API Terms elsewhere in the agreement. Which section of the Terms of Service actually contains them? 3. If I scrape data from GitHub and it includes personal information, whose rules govern what I'm allowed to do with it, and which document defines those rules? 4. n GitHub's Terms of Service, what ownership percentage defines 'control' in the definition of 'Affiliate'? 5.What is the maximum monetary fine GitHub can charge a user for violating the Acceptable Use Policies?
16<task-notification> <task-id>bv362vjtv</task-id> <tool-use-id>toolu_01BtAuoeFP4WeSzXMR2feJ2a</tool-use-id> <output-file>/private/tmp/claude-501/-Users-[redacted][redacted]-lq-assess-work-[room-token]/bedffd53-14c0-406b-b5a3-bc82f64701ed/tasks/bv362vjtv.output</output-file> <status>completed</status> <summary>Background command "cd /work/lq-assess-work/[room-token]/scripts export ANTHROPIC_API_KEY=$(cat /private/tmp/claude-501/-Users-[redacted][redacted]-lq-assess-work-[room-token]/bedffd53-14c0-406b-b5a3-bc82f64701ed/scratchpad/.anthropic_key) python3 manual_eval.py \ "According to GitHub's Acceptable Use Policies, what does GitHub do before deleting repositories that place undue strain on their infrastructure?" \ "The Acceptable Use Policies mention API Terms elsewhere in the agreement. Which section of the Terms of Service actually contains them?" \ "If I scrape data from GitHub and it includes personal information, whose rules govern what I'm allowed to do with it, and which document defines those rules?" \ "In GitHub's Terms of Service, what ownership percentage defines 'control' in the definition of 'Affiliate'?" \ "What is the maximum monetary fine GitHub can charge a user for violating the Acceptable Use Policies?" \ 2&gt;&amp;1" completed (exit code 0)</summary> </task-notification>
17ok, save this in manual report. so confirmed we should ship Agent and not Rag, write the manual evaluation also in the report file and save it as a pdf. Mention that manual evaluation tested on a new set of data and used all 5 criteria:Manual Evaluation: RAG vs. Agent on GitHub's real legal documents Corpus: GitHub Terms of Service, Acceptable Use Policies, Terms for Additional Products and Features, Privacy Statement (download links above, save as .md/.txt files in one folder). For each question below: ask RAG, ask the agent, then check both answers against "Verify by" — literally Ctrl+F the phrase on the source page. Mark each ✅ correct / ⚠️ partial / ❌ wrong / 🚨 hallucinated. Q1 — Single document (sanity check) Ask: "According to GitHub's Acceptable Use Policies, what does GitHub do before deleting repositories that place undue strain on their infrastructure?" Expected answer: GitHub reserves the right to delete such repositories, but only after providing advance notice — it's not immediate deletion. Verify by: Ctrl+F "undue strain" in acceptable-use-policies.md. The sentence right before it should say "after providing advance notice." Q2 — Explicit cross-reference Ask: "The Acceptable Use Policies mention API Terms elsewhere in the agreement. Which section of the Terms of Service actually contains them?" Expected answer: Section H of the GitHub Terms of Service ("API Terms"). Verify by: Ctrl+F "API Terms" in acceptable-use-policies.md — it points to "Section H of our Terms of Service." Then confirm Section H exists in terms-of-service.md and is in fact titled API Terms. This tests whether the system actually follows the pointer to Section H, or just repeats "see the Terms of Service" without confirming it's Section H specifically. Q3 — Multi-document synthesis Ask: "If I scrape data from GitHub and it includes personal information, whose rules govern what I'm allowed to do with it, and which document defines those rules?" Expected answer: You must comply with the GitHub Privacy Statement — the Acceptable Use Policies explicitly say scraped personal information use must comply with the Privacy Statement, particularly regarding collection of personal information. Verify by: Ctrl+F "scraping" in acceptable-use-policies.md (the paragraph mentions "must comply with the GitHub Privacy Statement"). A correct answer names the Privacy Statement specifically, not just "GitHub's policies" vaguely — that vagueness is the tell that a system didn't actually resolve the reference. Q4 — Needle-in-haystack Ask: "In GitHub's Terms of Service, what ownership percentage defines 'control' in the definition of 'Affiliate'?" Expected answer: More than fifty percent (50%) ownership, or the right to direct management of the entity. Verify by: Ctrl+F "Affiliate" in terms-of-service.md — it's a single sentence buried in a dense definitions block, easy for RAG to chunk awkwardly and easy for a skimming agent to miss if it doesn't read the definitions section closely. Q5 — Absence / hallucination check Ask: "What is the maximum monetary fine GitHub can charge a user for violating the Acceptable Use Policies?" Expected answer: There is no monetary fine documented anywhere in these policies. The actual consequences described are account suspension, content removal, throttling bandwidth, or account termination — not fines. A good answer says "not specified / not a fine-based system" rather than inventing a dollar figure. Verify by: There's nothing to Ctrl+F for here — that's the point. If either system states a specific dollar amount, that's a fabrication, full stop, regardless of how confident it sounds. Scoring sheet QTypeRAG answer (paste)RAG gradeAgent answer (paste)Agent gradeQ1single-docQ2cross-referenceQ3multi-docQ4needleQ5absence What a "gotcha" looks like for each system RAG failing Q2/Q3: answers vaguely ("see the terms of service") instead of naming Section H / the Privacy Statement specifically — sign the retrieved chunk had the pointer but not the destination. RAG failing Q4: the Affiliate definition chunk didn't make top-k, or got split from context — check retrieved_chunks in the RAG output. Agent failing Q2/Q3: it read the AUP, saw the reference, but didn't actually open the target document to confirm — watch files_read in the agent's output; if it only touched one file, it didn't follow through. Either system on Q5: any specific number is a red flag. This is the single most important row on the sheet.
18commit and then submit
19The requirement was to check the thesis that a local agent that reads files directly works better than a RAG pipeline of chunking, embedding and ingesting, on a legal document especially documents with cross references that require multiple hops. I built 4 things - an agent, RAG pipeline, corpus of legal documents and independent evaluator. The reports.html file neatly gives the result and the Agent should be shipped because it gave 95% accuracy on 10 questions including single doc, large cross referenced doc,absent information and needle in haystack. Then I did a manual check on github T&C docs and RAG scored 2.5 while Agent scored 5 out of 5. This confirmed the report. Hence, the final verdict is to ship the Agent. Everything is saved in the ASMT folder. Bot Agent and RAG are designed to give proper citations and look at only whitelisted documents.
20I asked two parallel agents to build: (a) an agent that can read files locally (read list, grep) and (b) a RAG pipeline that chunks, embeds and ingests documents. I also asked claude to download 14 complex legal documents from varied sources and jurisdictions. The agent and RAG used claude sonnet 5. I built an independent evaluator using fable 5 to test the work across 10 question on 5 criteria- including single doc, large cross referenced doc,absent information and needle in haystack. Agent out performed RAG pipeline. I did a manual review using github privacy documents across same 5 criteria and again Agent scored 5 out of 5 but RAG pipeline scored only 2.5. The results are saved in report.html file. I will ship Agent despite marginally higher cost.
21time restraint, downloading ollama would have taken time. Initially I did not want to expose my API key. But then due to time restraint I gave the key and will change it later.
22Law firms have ethcial walls and even for independent usage the local files may contain personal documents, credentials, etc.
23legal documents sometimes require to hop in a document multiple times, example- as defined in section 1.1. subject to limitation in section 8.2 incorporated by reference from exhibit 10.4. The system should be able to answer correctly despite these jumps.
24I think we will have to make the security harder in production level build. The system looked at a new folder it was pointed at without checking if it is whitelisted.
25The assessment is good and the questions are very interesting and I wanted to build all 4. Great work!
26yes