Agent 和 tool calling 怎么工作?
MCP 标准化了什么?

英文问法How does tool calling work? · Explain the ReAct loop. · What is MCP and why does it matter? · Why not just put the tool outputs in the prompt? · What are common failure modes of agents?

考过面经:微软 Teams AS IC2("RAGs, GenAI, A/B testing, and MCP")· 微软中国 deep research 组实习("为什么不直接把tool调用的工具输出后放到prompt里给到LLM?")

先弄清楚:每个概念是什么

Agent
LLM 在循环里自己做决定:看现状 → 选动作 → 看结果,直到任务完成。
Tool calling(function calling)
给模型一份工具说明书。模型不执行,只输出一个结构化调用,由 runtime 执行后把结果放回 context。例:模型输出 get_weather({"location": "New York"}),runtime 返回 "72°F, partly cloudy",模型据此回答。
ReAct
Thought → Action → Observation 交替。Thought 是写给自己的推理,不影响环境。Action 调工具。Observation 是工具返回。
MCP(Model Context Protocol)
LLM 应用连接外部 tool 和数据的开放协议,消息用 JSON-RPC 2.0,思路来自 Language Server Protocol。host 是 LLM 应用,里面每个 client 只连一个 server,server 暴露 tools、resources、prompts。例:5 个应用 × 20 个工具,各自对接要写 100 个集成;都讲 MCP 时只要 5 个 client 实现 + 20 个 server。

30 秒回答

We give the model a list of tools, each with a name, a description and a JSON Schema for its arguments. The model doesn't execute anything: it emits a structured call, a function name plus JSON arguments. The runtime validates and executes it, appends the result to the context and calls the model again, until the model answers. ReAct is this loop with explicit reasoning: thought, action, observation. MCP is an open protocol on JSON-RPC that standardizes how applications connect to tools and data: a host runs one client per server, and servers expose tools, resources and prompts, so a tool is implemented once and reused by every app.

一轮 tool call 怎么走

  1. 把 tools 的 name、description、JSON Schema 放进请求(MCP 里由 client 调 tools/list 拿到)。
  2. 模型输出 {name, arguments} 并停止生成。
  3. runtime 校验参数、检查权限(敏感操作先问用户),再执行(MCP 里是 tools/call)。
  4. 结果或错误信息追加进 context,再调模型;直到模型直接回答或到 max steps。

MCP 的三种 server 原语

原语谁决定用例子方法
Toolsmodel-controlled:模型决定调查天气、跑 SQLtools/list、tools/call
Resourcesapplication-driven:应用决定放进 context文件、DB schema,用 URI 标识resources/list、resources/read
Promptsuser-controlled:用户从菜单选slash command 模板prompts/list、prompts/get

传输层:本地用 stdio(client 启动 server 子进程),远程用 Streamable HTTP。

为什么不预先把 tool output 塞进 prompt(deep research 组原题)

常见失败和对策

必答点

追问

MCP 和 function calling 是什么关系?

function calling 是模型这一层的能力,读 schema、输出调用。MCP 是应用和 tool 提供方之间的协议。host 把 MCP server 的 tools 转成模型的 tool 定义。

tool 调用失败怎么处理?

MCP 分两种。protocol error(未知 tool、请求格式错)走 JSON-RPC error。tool execution error 放在结果里标 isError: true,回给模型自己改。

MCP 有哪些安全问题?

tool 等于任意代码执行,host 调用前要用户同意。不可信 server 的 tool 描述也不可信。server 看不到整段对话和别的 server。权限分级见 agent 的权限。

ReAct 和 CoT 比怎样?

HotpotQA 上 CoT 的失败 56% 是 hallucination,ReAct 是 0%,因为事实来自检索。但 ReAct 的 reasoning error 更多(47% vs 16%)。论文里效果最好的是 ReAct 和 CoT-SC 互相 fallback。

来源Yao et al. 2023, ReAct §2(p.3)、§3.1–3.2(pp.4–5)、§3.3 Table 2(p.6)· Schick et al. 2023, Toolformer §2(pp.2–4)· MCP specification 2026-07-28:Overview、Architecture、Server Features(Tools、Resources、Prompts)、Transports