← Back to LLMs Mind Map
⚡ LLMsID: agent-tool-calling

Agent & Tool Calling

Agent 与工具调用
🎯Core Definition
agents give LLMs external capabilities through tool calling, built on three mechanisms: (1) Function-calling schema — declaring each API as name + description + parameters (JSON Schema); the model emits a structured tool_call (name + JSON args), and a tool registry with parameter validation (required fields, enums, types) keeps calls legal; (2) grammar-constrained decoding — JSON mode / Outlines / guidance restrict sampling to tokens consistent with the schema, guaranteeing parseable output by only allowing candidates that satisfy schema(prefix)\text{schema}(\text{prefix}); (3) ReAct loop — Thought → Action → Observation iteration: st→LLM(Thoughtt,Actiont)→execot→st+1s_t \xrightarrow{\text{LLM}} (\text{Thought}_t, \text{Action}_t) \xrightarrow{\text{exec}} o_t \to s_{t+1}, feeding each observation back into the context, plus self-correction (reflecting on failures, retrying with other tools or parameters).
💡Use Cases
multi-tool orchestration (search, calculator, database, code execution); multi-step tasks (booking, data-analysis pipelines); defending against tool-argument hallucination (injecting JSON Schema + examples into the prompt); a favorite interview question — how to guarantee legal, retryable tool calls.
⚡Key Problems Solved
a bare LLM can't reach real-time data or execute computations, and free-form text can't reliably wire into APIs. Schema plus constrained decoding turns "possibly malformed strings" into "guaranteed-parseable structures", and the ReAct loop turns single-shot generation into a closed reason-act loop where errors are observable and correctable.
🎯Core Interview Exam Points
Fundamentals · Production Scenarios · Deep Dive
Core Def
Explain the core definition, underlying mechanism/math, and key principles of Agent & Tool Calling.
Use Cases
In production engineering, what are the primary use cases for Agent & Tool Calling and what core pain points does it solve?
🔥 High-Frequency Deep-Dive Questions
1
Walk the function-calling pipeline (schema → output → validation → execution → feedback) and the failure handling at each step.
2
How does grammar-constrained decoding work, and how does JSON mode differ from normal decoding in guaranteeing parseability?
3
How does the ReAct loop terminate — max steps and loop detection?
4
How do agents self-correct — retry vs switch tools on timeout, bad args, or empty results?
5
With many tools, how do you prevent tool-selection hallucination — tool descriptions, routing, and result verification?
Updated 2026-08-12
🎯
Verify Mastery: Practice Exam Questions for "Agent & Tool Calling"
Take pitfall multiple-choice questions with derivation options; mistakes are automatically logged.
🚀 Start Card Practice ➔
← Previous CardLong-Context Eval Needle/Lost-in-MiddleNext Card →Benchmarks MMLU/GSM8K

🔗 More LLMs Knowledge Cards

引用出处: TalentMe 450+ 工业级 AI 架构考点知识库 (Tech Vault) · 遵循 CC-BY-4.0 知识共享协议
URL: https://talentme.airsota.com/resources/tech/roadmap/mindmap/LLM/card/agent-tool-calling
中文速览与面试要点

Agent 与工具调用 (Agent & Tool Calling)

定义: Agent 让 LLM 通过工具调用获取外部能力,三大机制:(1) Function Calling Schema——把 API 声明为 name + description + parameters(JSON Schema),模型输出结构化的 tool_call(name + JSON 参数),工具注册表与参数校验(必填字段、枚举、类型)保证调用合法;(2) 语法约束解码——用约束解码(JSON mode / Outlines / guidance)在采样时只允许符合 Schema 的下一个 token,从概率上保证输出可解析:解码只遍历满足 schema( prefix) 的合法候选;(3) ReAct 循环——Thought → Action → Observation 交替迭代:s_t LLM ( Thought_t, Action_t) exec o_t s_t+1,观察结果回填上下文进入下一轮,配合自我纠错(反思失败、重试不同工具或参数)。 使用场景: 多工具编排(搜索、计算器、数据库、代码执行);多步任务(订票、数据分析流水线);工具参数幻觉的防御(把 JSON Schema 与示例注入提示);面试高频"如何保证 Agent 调用的参数合法且可重试"。 解决的问题: 裸 LLM 无法访问实时数据或执行计算,且自由文本输出无法稳定接入 API;Schema + 语法约束解码把"可能格式错误的字符串"变成"必然可解析的结构",ReAct 把单次生成扩展为闭环推理-行动循环,让错误可观察、可纠正。

核心要点

  • Function Calling 的完整链路:Schema 声明 → 模型输出 → 参数校验 → 执行 → 回填,每一步的失败处理怎么做?
  • 语法约束解码的原理是什么?JSON mode 与普通解码在保证可解析性上的区别?
  • ReAct 的 Thought-Action-Observation 循环如何实现终止?最大步数与循环检测怎么设?
  • Agent 如何自我纠错?工具调用失败(超时、参数错、结果空)时应该重试还是换工具?
  • 多工具场景如何防止工具选择幻觉:工具描述怎么写、如何做工具路由与结果验证?