Skip to contentমূল লেখায় যান

Topic 44 · AI/ML testingটপিক 44 · AI/ML testing

Advanced Capstone Setup: A Production RAG Application with an Agent Layer

The first capstone answered questions. This one has to decide what to do.

7 min read7 মিনিটে পড়া যায় · 6 sections6টি সেকশন · 5 sources5টি সোর্স · updated Nov 2026আপডেট: Nov 2026

The agent routes a question to one of three nodesএজেন্ট একটা প্রশ্নকে তিনটা node-এর একটায় পাঠায়

Send four questions and watch route() pick search_docs, check_order or escalate, including a follow-up that reuses an order id.চারটা প্রশ্ন পাঠান আর দেখুন route() কীভাবে search_docs, check_order বা escalate বেছে নেয়, যার মধ্যে একটা ফলো-আপ আগের order id আবার ব্যবহার করে।

3 min3 মিনিট8 steps8টি ধাপ
  • Branch chosenবেছে নেওয়া শাখা—
  • order_id in statestate-এ order_idempty
  • Tool calls loggedলগ করা টুল কল0
  • Chunks mergedমেশানো চাঙ্ক0
What is your return policy?আপনাদের রিটার্ন নীতি কী?Agentএজেন্টroute()route()order_id: emptyorder_id: খালিsearch_docssearch_docsmock RAGRAG চেইনcheck_ordercheck_ordermock toolমক টুলescalateescalateto a humanমানুষের কাছে

You’ll learnআপনি শিখবেন

  • route() picks one of three nodesroute() তিনটা node-এর একটা বাছে
  • Multi-source retrieval merges 3 × 3 chunksMulti-source retrieval 3 × 3 চাঙ্ক মেশায়
  • State remembers order_id across turnsstate turn জুড়ে order_id মনে রাখে
  • A handoff phrase escalates firsthandoff বাক্য সবার আগে escalate করে
  • Merged sources can disagreeমেশানো উৎস একমত নাও হতে পারে

In plain words

The advanced capstone is the Phase 1 capstone's harder sibling: still a RAG application retrieving from documents at answer time Source 3সোর্স 3, backed by a vector store Source 4সোর্স 4, but with two differences that change what the test suite has to cover. First, it pulls from multiple sources — a company knowledge base, product documentation, and an FAQ database — rather than one Source 5সোর্স 5. Second, it has an agent layer built with LangGraph on top of the chain Source 1সোর্স 1: it does not just answer, it decides whether to search documents, check an order's status through a tool, or hand the conversation to a human.

That agent layer is what the rest of this module's tests target. A chatbot that only retrieves and answers can be wrong about a fact. An agent that also acts can be wrong about whether to act at all — and testing that decision is a different problem from testing an answer's accuracy.

সহজ English

This capstone is a harder version of the Phase 1 capstone. It is still a RAG application. That means it looks up documents when it answers Source 3সোর্স 3. The documents live in a vector store Source 4সোর্স 4.

Two things are different, and both change what you must test.

First, it uses many sources. These are a company knowledge base, product documentation, and an FAQ database Source 5সোর্স 5. Phase 1 used only one.

Second, it has an agent layer, built with LangGraph on top of the chain Source 1সোর্স 1. The agent does more than answer. It decides what to do. It can search documents, check an order's status with a tool, or pass the chat to a human.

The rest of this module tests that agent layer. A chatbot that only answers can get a fact wrong. An agent that also acts can be wrong about whether to act at all. Testing that choice is a different job from checking whether an answer is accurate.

বাংলা ব্যাখ্যা

Advanced capstone হলো Phase 1 capstone-এর কঠিন ভাইবোন: তখনও একটা RAG application যা answer time-এ document থেকে retrieve করে Source 3সোর্স 3, একটা vector store দিয়ে সমর্থিত Source 4সোর্স 4, কিন্তু দুটো পার্থক্য আছে যা test suite-কে কী কভার করতে হবে তা বদলে দেয়। প্রথমত, এটা একাধিক উৎস থেকে টানে — একটা কোম্পানির knowledge base, product documentation, আর একটা FAQ database — একটার বদলে Source 5সোর্স 5। দ্বিতীয়ত, chain-এর ওপর LangGraph দিয়ে বানানো একটা agent layer আছে Source 1সোর্স 1: এটা শুধু উত্তর দেয় না, এটা সিদ্ধান্ত নেয় document খুঁজবে কিনা, একটা tool দিয়ে একটা order-এর status চেক করবে কিনা, নাকি কথোপকথন একজন মানুষের হাতে দেবে কিনা।

সেই agent layer-ই এই module-এর বাকি টেস্টের লক্ষ্য। একটা chatbot যা শুধু retrieve করে আর উত্তর দেয় একটা তথ্যে ভুল করতে পারে। একটা agent যা কাজও করে আদৌ কাজ করা উচিত কিনা তাতে ভুল করতে পারে — আর সেই সিদ্ধান্ত টেস্ট করা একটা উত্তরের সঠিকতা টেস্ট করা থেকে আলাদা সমস্যা।

How it works

The architecture adds one layer on top of the Phase 1 capstone's chain:

question -> agent (LangGraph) -> decides: search docs | check order | escalate
                                       |
                            search docs: retriever (multi-source) -> model -> answer
                            check order: mock order-status tool -> model -> answer
                            escalate:    hand off, with the conversation so far

The agent reads the question first, then routes to one of three nodes with a conditional edge Source 2সোর্স 2.

Multi-source retrieval means the retriever queries more than one collection — knowledge base, product docs, FAQ — and merges the results, which introduces a new failure mode the single-source Phase 1 capstone never had: two sources disagreeing, or one source's chunk outranking a more relevant one from another source. This failure mode is the tutorial's own analysis; Chroma itself only stores and searches each collection Source 4সোর্স 4.

The mock order-status tool exists specifically so the agent's tool-use decision can be tested without a real backend: it returns a fixed set of order states, and the test suite's job is to confirm the agent calls it only when the question is actually about an order, and passes it the correct order id extracted from the conversation.

সহজ English

This design adds one layer on top of the Phase 1 chain:

question -> agent (LangGraph) -> decides: search docs | check order | escalate
                                       |
                            search docs: retriever (multi-source) -> model -> answer
                            check order: mock order-status tool -> model -> answer
                            escalate:    hand off, with the conversation so far

The agent reads the question first. It then routes to one of three nodes with a conditional edge Source 2সোর্স 2.

Multi-source retrieval means the retriever searches more than one collection. These are the knowledge base, the product docs, and the FAQ. It then merges the results. This brings a new kind of failure that Phase 1 never had. Two sources can disagree. Or a chunk from one source can rank above a more relevant chunk from another. This is the tutorial's own analysis. Chroma itself only stores and searches each collection Source 4সোর্স 4.

The mock order-status tool lets you test the agent's tool choice without a real backend. It returns a fixed set of order states. Your tests must confirm two things. The agent calls the tool only when the question is really about an order. And it passes the right order id, taken from the conversation.

বাংলা ব্যাখ্যা

Architecture Phase 1 capstone-এর chain-এর ওপর একটা layer যোগ করে:

question -> agent (LangGraph) -> decides: search docs | check order | escalate
                                       |
                            search docs: retriever (multi-source) -> model -> answer
                            check order: mock order-status tool -> model -> answer
                            escalate:    hand off, with the conversation so far

এজেন্ট আগে প্রশ্নটা পড়ে, তারপর একটা conditional edge দিয়ে তিনটা node-এর একটায় route করে Source 2সোর্স 2।

Multi-source retrieval মানে retriever একাধিক collection-এ query করে — knowledge base, product docs, FAQ — আর ফলাফল মিশায়, যা একটা নতুন ব্যর্থতা মোড নিয়ে আসে যা একক-উৎস Phase 1 capstone-এর কখনো ছিল না: দুটো উৎস একমত না হওয়া, বা একটা উৎসের chunk অন্য উৎসের একটা বেশি প্রাসঙ্গিক chunk-কে ছাড়িয়ে যাওয়া। এই ব্যর্থতা মোডটা tutorial-এর নিজস্ব বিশ্লেষণ; Chroma নিজে শুধু প্রতিটা collection সংরক্ষণ ও খোঁজে Source 4সোর্স 4।

