Skip to content
Visual explainer 5h to learn 4 steps

Agentic RAG capstone: design the assistant and its targets

Write a design that fixes the corpus, caller scopes, model-only baseline, schemas, allowed tools, budgets and evaluation targets.

By Invicly Tech, , in Generative AI, Agentic AI and RAG. About 13 minutes to read.

Topic 32 of 34

In short

The design is the contract for the whole capstone. Before writing code you fix the corpus of 10 to 20 versioned synthetic documents in two permission scopes, the model-only baseline, the request and response schemas, the allowed read-only tools, the budgets and the evaluation targets. Fixing these first means all three versions are judged by the same rules, not rules adjusted after seeing results.

Think of it like this: It is like writing the exam and the marking scheme before teaching the class, so nobody can move the pass mark later.

Explained simply

The capstone pulls the whole path into one small product: an internal knowledge assistant for a fictional company, Contoso. It answers staff questions from a handful of policy documents. You build it three ways and compare them. The first step is not code. It is a short design document that says exactly what you will build and how you will judge it.

Start with the documents. Write 10 to 20 short synthetic files, such as a travel policy, a leave policy and an expense guide. Give each one an ID, a version number and the date it takes effect. Mark each as general, which every employee may read, or finance, which only finance staff may read. Keep an old version of one policy so you can test stale sources.

Next, write down the shape of a request and a response. Every version of the assistant, model-only, fixed RAG and agent, returns the same response: an answer or a status, the IDs of the sources it used, and a reason when it refuses or hands off. One shared shape is what makes a fair comparison possible.

Finally, set the limits and the targets. The agent gets a short list of read-only tools, a maximum number of tool calls, a token budget and a deadline. Then write 20 test cases and the scores you need, such as high retrieval recall and zero finance documents shown to general callers. Writing targets first stops you moving the goalposts.

Press Play on a diagram to walk through it one step at a time.

FlowIngestion path (offline, batch)
  1. 1
    Source files

    Markdown with doc ID, version, scope and effective date

  2. 2
    Parse and validate

    Reject missing metadata, log failed parses

  3. 3
    Chunk by heading

    Stable section IDs such as POL-003#2

  4. 4
    Embed and index

    pgvector column plus full-text column, model recorded

  5. 5
    Publish index build

    Mark superseded versions as not current

FlowQuery path (online, per caller)
  1. 1
    Authenticated request

    Scope comes from the verified token

  2. 2
    Choose mode

    Model-only, fixed RAG or bounded agent

  3. 3
    Scoped retrieval

    Scope and current-version filter inside SQL

  4. 4
    Draft

    Only from permitted evidence

  5. 5
    Validate citations

    Every ID must be in this request's evidence

  6. 6
    Respond

    Status, answer, citation IDs and reason

LayersCapstone repository layout
  1. 1
    api/

    FastAPI app, authentication, request IDs

  2. 2
    assistant/

    Model-only, fixed RAG and the agent loop

  3. 3
    retrieval/

    Hybrid search SQL with the scope filter

  4. 4
    ingest/

    Parse, chunk, embed and publish

  5. 5
    fixtures/

    Corpus, 20 cases, scripted model replies

  6. 6
    tests/ and eval/

    pytest checks and the report script

In depth

Designing the corpus and its two scopes

Keep the corpus small enough to read in one sitting, so you can label the expected source for every test question by hand. Store each document as Markdown with front matter: doc_id, title, version, scope, effective_from, supersedes and source_uri. Split on headings and give every section a stable ID such as POL-003#2. Cite with the version attached, POL-003#2@v2, so a stale citation is easy to spot.

Plant traps on purpose. Keep travel policy v1, which says book 30 days ahead, beside v2, which says 14 days. Add a finance-only document whose topic overlaps a general one. Make one question that needs two documents, and one that no document answers. These traps become fixture cases later.

  • 10 to 20 documents, two scopes: general and finance
  • At least one superseded version
  • At least one finance-only topic a general caller might ask about
  • At least one question that needs two documents
  • At least one question nothing answers
MapExample corpus plan
Contoso corpus v1
  • General scope
    • Travel policy v1 (superseded)
    • Travel policy v2
    • Leave policy
    • IT access guide
    • Office handbook
  • Finance scope
    • Approval limits
    • Vendor payment runbook
    • Quarter-close calendar
  • Planned traps
    • Stale travel rule
    • Finance topic that overlaps a general one
    • Answer needs two documents
    • Question with no source

Schemas, tools and the trusted identity

Define the contracts in Pydantic: AskRequest, AskResponse, a Caller with user ID and scopes, and one input and output model per tool. The agent gets three read-only tools. search_docs takes a query and k, capped at 8, and returns section IDs, titles and short snippets. get_section takes a section ID and returns its text or not-found. get_ticket_status is a typed mock that returns a scripted status for a ticket ID.

The caller's scope is not a tool argument. The server passes the verified Caller into every tool call, so text in a question or a retrieved passage cannot widen access. There are no write tools in the capstone. Each tool has its own timeout, for example 2 seconds, and returns minimal data.

  • search_docs(query, k) returns hits for the caller's scopes only
  • get_section(section_id) returns text or not-found
  • get_ticket_status(ticket_id) is a scripted, read-only mock
  • Scope is injected by the server and absent from tool schemas

Budgets and stop rules for each version

Every run must end in exactly one status: answered, clarify, abstained or escalated. Write starting budgets and say they are starting points you will revisit only with evidence. A reasonable set for this corpus: at most 4 tool calls, at most 2 query reformulations, about 6,000 input tokens, 2 seconds per tool and 8 seconds for the whole request. Fixed RAG gets one search with top 5 and a context limit of about 3,000 tokens. Model-only gets one call.

When a budget runs out, the agent stops and returns the best permitted response: an answer only if its citations validate, otherwise abstained with budget_exhausted. A tool timeout returns escalated with tool_timeout. Model-only cannot cite, so its answers are recorded and scored as unsupported rather than rejected by the schema.

CompareThe three versions under one contract
Model-only
  • One model call
  • No documents or tools
  • Citations always empty
  • Scored as unsupported when it answers
Fixed RAG
  • One scoped hybrid search, top 5
  • One generation call
  • Citations validated
  • No loop, no reformulation
Bounded agent
  • Routes, searches, reformulates, looks up
  • At most 4 tool calls and 8 seconds
  • Same citation validation
  • Always ends in a status

The 20-case fixture plan and targets

Spread the 20 cases across behaviours rather than writing 20 easy questions. A balanced plan: 8 answerable from one document, 2 that need two documents, 2 with a stale source, 2 ambiguous questions that need clarification, 2 with no evidence, 2 denied-access requests from a general caller, and 2 tool timeouts where the mock ticket tool sleeps past its limit. Each case records an ID, caller, question, expected status per mode, expected sources, forbidden documents and any injected fault.

Then write targets, for example: recall@5 of at least 0.9 on answerable cases, citation support of at least 0.95, correct status on at least 18 of 20 cases for the agent, p95 latency under 8 seconds in fixture mode, and zero cross-scope disclosures as a hard gate.

  • 8 single-document, 2 two-document
  • 2 stale source, 2 ambiguous
  • 2 no evidence, 2 denied access
  • 2 tool timeouts
  • Zero cross-scope disclosures is a gate, not an average

Learn it in 4 short steps

About 1h 15m each. Track them with a timer in your plan.

  1. 1
    Define 10–20 versioned documents in two scopes~1h 15m
  2. 2
    Diagram ingestion and querying separately~1h 15m
  3. 3
    Specify schemas, tools and budgets~1h 15m
  4. 4
    Write a 20-case fixture plan and targets~1h 15m

Key points

  • Write the design before code and treat later changes to it as versioned decisions.
  • Use two scopes, such as general and finance, and include finance-only content that a general caller might ask about.
  • One response schema serves all three versions, so their results can be compared fairly.
  • Budgets for tool calls, tokens and time are part of the design, not knobs added later.
  • Set evaluation targets, including zero cross-scope disclosures, before the first run.

Key terms

Tap a card to flip it. 0/6 known

