# Take-Home: A Document Agent With Retrieval and Tools

> How to build a document agent for a take-home test, with retrieval, tools, checks and the trade-offs reviewers look for, explained simply for your AI interview.

**In short:** A take-home is a small build you do on your own time. For a document agent, build retrieval first, give the agent only the tools it needs, and test it on real questions before you trust it.

AI and LLM interview question Q397, Forward Deployed Engineering and applied AI. Intermediate, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/take-home-a-document-agent-with-retrieval-and-tools

## Say it in 30 seconds

A take-home is a small project you finish at home. For this one I would build a document agent. First, retrieval: split the files into chunks, search them by keyword and by meaning, then merge the results. Second, tools: the agent can read, and anything that changes a record waits for a person to approve it. Last, I would test it on real questions with known answers, and say plainly what it cannot read yet.

## Say it in 2 minutes

A take-home is a small build you do on your own time, and the reviewer reads your choices as closely as your code. For a document agent, I would start with retrieval, because an agent that answers from the wrong file does more harm than no agent at all. I would split each document into chunks, search them two ways, and merge the results. Keyword search catches exact words like a clause number. Meaning search catches the same idea written in other words.

Next come the tools. The model can only ask for a search or to open a file. My code runs those calls and sends back the results. Anything that changes the outside world, like sending a notice to a vendor, creates a draft and waits for a person to approve the exact text. Document text is treated as untrusted, because a planted line in a contract could try to give the agent new orders.

Then I would test before I trust it. I would write thirty to fifty real questions, each with the right answer and the right source file, and score the search and the answer separately. Every answer would show the clause it used, so a reviewer can check it in one click. Anthropic's guidance is to start with simple prompts and add agent steps only when simpler solutions fall short.

In the write-up I would say what the build does not do yet: scanned PDFs, tables, and anything newer than the last index run. Reviewers often remember the limits more than the feature list.

## What is a take-home, in plain words?

A take-home is a small project a company sends you to finish on your own time. The team reads your choices as closely as your code, so a small, clear build with honest limits scores well.

This one is a document agent. It answers questions about a pile of files, and it can take a few actions, like opening a file or drafting a task for a person. Picture a new hire at a law firm, given a shared drive of 40,000 vendor contracts and asked which ones renew without notice. A good new hire searches, opens the right contract and quotes the clause they found. The AI agent should work the same way.

So the agent has three parts. Retrieval finds the passages. Tools let it ask for actions. The answer has to point back to its sources.

- **Retrieval:** Searching your own documents first, so the model answers from them.
- **Token:** A small piece of text, roughly a word or part of one.
- **Chunk:** A piece of a document that gets its own search index entry.
- **Tool:** A function the model can ask for, such as a search. Your code runs it.
- **Citation:** The file and clause an answer points to, so a reviewer can check it.

## How does the agent find the right passage?

Retrieval means searching your documents before the model writes a word, so the answer comes from the files themselves. The usual build cuts each document into chunks. Anthropic's write-up on retrieval says chunks are "usually no more than a few hundred tokens", which keeps each one small enough to search and to fit in the prompt.

*Diagram, From question to cited answer: A question goes to two searches at once. Their two lists are merged, and the model answers only from the merged top passages, naming the file for each claim.*
1. The question goes to the keyword search.
2. The same question goes to the meaning search.
3. Keyword hits go into the merge.
4. Meaning hits go into the merge too.
5. The merged top passages go to the model.
6. The model answers, and each claim names its file.

Keyword search, usually a scoring method called BM25 that rewards exact word matches, is strong at exact strings like a clause number, an error code or a date. Meaning search, built on embeddings (lists of numbers that capture meaning), finds the same idea written in other words, such as a clause that rolls over instead of renewing. Neither wins alone, so the usual build merges both lists with rank fusion. Each passage gets a score from where it ranks in each list, and the best total wins.

