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)?
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).
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.
Match Query Against Source Passages
Fetch only passages matching the query terms.
Display Retrieved Source Passages for Verification
Answers must trace directly to the retrieved passage.
When Evidence Is Removed or Absent → State Unknown
Return “not mentioned in supplied sources” rather than guessing.
First-principles breakdown: three steps
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.
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.
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.
[MCP tools/list] -> 发现外部服务 weather-server
[MCP tools/call] -> {"name": "get_weather", "arguments": {"city": "Beijing"}}Local retrieval + Tool protocol inspector: the model only emits structured JSON; the host runtime executes the tool and appends the result.
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.An LLM never “executes a tool” itself—it only emits a formatted JSON string, and the external host program runs the actual code.
When an Agent has a weather tool enabled and you ask “Will it rain in Shenzhen tomorrow?”, what actually happens under the hood?
Explanations, cases, and exercises are authored by Reallier. Links provide further learning. The workplace activity and people are fictional.