Examples

python
from typing import Literal
from pydantic import BaseModel, Field
Mode = Literal["model_only", "fixed_rag", "agent"]

class AskRequest(BaseModel):
    question: str = Field(min_length=3, max_length=2000)
    mode: Mode = "agent"
class AskResponse(BaseModel):
    request_id: str
    mode: Mode
    status: Literal["answered", "clarify", "abstained", "escalated"]
    answer: str | None = None
    citations: list[str] = []      # section IDs such as "POL-003#2@v2"
    reason: str | None = None      # why it abstained, escalated or asked

One request and one response shape shared by all three versions

Front matter for a current policy

Each document carries the metadata that ingestion, retrieval filters and citations rely on. The version and supersedes fields let you test stale sources, and the scope field drives the permission filter. A file missing any required field is rejected and logged during ingestion instead of being indexed without a scope.

markdown
---
doc_id: POL-003
title: Travel policy
version: 2
scope: general
effective_from: 2026-03-01
supersedes: POL-003@v1
source_uri: fixtures/corpus/pol-003-v2.md
---
## 1. Booking
Book flights at least 14 days before travel.
## 2. Daily allowance
Claim meals against the daily allowance table in section 3.

One denied-access fixture case

A general caller asks about vendor payment approval limits, which only the finance document FIN-002 covers. The expected outcome is abstained with the same generic reason used for missing evidence, so the response does not confirm that a hidden document exists. forbidden_docs lets the test fail if FIN-002 is ever cited.

json
{
  "id": "C14",
  "caller": {"user": "ana@example.com", "scopes": ["general"]},
  "question": "What is the approval limit for vendor payments?",
  "expected_status": {"model_only": "abstained", "fixed_rag": "abstained", "agent": "abstained"},
  "expected_sources": [],
  "forbidden_docs": ["FIN-002"],
  "reason": "no_permitted_evidence",
  "fault": null
}

Quick reference

  • Corpus: 10 to 20 synthetic documents, each with doc_id, version, scope, effective_from and source_uri.
  • Cite sections with their version, for example POL-003#2@v2, so stale citations are detectable.
  • Scope comes from the verified token on the server, never from the question or a tool argument.
  • One AskResponse for all three versions: request_id, mode, status, answer, citations, reason.
  • Statuses: answered, clarify, abstained, escalated. Every run ends in exactly one.
  • Example agent budget: 4 tool calls, 2 reformulations, 2 s per tool, 8 s per request.
  • Zero cross-scope disclosures across the whole 20-case suite is a hard release gate.

Common mistakes

  • Writing the test questions after building the system, so they quietly match what it already does well.
  • Taking the caller's scope from the request body or the question text instead of the verified token.
  • Using real company or personal data in the corpus. Keep every document synthetic.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1Why does the design use one response schema for all three versions?

Question 2

2A general caller asks about vendor payment approval limits, covered only by a finance document. What is the designed outcome?

Question 3

3Which parameter should not appear in the search_docs tool schema?

Question 4

4Why keep a superseded version of a policy in the corpus?

Question 5

5When should the evaluation targets be written?

0/5 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Write the front matter for three documents: a current general policy, its superseded earlier version, and a finance-only runbook.

  2. Exercise 2medium

    Extend AskResponse so that an answered response from fixed_rag or agent must have an answer and at least one citation, and abstained or escalated responses must have a reason.

  3. Exercise 3hard

    Write the 20-case fixture plan as counts by category and caller scope, and state each evaluation target with how it is computed.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Can I do the capstone without a paid model API?
Yes. Fixture mode uses a deterministic fake model and precomputed or local embeddings, so the full suite runs offline at no cost. A hosted or local model run is optional; label its numbers separately as live-model results.
Why only 10 to 20 documents?
That is small enough to label every expected source by hand and read every failure. The capstone tests decisions and safety, not scale.
Do I need a real identity provider for the two scopes?
No. In fixture mode, sign test tokens locally with a development-only secret or map static test tokens to users. Note in the design that production would use your organisation's identity provider.

Go deeper

ShareXLinkedInWhatsApp