Anthropic describes Contextual Retrieval, a method that adds a short note to each chunk before it is indexed. The note says what the chunk is about and which document it came from. Plain chunks lose that context, so a search can miss the right passage. Anthropic's own figures are on the card below.

> "This method can reduce the number of failed retrievals by 49% and, when combined with reranking, by 67%" (Anthropic, on Contextual Retrieval)

1. **Chunk the contracts:** Split each contract by its clauses, so a clause is never cut in half by a fixed character count.
2. **Index every chunk twice:** Store it for exact-word search and as an embedding for meaning search. Exact clause numbers are matched most reliably by the first index, so keep it.
3. **Merge and keep the top few:** Fuse the two lists and send only the best few passages to the model, not the whole folder.
4. **Answer with the source:** The model names the contract and the clause number. Your code rejects any answer that has no source.

Here is the merge step in plain Python. No search engine runs. The two lists are typed in, so the code shows only the fusion.

```python
# Merge a keyword search and a meaning search with rank fusion.
# No real search engine here: both lists are typed in, as if two searches had returned them.
keyword_hits = ["MSA-14", "SOW-22", "NDA-03"]  # exact words: "renew", "notice"
meaning_hits = ["SOW-22", "AMD-07", "MSA-14"]  # same idea, other words: "rolls over"
K = 60  # a damping constant: how fast lower ranks lose weight

def fuse(*ranked_lists):
    scores = {}
    for hits in ranked_lists:
        for rank, doc in enumerate(hits, start=1):
            scores[doc] = scores.get(doc, 0) + 1 / (K + rank)
    return sorted(scores, key=lambda d: -scores[d])

for place, doc in enumerate(fuse(keyword_hits, meaning_hits)[:3], start=1):
    print(place, doc)
```

Output:

```text
1 SOW-22
2 MSA-14
3 AMD-07
```

## Which tools should the agent get, and who runs them?

A tool is a function the model may ask for. In this build the tools are search_documents, open_contract and draft_renewal_notice. The model never runs them itself. It writes a request, and your code decides whether to run it.

> "Client tools (including user-defined tools and tools with Anthropic-defined schemas, such as bash and text_editor) run in your application" (Anthropic, Claude tool use guide)

*Diagram, The agent loop with a tool: The loop: the model asks for a search, your code runs it, and the result goes back. The model stops once it has enough sources to answer, and the answer names them.*
1. The analyst's question goes to the model.
2. The model asks your code to run a search.
3. Your code runs it and sends the result back.
4. With enough sources, the model writes the answer.

- **Read tools: Search and open.** Cannot change anything, so safe to loop. Their text still reaches the model, so treat results as untrusted, and log every call.
- **Act tools: Draft a notice.** Changes something outside the app. It only writes a draft, and waits for a person to approve the exact text.

Tool design matters as much as the prompt. Anthropic's agent guide says: "A good tool definition often includes example usage, edge cases, input format requirements, and clear boundaries from other tools."

Set hard limits in code as well: a maximum number of steps, a timeout for each search, and a cap on how many files one question can open. A loop with no limit can run up a large bill and never stop.

### How would you stop a planted line in a contract from triggering a tool?

A vendor could hide a line in its PDF, an order that tells the agent to draft a notice to a new address. The model reads it as text, so it cannot reliably tell an order from data. OWASP's 2026 guidance says there is "no reliable prevention mechanism exists today".

So the design limits what a fooled model can do. Search and open tools return text and cannot send anything. Any action that leaves the system goes through a check in your code, and then a person approves the exact action. OWASP asks for this: "Require explicit human confirmation before any privileged, irreversible, or externally visible action".

## How do you know it works, and when is a simpler build enough?

Build a small test set before the agent: 30 to 50 real questions, each with the right answer and the right contract. Test the search and the answer separately. If the right clause never reaches the model, no prompt will fix it.

