Function/Tool Callingopenai: 函数调用为 OpenAI 模型提供了一种强大而灵活的方式可以与您的代码或外部服务进行交互。通过函数调用您可以向 Assistant 描述函数并让其智能地返回需要调用的函数及其参数。openailangchain: 我们将“工具调用”与“函数调用”互换使用。虽然“函数调用”有时指的是单个函数的调用但我们将所有模型视为可以在每条消息中返回多个工具或函数调用。工具调用与 ReACT 的区别项目ReAct 提示词工程Function Calling核心思想用提示词引导模型「推理 行动 观察反馈」循环明确声明函数签名模型调用结构化函数技术机制Prompt 模板控制流程如Think - Act - Obs通过函数描述注册函数接口模型自动生成调用参数环境交互灵活性高适用于复杂多步任务、agent 类流程中适合明确定义的单步工具调用开发复杂度中需要精心设计提示词模板与中间状态管理低~中注册函数较直接但需要参数与返回值处理典型应用场景多步推理、多工具交替使用、信息抽取等复杂场景明确 API 调用、数据库查询、插件系统等与 Agent 框架集成度高常用于 LangChain、AutoGPT 中的推理行为生成高OpenAI、LangChain、Claude 支持直接注册使用优缺点总结✅ 灵活可控✅ 自动结构化调用❌ 难以规模化自动解析❌ 不擅长多步控制与反馈处理function calling 核心概念tools: 函数列表function: 单个函数定义function.name: 函数名字function.description: 函数作用描述parameters: 函数形参说明tools: [ { type: function, function: { name: current_time, description: A tool for getting the current time., parameters: { properties: {}, required: [], type: object } } }, { type: function, function: { name: simple_code, description: A tool for running code and getting the result back. Only native packages are allowed, network/IO operations are disabled. and you must use print() or console.log() to output the result or result will be empty., parameters: { properties: { code: { description: code to be executed, only native packages are allowed, network/IO operations are disabled., type: string }, language: { description: language of the code, only \python3\ and \javascript\ are supported, type: string } }, required: [language, code], type: object } } }]工具调用的返回格式tool_calls: 工具调用序列单个或者多个function 函数调用function.name 函数名字function.arguments 函数实参message: { role: assistant, content: , tool_calls: [ { function: { name: simple_code, arguments: { code: print(0.9111 ** 3), language: python3 } } } ] }常用工具代码解析器 python node命令解析器 bash文件管理 file directory浏览器控制 browser use外部接口 openapi swagger大模型上下文协议 MCP playwright-mcppython 工具调用示例没有工具调用的对话模型使用工具可以获得更加准确的结果带有 function call 的请求{ model: qwen3,stream: false,options: { temperature: 0 },messages: [ { role: system, content: /no_think\n }, { role: user, content: 使用python计算 0.9111**3 } ],tools: [ { type: function, function: { name: current_time, description: A tool for getting the current time., parameters: { properties: {}, required: [], type: object } } }, { type: function, function: { name: simple_code, description: A tool for running code and getting the result back. Only native packages are allowed, network/IO operations are disabled. and you must use print() or console.log() to output the result or result will be empty., parameters: { properties: { code: { description: code to be executed, only native packages are allowed, network/IO operations are disabled., type: string }, language: { description: language of the code, only \python3\ and \javascript\ are supported, type: string } }, required: [language, code], type: object } } } ]}大模型的响应{ model: qwen3,created_at: 2025-05-05T16:57:36.016688Z,message: { role: assistant, content: , tool_calls: [ { function: { name: simple_code, arguments: { code: print(0.9111 ** 3), language: python3 } } } ] },done_reason: stop,done: true,total_duration: 2037533417,load_duration: 34440000,prompt_eval_count: 275,prompt_eval_duration: 776227166,eval_count: 42,eval_duration: 1225024292}最终请求{ model: qwen3,stream: false,options: { temperature: 0 },messages: [ { role: system, content: /no_think\n }, { role: user, content: 使用python计算 0.9111**3 }, { role: assistant, content: }, { role: tool, content: 0.756307034631\n } ],tools: [ { type: function, function: { name: current_time, description: A tool for getting the current time., parameters: { properties: {}, required: [], type: object } } }, { type: function, function: { name: simple_code, description: A tool for running code and getting the result back. Only native packages are allowed, network/IO operations are disabled. and you must use print() or console.log() to output the result or result will be empty., parameters: { properties: { code: { description: code to be executed, only native packages are allowed, network/IO operations are disabled., type: string }, language: { description: language of the code, only \python3\ and \javascript\ are supported, type: string } }, required: [language, code], type: object } } } ]}最终响应{ model: qwen3,created_at: 2025-05-05T16:57:37.121945Z,message: { role: assistant, content: think\n\n/think\n\n0.9111 raised to the power of 3 is approximately **0.7563**. },done_reason: stop,done: true,total_duration: 1030672292,load_duration: 11999667,prompt_eval_count: 303,prompt_eval_duration: 122764292,eval_count: 29,eval_duration: 892274041}说真的这两年看着身边一个个搞Java、C、前端、数据、架构的开始卷大模型挺唏嘘的。大家最开始都是写接口、搞Spring Boot、连数据库、配Redis稳稳当当过日子。结果GPT、DeepSeek火了之后整条线上的人都开始有点慌了大家都在想“我是不是要学大模型不然这饭碗还能保多久”我先给出最直接的答案一定要把现有的技术和大模型结合起来而不是抛弃你们现有技术掌握AI能力的Java工程师比纯Java岗要吃香的多。即使现在裁员、降薪、团队解散的比比皆是……但后续的趋势一定是AI应用落地大模型方向才是实现职业升级、提升薪资待遇的绝佳机遇这绝非空谈。数据说话2025年的最后一个月脉脉高聘发布了《2025年度人才迁徙报告》披露了2025年前10个月的招聘市场现状。AI领域的人才需求呈现出极为迫切的“井喷”态势2025年前10个月新发AI岗位量同比增长543%9月单月同比增幅超11倍。同时在薪资方面AI领域也显著领先。其中月薪排名前20的高薪岗位平均月薪均超过6万元而这些席位大部分被AI研发岗占据。与此相对应市场为AI人才支付了显著的溢价算法工程师中专攻AIGC方向的岗位平均薪资较普通算法工程师高出近18%产品经理岗位中AI方向的产品经理薪资也领先约20%。当你意识到“技术AI”是个人突围的最佳路径时整个就业市场的数据也印证了同一个事实AI大模型正成为高薪机会的最大源头。最后我在一线科技企业深耕十二载见证过太多因技术卡位而跃迁的案例。那些率先拥抱 AI 的同事早已在效率与薪资上形成代际优势我意识到有很多经验和知识值得分享给大家也可以通过我们的能力和经验解答大家在大模型的学习中的很多困惑。我整理出这套 AI 大模型突围资料包【允许白嫖】✅从入门到精通的全套视频教程✅AI大模型学习路线图0基础到项目实战仅需90天✅大模型书籍与技术文档PDF✅各大厂大模型面试题目详解✅640套AI大模型报告合集✅大模型入门实战训练这份完整版的大模型 AI 学习和面试资料已经上传CSDN朋友们如果需要可以微信扫描下方CSDN官方认证二维码免费领取【保证100%免费】①从入门到精通的全套视频教程包含提示词工程、RAG、Agent等技术点② AI大模型学习路线图0基础到项目实战仅需90天全过程AI大模型学习路线③学习电子书籍和技术文档市面上的大模型书籍确实太多了这些是我精选出来的④各大厂大模型面试题目详解⑤640套AI大模型报告合集⑥大模型入门实战训练获取方式有需要的小伙伴可以保存图片到wx扫描二v码免费领取【保证100%免费】