Skip to content
CrewAI 文档版本 跟随上游 源快照 6b70a295 更新于 2026-10-18

AI Mind 工具

AIMindTool 旨在使用自然语言查询数据源。

AIMindTool

描述

AIMindTool 是 AI-Minds 的封装,由 MindsDB 提供。它允许你只需配置数据源的连接参数,即可使用自然语言查询数据源。当你需要从存储在 PostgreSQL、MySQL、MariaDB、ClickHouse、Snowflake 和 Google BigQuery 等各种数据源中的数据里获得问题答案时,此工具很有用。

Minds 是 AI 系统,其工作方式类似于大语言模型(LLM),但更进一步,可以回答来自任何数据的任何问题。这通过以下方式实现:

  • 使用参数化搜索选择与答案最相关的数据
  • 通过语义搜索理解含义并在正确的上下文中提供响应
  • 通过分析数据并使用机器学习(ML)模型来提供精确答案

安装

要将此工具纳入你的项目,你需要安装 Minds SDK:

shell
uv add minds-sdk

入门步骤

要有效使用 AIMindTool,请遵循以下步骤:

  1. 安装包:确认你的 Python 环境中已安装 crewai[tools] 和 minds-sdk 包。
  2. 获取 API 密钥:在此处注册 Minds 账户,并获取 API 密钥。
  3. 配置环境:将你获取的 API 密钥存储在名为 MINDS_API_KEY 的环境变量中,以便该工具使用。

示例

以下示例演示如何初始化该工具并执行查询:

python
from crewai_tools import AIMindTool

# Initialize the AIMindTool
aimind_tool = AIMindTool(
    datasources=[
        {
            "description": "house sales data",
            "engine": "postgres",
            "connection_data": {
                "user": "demo_user",
                "password": "demo_password",
                "host": "samples.mindsdb.com",
                "port": 5432,
                "database": "demo",
                "schema": "demo_data"
            },
            "tables": ["house_sales"]
        }
    ]
)

# Run a natural language query
result = aimind_tool.run("How many 3 bedroom houses were sold in 2008?")
print(result)

参数

AIMindTool 接受以下参数:

  • api_key:可选。你的 Minds API 密钥。如果未提供,将从 MINDS_API_KEY 环境变量中读取。
  • datasources:字典列表,每个字典包含以下键:
    • description:数据源中所包含数据的描述。
    • engine:数据源的引擎(或类型)。
    • connection_data:包含数据源连接参数的字典。
    • tables:数据源将使用的表列表。这是可选的,如果要使用数据源中的所有表,则可以省略。

受支持的数据源及其连接参数列表可在此处找到。

智能体集成示例

以下是将 AIMindTool 与 CrewAI 智能体集成的方法:

python
from crewai import Agent
from crewai.project import agent
from crewai_tools import AIMindTool

# Initialize the tool
aimind_tool = AIMindTool(
    datasources=[
        {
            "description": "sales data",
            "engine": "postgres",
            "connection_data": {
                "user": "your_user",
                "password": "your_password",
                "host": "your_host",
                "port": 5432,
                "database": "your_db",
                "schema": "your_schema"
            },
            "tables": ["sales"]
        }
    ]
)

# Define an agent with the AIMindTool
@agent
def data_analyst(self) -> Agent:
    return Agent(
        config=self.agents_config["data_analyst"],
        allow_delegation=False,
        tools=[aimind_tool]
    )

结论

AIMindTool 提供了一种使用自然语言查询数据源的强大方式,使你无需编写复杂的 SQL 查询即可更轻松地提取洞见。通过连接到各种数据源并利用 AI-Minds 技术,此工具使智能体能够高效地访问和分析数据。

BytesRouter 是社区翻译站点,所有译文仅供参考,一切以官方英文原文为准。