Skip to content

SQL AI Agent 节点#

¥SQL AI Agent node

Feature removed

n8n 已于 2025 年 2 月移除此功能。

¥n8n removed this functionality in February 2025.

SQL Agent 使用 SQL 数据库作为数据源。它可以理解自然语言问题,将其转换为 SQL 查询,执行查询,并以用户友好的格式呈现结果。此代理对于构建数据库的自然语言接口非常有价值。

¥The SQL Agent uses a SQL database as a data source. It can understand natural language questions, convert them into SQL queries, execute the queries, and present the results in a user-friendly format. This agent is valuable for building natural language interfaces to databases.

有关 AI Agent 节点本身的更多信息,请参阅 AI 代理

¥Refer to AI Agent for more information on the AI Agent node itself.

节点参数#

¥Node parameters

使用以下参数配置 SQL Agent。

¥Configure the SQL Agent using the following parameters.

数据源#

¥Data Source

选择用作节点数据源的数据库。选项包括:

¥Choose the database to use as a data source for the node. Options include:

  • MySQL:选择此选项可使用 MySQL 数据库。

¥MySQL: Select this option to use a MySQL database.

  • 同时选择 MySQL 的凭据。

    ¥Also select the Credential for MySQL.

  • SQLite:选择此选项以使用 SQLite 数据库。

¥SQLite: Select this option to use a SQLite database.

  • 你必须在 Agent 之前添加一个 从磁盘读取/写入文件 节点才能读取你的 SQLite 文件。

    ¥You must add a Read/Write File From Disk node before the Agent to read your SQLite file.

  • 同时输入来自“从磁盘读取/写入文件”节点的 SQLite 文件的“输入二进制字段”名称。

    ¥Also enter the Input Binary Field name of your SQLite file coming from the Read/Write File From Disk node.

  • Postgres:选择此选项以使用 Postgres 数据库。

¥Postgres: Select this option to use a Postgres database.

  • 同时选择 Postgres 的凭据。

    ¥Also select the Credential for Postgres.

Postgres and MySQL Agents

如果你使用的是 PostgresMySQL,此代理不支持凭据隧道选项。

¥If you are using Postgres or MySQL, this agent doesn't support the credential tunnel options.

提示#

¥Prompt

Select how you want the node to construct the prompt (also known as the user's query or input from the chat).

Choose from:

  • Take from previous node automatically: If you select this option, the node expects an input from a previous node called chatInput.
  • Define below: If you select this option, provide either static text or an expression for dynamic content to serve as the prompt in the Prompt (User Message) field.

节点选项#

¥Node options

使用以下选项优化 SQL 代理节点的行为:

¥Refine the SQL Agent node's behavior using these options:

已忽略表格#

¥Ignored Tables

如果你希望节点忽略数据库中的某些表,请输入以逗号分隔的表列表,以表明你希望节点忽略这些表。

¥If you'd like the node to ignore any tables from the database, enter a comma-separated list of tables you'd like it to ignore.

如果留空,代理不会忽略任何表。

¥If left empty, the agent doesn't ignore any tables.

包含示例行#

¥Include Sample Rows

输入要包含在提示代理的样本行数。默认为 3

¥Enter the number of sample rows to include in the prompt to the agent. Default is 3.

示例行有助于代理理解数据库架构,但也会增加使用的令牌数量。

¥Sample rows help the agent understand the schema of the database, but they also increase the number of tokens used.

包含表格#

¥Included Tables

如果你只想包含数据库中的特定表,请输入以逗号分隔的表列表。

¥If you'd only like to include specific tables from the database, enter a comma-separated list of tables to include.

如果留空,代理将包含所有表。

¥If left empty, the agent includes all tables.

提示前缀#

¥Prefix Prompt

输入你希望在提示文本之前发送给代理的消息。此初始消息可以为代理提供更多上下文信息和指导,说明它可以做什么和不能做什么,以及如何格式化响应。

¥Enter a message you'd like to send to the agent before the Prompt text. This initial message can provide more context and guidance to the agent about what it can and can't do, and how to format the response.

n8n 会在此字段中填充一个示例。

¥n8n fills this field with an example.

后缀提示#

¥Suffix Prompt

输入你希望在提示文本之后发送给代理的消息。

¥Enter a message you'd like to send to the agent after the Prompt text.

可用的 LangChain 表达式:

¥Available LangChain expressions:

  • {chatHistory}:此对话中的消息历史记录,有助于维护上下文。

¥{chatHistory}: A history of messages in this conversation, useful for maintaining context.

  • {input}:包含用户提示。

¥{input}: Contains the user prompt.

  • {agent_scratchpad}:下次迭代需要记住的信息。

¥{agent_scratchpad}: Information to remember for the next iteration.

n8n 会在此字段中填充一个示例。

¥n8n fills this field with an example.

限制#

¥Limit

请输入要返回的最大结果数。

¥Enter the maximum number of results to return.

默认为 10

¥Default is 10.

模板和示例#

¥Templates and examples

请参阅主 AI 代理节点的 模板和示例 部分。

¥Refer to the main AI Agent node's Templates and examples section.

常见问题#

¥Common issues

有关常见问题或建议的解决方案,请参阅 常见问题

¥For common questions or issues and suggested solutions, refer to Common issues.