Mock order-status tool বিশেষভাবে এজন্য আছে যাতে agent-এর tool-use সিদ্ধান্ত একটা real backend ছাড়াই টেস্ট করা যায়: এটা একটা স্থির order state সেট ফেরত দেয়, আর test suite-এর কাজ নিশ্চিত করা agent এটা শুধু তখনই কল করে যখন প্রশ্নটা আসলেই একটা order সম্পর্কে, আর কথোপকথন থেকে বের করা সঠিক order id এটাকে পাঠায়।

In practice

A LangGraph agent with three branches Source 2সোর্স 2:

import re
from typing import TypedDict
from langgraph.graph import END, START, StateGraph

class AgentState(TypedDict, total=False):
    question: str
    context: list
    answer: str
    order_id: str      # remembered across turns
    tool_calls: list   # one entry per tool call, for tests to inspect

HANDOFF_PHRASES = ("speak to a manager", "talk to a human")

def extract_order_id(text: str):
    match = re.search(r"#(\d+)", text)
    return match.group(1) if match else None

def route(state: AgentState) -> str:
    question = state["question"].lower()
    if any(phrase in question for phrase in HANDOFF_PHRASES):
        return "escalate"
    if "order" in question and extract_order_id(question):
        return "check_order"
    if state.get("order_id") and ("order" in question or "status" in question):
        return "check_order"  # follow-up turn: reuse the remembered order id
    return "search_docs"

def check_order_node(state: AgentState) -> dict:
    order_id = extract_order_id(state["question"]) or state["order_id"]
    # call the deterministic mock order-status tool here, then record the call
    call = {"name": "check_order", "arguments": {"order_id": order_id}}
    return {"order_id": order_id, "tool_calls": state.get("tool_calls", []) + [call]}

graph = StateGraph(AgentState)
graph.add_node("search_docs", search_docs_node)
graph.add_node("check_order", check_order_node)
graph.add_node("escalate", escalate_node)
graph.add_conditional_edges(START, route, {
    "search_docs": "search_docs", "check_order": "check_order", "escalate": "escalate",
})
for node in ("search_docs", "check_order", "escalate"):
    graph.add_edge(node, END)
agent = graph.compile()

Multi-source retrieval merging three collections Source 4সোর্স 4:

def search_docs_node(state: dict) -> dict:
    hits = []
    for collection in (knowledge_base, product_docs, faq):
        hits += collection.query(query_texts=[state["question"]], n_results=3)["documents"][0]
    return {**state, "context": hits, "answer": generate(state["question"], hits)}

A test of the routing decision itself, before any model call:

import pytest

ROUTING_CASES = [
    ("Where is order #4821?", "check_order"),
    ("What is your return policy?", "search_docs"),
    ("I want to speak to a manager, this is unacceptable.", "escalate"),
]

@pytest.mark.parametrize("question, expected_branch", ROUTING_CASES)
def test_the_agent_routes_to_the_correct_branch(question, expected_branch):
    assert route({"question": question}) == expected_branch

Tutorial advice

This advice is the tutorial's own. It does not come from the sources.

  • Test the routing function directly, separately from the full agent run; it is cheap and it is where most decision bugs live.
  • Keep the mock order-status tool deterministic, with a fixed, documented set of order ids and states, so a test failure is never "the mock data changed".
  • Log which branch the agent took on every real call, from the first day of testing, not added later when a routing bug is suspected.

সহজ English

Here is a LangGraph agent with three branches Source 2সোর্স 2:

import re
from typing import TypedDict
from langgraph.graph import END, START, StateGraph

class AgentState(TypedDict, total=False):
    question: str
    context: list
    answer: str
    order_id: str      # remembered across turns
    tool_calls: list   # one entry per tool call, for tests to inspect

HANDOFF_PHRASES = ("speak to a manager", "talk to a human")

