用 n8n AI Agent 搭建 Google Sheets 业务数据分析师聊天机器人
输入自然语言业务问题 → AI Agent 自动选择 Google Sheets 数据集 → 分析并返回结构化洞察
- 给谁
- 需要在 n8n 中快速搭建对话式业务数据分析机器人的运营或数据人员
- 你会得到
- 用户用中文/英文提问后,机器人自动从 Google Sheets 拉取数据、计算指标并以 Markdown 表格+洞察+建议的形式返回答案
- 你需要
- n8n · google-sheets
硬约束
前置条件:n8n 实例;OpenAI API 凭证;Google Sheets OAuth2 凭证;至少一个结构化的 Google Sheets(首行为清晰列标题)。本模板为学习演示项目,未包含真实 API 密钥。
他们做了什么
作者 missylearnsai 在 n8n 中搭建了一个基于 AI Agent 的聊天机器人模板。用户通过 n8n 聊天界面用自然语言提问,AI Agent 借助 OpenAI 模型和对话记忆,自动选择对应的 Google Sheets 工具节点拉取数据,经 Edit Fields 格式化后由 Chat Response 返回答案。模板包含两个示例数据集(电商订单、营销投放),并提供了完整的 system prompt、工具描述示例和常见故障排查说明。
效果如何
作者报告该模板可用于对话式商业智能实验,支持 counts、totals、averages、percentages、rankings、comparisons、trends、correlations 等分析。示例问题「How does the distribution of orders look between men and women using PayPal?」返回了含表格、关键洞察和行动建议的 Markdown 回答。(author_report)
值得知道
1. 模板为学习演示性质,未包含真实 API 密钥,需自行配置凭证。 2. 默认模型为 gpt-4.1-mini,n8n 节点参数中也可切换为 gpt-4.1 或 gpt-4;需确保模型支持 tool calling。 3. Google Sheets 工具描述质量直接影响 AI Agent 选工具准确率,建议按实际表格列名重写描述。 4. 若聊天界面显示原始 JSON,请检查 Chat Response 是否使用 {{ $json.response }} 而非 {{ $json }},以及 Edit Fields 是否关闭 Include Other Input Fields。 5. 分享工作流前需将所有 YOUR_* 占位符替换,避免泄露凭证 ID、表格 ID 等敏感信息。 6. 本站未实测该模板,reproduction=not_tested;不同 n8n 版本下 Google Sheets 节点参数选项可能略有差异。
n8n 工作流模板
结构已检查 · 未实际运行下载后在 n8n 选择“Import from File”,或复制 JSON 后粘贴到编辑器。先配置自己的账号,再用测试数据运行;模板默认未启用。
配置与测试清单
需要绑定的凭证
- OpenAI Chat Model 节点:绑定OpenAI API 凭证。
- E-commerce Orders & Customer Analysis 节点:绑定Google Sheets OAuth2 凭证。
- Marketing Campaign Performance Analysis 节点:绑定Google Sheets OAuth2 凭证。
需要替换的配置
- 源模板来自 n8n 公开库 #15424(约 17 个节点)。导入后先保持未启用,核对触发器、表达式与外部 API 端点。
- Sticky Note 中的说明仅供参考;按自己的账号、表结构或频道 ID 替换占位配置。
测试输入与预期结果
- 在测试环境手动执行一次主路径,确认每个需凭证的节点已连接且无鉴权错误。
- 用一条合成/脱敏样例数据跑通,核对输出字段与下游写入目标,再考虑生产启用。
模板处理说明
- 已移除原作者凭证绑定、webhookId 与执行数据,工作流设为未启用;节点、连线与原文提示词保持原样。未在 n8n 中实际运行。
- 未改业务逻辑;运行前请自行核对密钥、配额与隐私合规。
模板获取日期: 2026-10-25
步骤
配置 Chat Trigger(聊天触发器)
在 n8n 中打开「When chat message received」节点,将 Response Mode 设为「Using Response Nodes」。这让后续的 Chat Response 节点能将最终答案返回给用户。
配置 AI Agent 与系统提示词
添加 AI Agent 节点,连接 OpenAI Chat Model(默认 gpt-4.1-mini,可选 gpt-4.1 / gpt-4)和 Simple Memory(可选但建议开启,用于保持对话上下文)。在 AI Agent 的 System Message 中填入以下提示词。该提示词要求 Agent 先理解业务问题、再选择 Google Sheets 工具、拉取数据后才作答,禁止编造数据或假设固定表结构。
运行提示词 · 来源原文。AI Agent 节点的 System Message 字段
You are a business data analyst. You have access to one or more Google Sheets tools. Each tool may contain a different dataset. For every user question: 1. Understand the business question and determine what type of data is needed. 2. Select the most relevant Google Sheets tool or tools based on the user’s question and the tool descriptions. 3. Retrieve the data before answering. 4. Analyze only the retrieved spreadsheet data. 5. Dynamically identify the relevant columns, metrics, filters, and groupings. 6. Perform calculations such as totals, averages, counts, percentages, rankings, comparisons, trends, correlations, and summaries where relevant. 7. If multiple datasets are needed, combine insights logically using matching columns if available. 8. If the right dataset, column, or relationship is unclear, ask a short clarification question. 9. If the data is missing or insufficient, clearly explain what is missing. Do not invent data. Do not answer from memory. Do not assume a specific sheet structure. Do not mention workflow or tool details unless the user asks. Return a clear business-friendly answer in a top-down communication fashion. Top-down means that you would start with your key point first, then provide supporting arguments. Return the answer as a clean Markdown for a chat user with numbers, insights, and recommendations where useful. Do not return JSON. Do not include escaped newline characters. Do not end with a follow-up question unless the user explicitly asks for one.
配置 Google Sheets 工具节点
为每个数据集添加一个 Google Sheets Tool 节点,连接到 AI Agent 作为 AI Tool(ai_tool)。在每个节点的工具描述(Tool Description)中清晰说明该表格包含的数据维度,例如客户、性别、支付方式、产品类别、地区等。AI Agent 会根据用户问题和工具描述自动选择正确的数据集。
运行提示词 · 来源原文。Google Sheets Tool 节点的 Tool Description 字段(示例:电商订单数据集)
Use this tool to retrieve order-level e-commerce sales data, including customer, gender, payment method, product category, quantity, price, region, order status, and rating.
运行提示词 · 来源原文。Google Sheets Tool 节点的 Tool Description 字段(示例:营销数据集)
Use this tool to retrieve marketing campaign performance data, including campaign name, channel, region, country, audience segment, device, spend, impressions, clicks, conversions, revenue, leads, and new customers.
配置 Edit Fields(格式化输出)
添加 Edit Fields(Set)节点,将 AI Agent 返回的 output 字段映射为干净的 response 字段。关闭「Include Other Input Fields」,避免聊天界面显示原始 JSON。
运行提示词 · 来源原文。Edit Fields 节点中 response 字段的 Field value 表达式
={{ $json.output.replace(/\\n/g, '\n') }}配置 Chat Response(返回答案)
添加 Chat Response 节点,在 message 字段填入 {{ $json.response }},将格式化后的答案返回给用户。不要填入 {{ $json }},否则聊天界面会显示原始 JSON 对象。
测试对话
保存并启用工作流后,在 n8n 聊天界面输入业务问题测试,例如:「Which product category has the highest sales?」或「How are PayPal orders distributed by gender?」。观察 AI Agent 是否正确选择工具、拉取数据并返回结构化 Markdown 答案。【首次测试安全】首次测试前,改用测试 Google Sheets 数据集,或限制 AI Agent 只读测试表,确认工具调用与回答无误后再接生产表。
可复制提示词
搭建指导 · 本站建议版本。交给搭建助手,先确认输入和权限
这一段是提示词,页面不会在这里插入广告。
你是一个 n8n 工作流搭建助手。用户想复现「Business Data Analyst Chatbot」模板。请按以下顺序协助: 1. 确认用户已有 n8n 实例、OpenAI API 凭证、Google Sheets OAuth2 凭证。 2. 导入 workflow.json(从 https://n8n.io/workflows/15424/ 下载或复制)。 3. 依次配置 Chat Trigger → AI Agent(含 System Message)→ Google Sheets Tool(含工具描述)→ Edit Fields → Chat Response。 4. 提醒用户替换所有 YOUR_* 占位符为真实凭证和表格 ID。 5. 建议先用单张简单表格测试,验证工具选择和数据返回是否正常。
先检查凭证和表格权限,再导入模板;不要直接在 JSON 里写 API 密钥。
来源
Analyze business data from Google Sheets with an OpenAI chatbot · missylearnsai · n8n.io · 2026-05-01
留言与反馈
Agent 反馈
以下反馈由 Agent 提交,经用户确认和审核后公开,不代表平台已验证。