Skip to content
Forward Deployed

Forward Deployed
T15 exercise

Exercise: choose an architecture for the support assistant

Track
Architecture Decisions
By
Sourav Banerjee
Last updated
30 Nov 2026

Report an issue

01 Context

Problem statement

Larkspur Cloud's support assistant answers customers from the handbook. Three engineers each propose a design: plain RAG, a ReAct agent that searches the handbook as a tool, and plain RAG with a relevance check that refuses when the passages do not answer. You build a small version of each with the same local model, run them on the same 20 questions, and write the decision record.

The requirement is that a wrong answer costs a support ticket and a customer who acted on bad advice. A refusal costs a ticket only. So the rule has three steps. First, keep only the designs with no wrong answers. Then, of those, take the one with the fewest refusals of questions the handbook answers. When two designs differ by a single question, treat it as a tie and keep the one with fewer model calls. This is lesson 3 of T15.1's rule: a component earns its place only with a measured gain that nothing cheaper buys.

02 Outcomes

What you will learn

  • Build three candidate architectures from lesson 3 of T15.1's decision chain on one shared retriever and one shared answer prompt.
  • Score every reply as correct, declined or wrong, and count model calls per question the same way for a chain, a graph and an agent.
  • Read the per-question rows to name the stage that failed: retrieval, the grader or the model's own choice.
  • Write a decision record that justifies each component against the simpler design.
  • Explain why a loop can cost more calls without fixing a retrieval miss.

03 Setup

Before you start

Lessons

Dataset

The Larkspur Cloud handbook (13 files) and its golden set, plus answer_checks.jsonl, in data/. The exercise runs 20 golden questions: 15 the handbook answers (9 lookup, 4 multi-hop, 2 numeric) and the 5 out-of-corpus ones, whose only correct reply is the refusal.

Code

load_handbook, load_jsonl, tfidf_retriever, is_hit and normalise from src/lab_kit.py, RecursiveCharacterTextSplitter, ChatOllama, and create_agent with ModelCallLimitMiddleware from langchain.agents.

Environment

The course's default environment (uv run jupyter lab) and a local Ollama server with ollama pull qwen2.5:3b. Everything runs offline with no API keys. Retrieval is TF-IDF, so no embedding model is needed. The whole run makes about 130 model calls and took about 4 minutes on an Apple-silicon laptop with the server to itself.

04 Architecture

Experiment workflow

The chunks, the retriever at k = 4, the model, the answer prompt, the refusal sentence and the 20 questions stay fixed. Only the architecture around them changes.

Diagram: Load the handbook, the golden set and the answer checks; Shared: recursive 500 / 50 chunks, TF-IDF k = 4, qwen2.5:3b; A: plain RAG, retrieve then answer; B: ReAct agent, search tool, at most 4 calls; C: retrieve, grade, then answer or refuse; Score each reply correct, declined or wrong, and count calls; Read the questions where the candidates disagree; Write the decision recordDiagram: Load the handbook, the golden set and the answer checks; Shared: recursive 500 / 50 chunks, TF-IDF k = 4, qwen2.5:3b; A: plain RAG, retrieve then answer; B: ReAct agent, search tool, at most 4 calls; C: retrieve, grade, then answer or refuse; Score each reply correct, declined or wrong, and count calls; Read the questions where the candidates disagree; Write the decision record

Extension: a fourth row, C with one query rewrite before it refuses, scored the same way.

05 Build

Implementation tasks

  1. Task 1: Load the data

    Load the handbook and the golden set from data/larkspur/ and the 20 questions with their facts from data/answer_checks.jsonl. Split the handbook with the recursive splitter and build one TF-IDF retriever that every candidate shares.

    RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)
    tfidf_retriever(chunks, k=4)
    ChatOllama(model="qwen2.5:3b", temperature=0)
    
  2. Task 2: Write one scorer and one call counter

    Score each reply in one of three ways. A reply that contains the refusal sentence is correct for an out-of-corpus question and declined for any other. Any other reply is correct when it mentions every fact of its question, and wrong when it misses one or answers an out-of-corpus question. Count model calls with a callback that adds one each time a chat model starts, and pass it in the config of every call.

    New here: the callback counter is a few lines on BaseCallbackHandler.on_chat_model_start, and the fact check is a substring test on normalise(answer). Earlier labs counted calls by hand for each design.

  3. Task 3: Candidate A: plain RAG

    Retrieve the top 4 chunks and make one answer call. The prompt says to use only the numbered passages and to reply with the refusal sentence when they do not answer.

  4. Task 4: Candidate B: a ReAct agent

    Give create_agent one tool, search_handbook, that wraps the same retriever, and cap the loop with ModelCallLimitMiddleware(run_limit=4). Collect the chunks the tool returned, so you can say whether the agent saw the evidence, and record which questions it answered without searching at all.

  5. Task 5: Candidate C: plain RAG with a relevance check

    Retrieve the top 4 chunks, then make one grader call with structured output, relevant: bool, as in the T9.1 lab. A "no" returns the refusal sentence with no answer call. A "yes" goes on to A's answer call.

  6. Task 6: Read the disagreements

    Make the results table, then list every question where the candidates disagree, with whether the evidence was in the retrieved chunks. Read the answer behind every "wrong" and "declined". For each one, name the failing stage: retrieval (the evidence was not retrieved), the grader (it was retrieved and the grader said no) or the model (it skipped the tool or refused passages that held the answer).

  7. Task 7: Write the decision record

    Apply the rule from the problem statement to the table. Then write one row per component in lesson 3 of T15.1's format: the failure it fixes, the simpler alternative, the measured gain and the calls it adds.

  8. Task 8: Extension: one rewrite before the refusal

    When C's grader says no, rewrite the question once in handbook words, retrieve again and grade again (the T9.1 retry loop, with one retry). Add it as a fourth row and say which declined question it recovers, at what cost in calls.