- **Log every tool call:** Keep each call and its result, so a bad answer can be traced.
- **Re-run the same test set:** Run it after every change, so a fix in one place cannot break another.
- **Show the clause used:** A reviewer checks the answer against the clause in one click.
- **Track the failures:** Write down which questions fail, and why, before you change anything.

Anthropic's guide says to start simple, and to add agent steps only when simpler solutions fall short.

> **Tip:** In the write-up, say which agent steps the task really needed, and which a single search and answer could have done. Reviewers notice a build that knows its own limits.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: the agent searches your files, uses tools, and cites its sources.
- [ ] Retrieval first: keyword and meaning search, merged, over chunks.
- [ ] Tools split into read and act, with a person approving any act.
- [ ] Honest limits: what it cannot read yet, and what it costs to run.
- [ ] A test set of real questions, scored in two parts.
- [ ] The simplest build first, with a reason for each agent step.

**Common traps**

- Trap: "The model checks its own answers, so the output is safe." Better: A second model call can make the same mistake. Check the answer against the source file and the rules in code.
- Trap: "Vector search is enough, so skip the keyword index." Better: Meaning search is weak at exact clause numbers and codes. Keep both indexes and merge them.
- Trap: "Add more tools and the agent gets better." Better: Each extra tool is one more thing to get wrong. Add one only when a test question needs it.

## Can you spot the risky design?

**Spot the risky tool:** A teammate's version of this agent has four tools. Which one is the risk?

A. search_documents(query): returns the top 5 passages with their file names
B. open_contract(file_id): returns the full text of one contract
C. draft_renewal_notice(vendor_id, text): saves a draft for a person to review
D. send_renewal_notice(vendor_id, text): emails the vendor as soon as the model calls it

**Answer:** D. Sending an email to a vendor changes something outside the system, and it cannot be taken back. The safe design only drafts, your code picks the vendor address, and a person approves the exact text.

**Quick check:** Keyword search missed a clause that says 'rolls over' when the analyst typed 'renew'. What is the most direct fix?

A. Add a meaning search and merge both lists with rank fusion
B. Write a longer system prompt that tells the model to try harder
C. Raise the temperature so the model guesses more widely
D. Switch to a bigger model and keep the search as it is

**Answer:** A. Meaning search finds passages that say the same thing in other words, and rank fusion merges it with the keyword results. A longer prompt or a bigger model cannot answer from a passage the search never returned.

## Can you answer these from memory?

**Flash cards**

- **What is a take-home?** A small build you do on your own time, judged on your choices and your honest limits.
- **Keyword vs meaning search?** Keyword finds exact words, like clause numbers. Meaning finds the same idea in other words.
- **What is rank fusion?** Merging two ranked lists, scoring each item by its place in both.
- **Read tool vs act tool?** Read tools only fetch. Act tools change something, so a person approves them first.
- **What must the model never do alone?** Run an action that leaves the system, like sending a notice to a vendor.
- **Where do you start?** The simplest build that passes your test set. Add agent steps only when it falls short.

## Likely follow-up questions

- Q133 What are common RAG failure modes? https://designervenkat.online/interview/ai/common-rag-failure-modes
- Q135 How do you add citations? https://designervenkat.online/interview/ai/how-do-you-add-citations
- Q140 How do you enforce access control in RAG? https://designervenkat.online/interview/ai/how-do-you-enforce-access-control-in-rag
- Q177 What makes a good tool set? https://designervenkat.online/interview/ai/what-makes-a-good-tool-set
- Q172 When and how do you add a human in the loop? https://designervenkat.online/interview/ai/human-in-the-loop-for-ai-agents
- Q181 How do you evaluate agents? https://designervenkat.online/interview/ai/how-to-evaluate-ai-agents

## Learn it in depth

- [Retrieval-augmented generation](https://designervenkat.online/learn/ai-engineering/rags)
- [From question to context](https://designervenkat.online/learn/ai-engineering/retrieval-process)
- [AI Agents](https://designervenkat.online/learn/ai-engineering/ai-agents)