def extract_order_id(text: str):
    match = re.search(r"#(\d+)", text)
    return match.group(1) if match else None

def route(state: AgentState) -> str:
    question = state["question"].lower()
    if any(phrase in question for phrase in HANDOFF_PHRASES):
        return "escalate"
    if "order" in question and extract_order_id(question):
        return "check_order"
    if state.get("order_id") and ("order" in question or "status" in question):
        return "check_order"  # follow-up turn: reuse the remembered order id
    return "search_docs"

def check_order_node(state: AgentState) -> dict:
    order_id = extract_order_id(state["question"]) or state["order_id"]
    # call the deterministic mock order-status tool here, then record the call
    call = {"name": "check_order", "arguments": {"order_id": order_id}}
    return {"order_id": order_id, "tool_calls": state.get("tool_calls", []) + [call]}

graph = StateGraph(AgentState)
graph.add_node("search_docs", search_docs_node)
graph.add_node("check_order", check_order_node)
graph.add_node("escalate", escalate_node)
graph.add_conditional_edges(START, route, {
    "search_docs": "search_docs", "check_order": "check_order", "escalate": "escalate",
})
for node in ("search_docs", "check_order", "escalate"):
    graph.add_edge(node, END)
agent = graph.compile()

This next code searches three collections and merges what it finds Source 4সোর্স 4:

def search_docs_node(state: dict) -> dict:
    hits = []
    for collection in (knowledge_base, product_docs, faq):
        hits += collection.query(query_texts=[state["question"]], n_results=3)["documents"][0]
    return {**state, "context": hits, "answer": generate(state["question"], hits)}

This test checks the routing choice alone. It runs before any model call:

import pytest

ROUTING_CASES = [
    ("Where is order #4821?", "check_order"),
    ("What is your return policy?", "search_docs"),
    ("I want to speak to a manager, this is unacceptable.", "escalate"),
]

@pytest.mark.parametrize("question, expected_branch", ROUTING_CASES)
def test_the_agent_routes_to_the_correct_branch(question, expected_branch):
    assert route({"question": question}) == expected_branch

Tutorial advice. This advice is the tutorial's own. It does not come from the sources.

  • Test the routing function directly, apart from the full agent run. It is cheap, and most decision bugs live there.
  • Keep the mock order-status tool deterministic. Use a fixed, documented set of order ids and states. Then a failure is never "the mock data changed".
  • Log which branch the agent took on every real call. Start on the first day of testing. Do not wait until you suspect a routing bug.

বাংলা ব্যাখ্যা

তিনটা শাখা সহ একটা LangGraph agent Source 2সোর্স 2:

import re
from typing import TypedDict
from langgraph.graph import END, START, StateGraph

class AgentState(TypedDict, total=False):
    question: str
    context: list
    answer: str
    order_id: str      # remembered across turns
    tool_calls: list   # one entry per tool call, for tests to inspect

HANDOFF_PHRASES = ("speak to a manager", "talk to a human")

def extract_order_id(text: str):
    match = re.search(r"#(\d+)", text)
    return match.group(1) if match else None

def route(state: AgentState) -> str:
    question = state["question"].lower()
    if any(phrase in question for phrase in HANDOFF_PHRASES):
        return "escalate"
    if "order" in question and extract_order_id(question):
        return "check_order"
    if state.get("order_id") and ("order" in question or "status" in question):
        return "check_order"  # follow-up turn: reuse the remembered order id
    return "search_docs"

def check_order_node(state: AgentState) -> dict:
    order_id = extract_order_id(state["question"]) or state["order_id"]
    # call the deterministic mock order-status tool here, then record the call
    call = {"name": "check_order", "arguments": {"order_id": order_id}}
    return {"order_id": order_id, "tool_calls": state.get("tool_calls", []) + [call]}

graph = StateGraph(AgentState)
graph.add_node("search_docs", search_docs_node)
graph.add_node("check_order", check_order_node)
graph.add_node("escalate", escalate_node)
graph.add_conditional_edges(START, route, {
    "search_docs": "search_docs", "check_order": "check_order", "escalate": "escalate",
})
for node in ("search_docs", "check_order", "escalate"):
    graph.add_edge(node, END)