06 Measure

Record results

What you enter stays in this browser only.

CandidateCorrectDeclinedWrongOut-of-corpus refusedCalls per questionSeconds per question
A plain RAG1.0
B ReAct agent
C graded RAG
D graded RAG + 1 rewrite (extension)
Decision

Correct, declined and wrong count the 20 questions and sum to 20. Out-of-corpus refused counts the 5 out-of-corpus questions the candidate refused. Seconds depend on the machine and on what else the Ollama server is doing, so compare them only within one run.

07 Verify

Done when

0 of 4 done

What you enter stays in this browser only.

08 Debug

Common mistakes

Counting a refusal as a wrong answer

They cost different things here. A refusal sends the customer to a ticket. A wrong answer sends them away with bad advice. Keep the two columns apart, or the rule cannot be applied.

Trusting the keyword check without reading

A paraphrase outside the accepted phrasings is marked wrong, and a reply that opens with the refusal and then answers anyway is marked declined. Read every reply that is not correct before you count it.

Comparing calls without comparing answers

An agent that refuses at once makes 1 call and looks cheap. Its calls per question say nothing until you know whether it searched.

Treating a one-question gap as a win

On 20 questions one question moves a count by 5 points. Call it a tie and keep the cheaper design, as the T15.1 lab does.

09 Transfer

Interview angle

“Your RAG assistant sometimes gives wrong answers. Would you move to an agent?”

Show a model answer

Not before reading which stage fails. Run the candidates on one golden set, score correct, declined and wrong separately, and count model calls. On our run the agent skipped its search on 13 of 20 questions. A one-call grader removed the only wrong answer. The miss that remained was a retrieval miss, so the next fix is retrieval, not a loop.

10 Review

Worked solution

The worked solution is solution/p14_exercise_solution.ipynb (open in Colab). Locally, open it from exercise/solution/ so ../data/ resolves, start Ollama, and run it top to bottom with the default environment. In Colab, clone the repository and install Ollama first, because the notebook reads the corpus and src/lab_kit.py from the repository and calls a local model.

Show our run and the reasoning

Our run: qwen2.5:3b through Ollama 0.40.6, langchain 1.4.7, langchain-ollama 1.1.0 and scikit-learn 1.9.1, offline.

Candidate Correct Declined Wrong Out-of-corpus refused Calls per question Seconds per question
A plain RAG 17 2 1 5 1.0 8.2
B ReAct agent 9 10 1 5 1.4 4.1
C graded RAG 15 5 0 5 1.6 1.3
D graded RAG + 1 rewrite (extension) 16 4 0 5 2.5 4.1
Decision C graded RAG

The verdicts were the same in two full runs. The seconds were not, because 12 other jobs shared the Ollama server: plain RAG took 1.9 seconds per question in the first run and 8.2 in the second. Read the seconds as noise and the calls as the budget.

Plain RAG gives one wrong answer, g02. "What happens if my server goes down?" retrieves no outage evidence, because the handbook says "outage" and the question says "goes down". The model answers from the reboot passage it did get, with reboot advice. This is lesson 3 of T15.1's outage question, and the failure is in retrieval. A also declines g21 with the maintenance evidence in its passages, and g03 opens with the refusal sentence and then gives the 30-day answer. The scorer counts that as declined.

The ReAct agent is ruled out. It answered 13 of the 20 questions without calling its search tool. Nine of those were answerable questions it declined, and four were out-of-corpus questions it refused correctly but by chance. It searched on only 7 questions. When it did search g02, it got the same wrong chunks as A and wrote a longer wrong answer. Its 1.4 calls per question look cheap only because it mostly did not work. A 3B model's tool choice is the failing stage here, and the rule needs no more than its one wrong answer to rule it out.

Graded RAG is the only design with no wrong answers at the lowest cost. The grader refuses g02 at 1 call instead of answering it wrongly. The price is three questions the grader turned down although the evidence was in the top 4: g12, g17 and g21. A answered g12 and g17 correctly from the same passages. So C declines 5 against A's 2, at 1.6 calls per question against 1.0.

The rewrite does not earn its place. D recovers g17 on its rewrite, at 4 calls for that question, and leaves g02 declined. Its rewritten query still did not reach the outage chunks. That is one question for 0.9 more calls per question, a tie by the rule, so C stays. D's g02 is lesson 3 of T15.1's loop over a miss in small form: 3 calls to work around a retrieval failure that a rewrite did not fix.

The decision record, in lesson 3 of T15.1's format:

Component Failure it fixes Simpler alternative Measured gain Calls added
Relevance grader g02 answered wrongly from unrelated chunks plain RAG wrong answers 1 to 0, at a cost of 3 more declines (g12, g17, g21) 1 more on an answered question, none on a refusal
Query rewrite before refusing g17 declined by the grader grader alone g17 recovered, g02 not, a tie on 20 questions 0.9 per question on average, up to 3
ReAct agent loop none on this set plain RAG none: 13 questions answered without a search none kept

The next change is the retrieval stage. Lesson 3 of T15.1 fixes the outage miss with dense retrieval at no extra model calls, and the grader's three false refusals are the next thing to measure. This exercise kept TF-IDF so that every candidate shared one retriever.