Practised 0 / 16Next →
14 / 16 · MODULE 04 · RAG, FUNCTION CALLING & MCP

External knowledge & action protocols: RAG, Function Calling, and MCP

How can a model that only emits text search private documents (RAG) and execute external tools (Function Calling & MCP)?

TAKE AWAYToggle RAG evidence passages above and inspect Function Calling JSON interception and MCP discovery below

A bare LLM has two inherent limits: 1) frozen training cutoff with no access to your private files; 2) it can only emit text and cannot execute code or network calls itself. An Agent is simply the wrapper program that fetches data or runs tools on the model’s behalf.

Searching local chunks by vector similarity and injecting them into context is RAG. To let the wrapper program reliably trigger external tools, engineers constrained the model to emit strict JSON—called Function Calling. And to decouple tool servers from the host Agent app, the industry standardized the discovery/call wire format as MCP (Model Context Protocol).

DIAGRAM · RETRIEVAL-AUGMENTED GENERATION PIPELINE

Retrieve matching passages first, answer only from evidence, and abstain when evidence is missing

Retrieval supplies reference passages; when evidence is absent, the system should report no basis.

01 KEYWORD RETRIEVALMatch Query Against Source PassagesFetch only passages matching the query terms.→02 GROUNDED EVIDENCEDisplay Retrieved Source Passages for VerificationAnswers must trace directly to the retrieved passage.→03 NO EVIDENCE → NO FABRICATIONWhen Evidence Is Removed or Absent → State UnknownReturn “not mentioned in supplied sources” rather than guessing.
01 KEYWORD RETRIEVAL

Match Query Against Source Passages

Fetch only passages matching the query terms.

02 GROUNDED EVIDENCE

Display Retrieved Source Passages for Verification

Answers must trace directly to the retrieved passage.

03 NO EVIDENCE → NO FABRICATION

When Evidence Is Removed or Absent → State Unknown

Return “not mentioned in supplied sources” rather than guessing.

First-principles breakdown: three steps
  1. RAG: Retrieve Evidence First, Then Inject into Context

    Match relevant passages via lexical or vector search and inject them into the prompt with strict grounding rules.

  2. Function Calling: Strict JSON Interface Agreement

    Require the model to emit structured JSON tool calls so the host program can parse and execute them deterministically.

  3. MCP: Standardize & Decouple Tool Servers

    Standardize tools/list and tools/call endpoints so any Agent host can plug into external tool servers without custom glue code.

Toggle source passages in the top RAG panel to test grounded answers vs. abstention; then switch protocol modes below to inspect the two-trip tool execution loop.

TRY IT YOURSELF · LIVE CODE SANDBOXLIVE CALCULATION
Available sources · fictional course
PART 2 · FUNCTION CALLING & MCP PROTOCOL INSPECTOR
[MCP tools/list] -> 发现外部服务 weather-server
[MCP tools/call] -> {"name": "get_weather", "arguments": {"city": "Beijing"}}
✓ 工具实现与 Agent 主程序彻底解耦:通过标准 MCP 协议动态发现工具列表(tools/list)并跨进程调用(tools/call)。

Local retrieval + Tool protocol inspector: the model only emits structured JSON; the host runtime executes the tool and appends the result.

JARGON BUSTER · STRIP AWAY THE HYPE

Retrieval-Augmented Generation (RAG)

Search documents first, paste matching excerpts into the prompt, and have the model answer from those excerpts.

Retrieval alone isn’t enough; pair it with source citations and explicit abstention when evidence is missing.

Function Calling / Tool Use

A handshake protocol: the model outputs a JSON request, the host app runs the function, and feeds the result back.

Identical in spirit to a frontend-backend JSON API contract—zero magic involved.

Model Context Protocol (MCP)

A universal “USB plug standard” for AI tools: implement an MCP server once, and any MCP-compatible Agent can call it.

Eliminates rewriting custom tool integrations for every different Agent application.
ONE IDEA TO KEEP

An LLM never “executes a tool” itself—it only emits a formatted JSON string, and the external host program runs the actual code.

CHECK YOUR UNDERSTANDING

When an Agent has a weather tool enabled and you ask “Will it rain in Shenzhen tomorrow?”, what actually happens under the hood?

When an Agent has a weather tool enabled and you ask “Will it rain in Shenzhen tomorrow?”, what actually happens under the hood?
REFERENCES & FURTHER LEARNING

Explanations, cases, and exercises are authored by Reallier. Links provide further learning. The workplace activity and people are fictional.