Run an OpenAI Function Calling Order Query
This hands-on tutorial builds a Python order-status assistant around Function Calling, covering tool schemas, parameter validation, backend execution, authorization, and result handling. It provides a local Mock mode and an OpenAI Responses API live mode, while emphasizing that the model proposes calls but the backend retains execution control.
The runnable example demonstrates how developers can connect LLM tool requests to business systems while enforcing validation, permissions, failure handling, and prompt-injection defenses outside the model.
Agent开发 01|Function Calling:AI 如何调用工具?
《Agent开发》系列 · 第 01 篇
我们已经习惯向 AI 助手提问。例如,“什么是 Google Play Billing”,大模型可以根据已有知识解释概念。但如果问题变成“帮我查询订单 1001 的支付状态”,回答就需要来自当前业务系统的数据。
模型怎样知道有哪些接口可以用?它怎样表达调用请求?后端又怎样检查、执行,并把结果交回来?
这篇文章沿着一次订单查询,从基本原理走到可运行的 Python 示例。读者了解基本的函数、JSON 和 API 调用即可开始,不需要提前学习 Agent 框架。
一、为什么需要 Function Calling?
普通订单页面上的查询按钮,对应着明确的代码调用: