S7-06 · 基础S7-06 · Foundation

函数调用 · 请求有结构,执行才有边界Function Calling · Structure the Request Before Anything Runs

function name + typed arguments → validation gate → application runtime → tool result → loop

函数调用(Function Calling)让模型按预定义名称和参数结构请求应用执行某个函数。结构化请求仍需参数校验、权限检查和结果确认。Function calling lets a model request application execution through a predefined function name and typed arguments. A structured request still requires validation, permission checks, and result confirmation.

01 · 填好表单不等于已经发货01 · A completed form is not a shipped order

模型写出 calculate_shipping({ units: 3 }),应用该立刻执行,还是先确认参数类型真的符合约定?A model writes calculate_shipping({ units: 3 }). Should the application execute immediately, or first verify that every argument matches the contract?

02修改参数 Schema:非法类型锁门,合法调用执行真实本地函数Edit the Parameter Schema: Block Invalid Types, Execute a Valid Local Function

Schema → 应用运行时 → 循环Schema → app runtime → loop
状态 AMetric A
—
—
状态 BMetric B
—
—
状态 CMetric C
—
—

所有概率、得分与输出均为固定种子的教学模拟,不代表真实模型。拖回主变量即可复核结论。All probabilities, scores, and outputs are fixed-seed teaching simulations, not real model output. Move the main variable back to verify the conclusion.

03把刚才的变化拆成 4 个零件Break the Change into Four Parts

Function Calling
NAME

函数名称Function name

应用只暴露预定义的 calculate_shipping。The application exposes only the predefined calculate_shipping function.

SCHEMA

参数 SchemaArgument Schema

字段名称、类型和必填关系先机械校验。Field names, types, and required status are validated mechanically.

RUNTIME

应用执行Application runtime

通过校验后,由本地 JavaScript 函数真正计算返回值。After validation, a local JavaScript function computes the actual return value.

RESULT

结果回环Result loop

返回对象以 tool result 身份送回 Agent 下一轮。The returned object goes back to the agent as a tool result.

04最小机制:主交互能逐项验证Minimal Mechanism: Verify Each Link in the Interaction

MECHANISM
call_allowed = name_known ∧ args_match_schema ∧ permission_ok
本页直接验证第一道门:非法 units.type 让提交按钮 disabled;合法参数才进入应用运行时。This lesson verifies the first gate directly: an invalid units.type disables submission; valid arguments can reach the application runtime.
生成请求Propose call名称 + 参数对象name + argument object
机械校验ValidateSchema / 权限Schema / permission
执行并回传Run and return真实函数结果进循环actual function result enters loop

05把 units.type 改成不存在的 number-ishChange units.type to the Nonexistent number-ish Type

主动制造失败Create a failure

边界实验Boundary experiment

结构长得像 JSON 并不够。失败按钮写入非法 Schema 类型;提交必须被禁用,函数调用次数保持为 0。JSON-shaped text is not enough. The failure button inserts an invalid Schema type; submission must stay disabled and the function call count remain zero.

尚未执行。先在主交互中观察正常机制。Not run yet. Observe the normal mechanism in the main interaction first.
✗ 模型输出了函数名,函数就已经执行。A function name in model output means the function ran.→ ✓ 模型只提出结构化请求,应用负责校验与执行。The model proposes a structured request; the application validates and executes it.
✗ 参数能解析成 JSON 就一定合法。Parseable JSON guarantees valid arguments.→ ✓ 字段类型、必填项与业务范围仍要逐项校验。Types, required fields, and business ranges still need validation.
✗ 返回一段文字就算调用成功。A text response proves the call succeeded.→ ✓ 应用运行时的真实返回对象必须送回循环并确认。The actual application-runtime return object must enter the loop and be confirmed.
06 · 一句话带走06 · One line to keep

函数调用是“模型提出结构化请求—应用校验并执行—真实返回值送回循环”;任何非法参数都应在执行前停住。Function calling is a loop: the model proposes a structured request, the application validates and executes it, and the actual return value comes back. Invalid arguments must stop before execution.