agent = graph.compile()

তিনটা collection মিশিয়ে Multi-source retrieval Source 4সোর্স 4:

def search_docs_node(state: dict) -> dict:
    hits = []
    for collection in (knowledge_base, product_docs, faq):
        hits += collection.query(query_texts=[state["question"]], n_results=3)["documents"][0]
    return {**state, "context": hits, "answer": generate(state["question"], hits)}

কোনো model call-এর আগে routing সিদ্ধান্তের একটা টেস্ট:

import pytest

ROUTING_CASES = [
    ("Where is order #4821?", "check_order"),
    ("What is your return policy?", "search_docs"),
    ("I want to speak to a manager, this is unacceptable.", "escalate"),
]

@pytest.mark.parametrize("question, expected_branch", ROUTING_CASES)
def test_the_agent_routes_to_the_correct_branch(question, expected_branch):
    assert route({"question": question}) == expected_branch

Tutorial advice

এই পরামর্শ টিউটোরিয়ালের নিজস্ব। এটি সোর্স থেকে আসেনি।

  • routing function সরাসরি টেস্ট করুন, পূর্ণ agent run থেকে আলাদা; এটা সস্তা আর এখানেই বেশিরভাগ সিদ্ধান্ত বাগ থাকে।
  • Mock order-status tool-কে deterministic রাখুন, একটা স্থির, documented order id আর state সেট সহ, যাতে একটা test failure কখনো "mock data বদলেছে" না হয়।
  • প্রতিটা real call-এ agent কোন শাখা নিয়েছে তা লগ করুন, টেস্টিং-এর প্রথম দিন থেকেই, একটা routing bug সন্দেহ হলে পরে যোগ করা নয়।

Common mistakes

Mistake 1: testing only the end answer, never the routing decision. A correct answer reached through the wrong branch (an order lookup that accidentally went through document search) is still a bug.

Mistake 2: a non-deterministic mock tool. If the mock order-status tool returns random data, a test failure cannot be told apart from mock noise.

Mistake 3: no test for source conflict in multi-source retrieval. Three collections that have never been tested together for a contradicting answer will eventually produce one.

Mistake 4: treating escalation as a dead end with no test. The handoff needs to carry the full conversation; a test should confirm the receiving human actually gets that context, not just that the chat ended.

Mistake 5: building the agent and the test suite in sequence instead of together. Writing the routing test cases alongside the routing function catches an ambiguous rule before it ships, not after.

সহজ English

Mistake 1: checking only the final answer, never the routing choice. An answer can be right but reached by the wrong branch. For example, an order lookup may have gone through document search. That is still a bug.

Mistake 2: a mock tool that is not deterministic. If the mock order-status tool returns random data, you cannot tell a real failure from mock noise.

Mistake 3: no test for sources that disagree. If you never test three collections together for a contradicting answer, one will eventually appear.

Mistake 4: treating escalation as a dead end with no test. The handoff must carry the whole conversation. Your test should confirm the human really receives that context. Checking that the chat ended is not enough.

Mistake 5: building the agent first and the tests later. Write the routing test cases while you write the routing function. This catches an unclear rule before it ships, not after.

বাংলা ব্যাখ্যা

ভুল ১: শুধু চূড়ান্ত উত্তর টেস্ট করা, কখনো routing সিদ্ধান্ত নয়। ভুল শাখার মধ্য দিয়ে পৌঁছানো একটা সঠিক উত্তর (একটা order lookup যা দুর্ঘটনাক্রমে document search দিয়ে গেছে) তখনও একটা বাগ।

ভুল ২: একটা non-deterministic mock tool। যদি mock order-status tool এলোমেলো data ফেরত দেয়, একটা test failure mock noise থেকে আলাদা করা যায় না।

ভুল ৩: multi-source retrieval-এ source conflict-এর জন্য কোনো টেস্ট নেই। তিনটা collection যেগুলো একসাথে বিরোধী উত্তরের জন্য কখনো টেস্ট করা হয়নি শেষ পর্যন্ত একটা তৈরি করবে।

ভুল ৪: escalation-কে টেস্ট ছাড়া একটা dead end ভাবা। Handoff-এর পুরো কথোপকথন বহন করা দরকার; একটা টেস্ট নিশ্চিত করা উচিত যে গ্রহণকারী মানুষ আসলেই সেই context পায়, শুধু chat শেষ হয়েছে তা নয়।

ভুল ৫: agent আর test suite ক্রমানুসারে বানানো, একসাথে নয়। routing function-এর পাশাপাশি routing test case লেখা ship হওয়ার আগে একটা অস্পষ্ট নিয়ম ধরে, পরে নয়।

What a tester can check

Tutorial advice

This advice is the tutorial's own. It does not come from the sources.

  • Write the routing test cases before or alongside the routing function, not after the agent is otherwise complete.
  • Confirm the mock order-status tool is fully deterministic before using it in any test.
  • Build at least one deliberate source-conflict case for the multi-source retriever and confirm the agent handles it sanely.
  • Confirm the escalation branch actually carries the conversation history to the handoff, not just a flag.

সহজ English

Tutorial advice

This advice is the tutorial's own. It does not come from the sources.

  • Write the routing test cases before or alongside the routing function, not after the agent is otherwise complete.
  • Confirm the mock order-status tool is fully deterministic before using it in any test.
  • Build at least one deliberate source-conflict case for the multi-source retriever and confirm the agent handles it sanely.
  • Confirm the escalation branch actually carries the conversation history to the handoff, not just a flag.

বাংলা ব্যাখ্যা

Tutorial advice

এই পরামর্শ টিউটোরিয়ালের নিজস্ব। এটি সোর্স থেকে আসেনি।

  • agent অন্যথায় সম্পূর্ণ হওয়ার পরে নয়, routing function-এর আগে বা পাশাপাশি routing test case লিখুন।
  • যেকোনো টেস্টে ব্যবহারের আগে mock order-status tool সম্পূর্ণ deterministic তা নিশ্চিত করুন।
  • multi-source retriever-এর জন্য অন্তত একটা ইচ্ছাকৃত source-conflict কেস বানান আর agent সেটা যুক্তিসঙ্গতভাবে সামলায় তা নিশ্চিত করুন।
  • escalation শাখা আসলেই কথোপকথনের ইতিহাস handoff-এ বহন করে, শুধু একটা flag নয়, তা নিশ্চিত করুন।

Key words

WordWhat it means
Agent layerThe decision-making component on top of a RAG chain that chooses an action
Multi-source retrievalQuerying more than one collection and merging the results
Mock toolA deterministic stand-in for a real backend, used to test agent tool-use safely
Routing decisionWhich branch (search, tool call, escalation) the agent chooses for a question
EscalationHanding a conversation off to a human, with its context, instead of answering

Reels on this topicএই টপিকের রিলস

Short videos from other creators, picked for this topic. They are not part of this page's fact-checked text. Nothing loads from YouTube until you press Play.অন্য ক্রিয়েটরদের বানানো ছোট ভিডিও, এই টপিকের জন্য বাছাই করা। এগুলো এই পেজের ফ্যাক্ট-চেক করা লেখার অংশ নয়। চালান বাটন চাপার আগে YouTube থেকে কিছুই লোড হয় না।

  1. [1]
    LangGraph overview

    LangChain (LangGraph docs) · accessed 2026-11-01দেখা হয়েছে: 2026-11-01

  2. [2]
    Graph API overview

    LangChain (docs) · accessed 2026-11-01দেখা হয়েছে: 2026-11-01

  3. [3]
    Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks

    arXiv · accessed 2026-11-01দেখা হয়েছে: 2026-11-01

  4. [4]
    Introduction

    Chroma (docs) · accessed 2026-11-01দেখা হয়েছে: 2026-11-01

  5. [5]
    AI & ML Testing Professional Course (Phase 1 and Phase 2)

    QodeBench, Journey to Automation · accessed 2026-11-27দেখা হয়েছে: 2026-11-27