跳转到内容

Google 表格集成

让你的代理通过 Google 表格管理电子表格数据。读取行、创建新条目、更新现有数据,并借助 AI 驱动的自动化简化数据管理工作流。非常适合数据跟踪、报表和协作式数据管理。

在使用 Google 表格集成前,请确保你已经具备:

  • 一个拥有有效订阅的 CrewAI AMP 账号
  • 一个可访问 Google 表格的 Google 账号
  • 已通过 集成页面 连接你的 Google 账号
  • 带有正确列标题的电子表格,以便进行数据操作
  1. 进入 CrewAI AMP Integrations
  2. 在身份验证集成部分找到 Google Sheets
  3. 点击 Connect 并完成 OAuth 流程
  4. 授予电子表格访问所需的权限
  5. Integration Settings 复制你的 Enterprise Token
Terminal window
uv add crewai-tools
Terminal window
export CREWAI_PLATFORM_INTEGRATION_TOKEN="your_enterprise_token"

或者将其添加到你的 .env 文件中:

CREWAI_PLATFORM_INTEGRATION_TOKEN=your_enterprise_token
google_sheets/get_spreadsheet

描述: 检索电子表格的属性和数据。

参数:

  • spreadsheetId (string, required): 要检索的电子表格 ID。
  • ranges (array, optional): 要从电子表格中检索的范围。
  • includeGridData (boolean, optional): 是否应返回网格数据。默认值:false
  • fields (string, optional): 要包含在响应中的字段。使用此项可通过仅返回所需数据来提升性能。
google_sheets/get_values

描述: 返回电子表格中的一段值。

参数:

  • spreadsheetId (string, required): 要从中检索数据的电子表格 ID。
  • range (string, required): 要从中检索值的 A1 表示法或 R1C1 表示法范围。
  • valueRenderOption (string, optional): 值在输出中应如何表示。可选项:FORMATTED_VALUE, UNFORMATTED_VALUE, FORMULA。默认值:FORMATTED_VALUE
  • dateTimeRenderOption (string, optional): 日期、时间和持续时间在输出中应如何表示。可选项:SERIAL_NUMBER, FORMATTED_STRING。默认值:SERIAL_NUMBER
  • majorDimension (string, optional): 结果应使用的主维度。可选项:ROWS, COLUMNS。默认值:ROWS
google_sheets/update_values

描述: 在电子表格的某个范围内设置值。

参数:

  • spreadsheetId (string, required): 要更新的电子表格 ID。
  • range (string, required): 要更新的范围的 A1 表示法。
  • values (array, required): 要写入的数据。每个数组代表一行。
    [
    ["Value1", "Value2", "Value3"],
    ["Value4", "Value5", "Value6"]
    ]
  • valueInputOption (string, optional): 输入数据应如何解释。可选项:RAW, USER_ENTERED。默认值:USER_ENTERED
google_sheets/append_values

描述: 将值追加到电子表格中。

参数:

  • spreadsheetId (string, required): 要更新的电子表格 ID。
  • range (string, required): 用于搜索逻辑数据表的范围的 A1 表示法。
  • values (array, required): 要追加的数据。每个数组代表一行。
    [
    ["Value1", "Value2", "Value3"],
    ["Value4", "Value5", "Value6"]
    ]
  • valueInputOption (string, optional): 输入数据应如何解释。可选项:RAW, USER_ENTERED。默认值:USER_ENTERED
  • insertDataOption (string, optional): 输入数据应如何插入。可选项:OVERWRITE, INSERT_ROWS。默认值:INSERT_ROWS
google_sheets/create_spreadsheet

描述: 创建新的电子表格。

参数:

  • title (string, required): 新电子表格的标题。
  • sheets (array, optional): 电子表格中的工作表。
    [
    {
    "properties": {
    "title": "Sheet1"
    }
    }
    ]
from crewai import Agent, Task, Crew
# Create an agent with Google Sheets capabilities
sheets_agent = Agent(
role="Data Manager",
goal="Manage spreadsheet data and track information efficiently",
backstory="An AI assistant specialized in data management and spreadsheet operations.",
apps=['google_sheets']
)
# Task to add new data to a spreadsheet
data_entry_task = Task(
description="Add a new customer record to the customer database spreadsheet with name, email, and signup date",
agent=sheets_agent,
expected_output="New customer record added successfully to the spreadsheet"
)
# Run the task
crew = Crew(
agents=[sheets_agent],
tasks=[data_entry_task]
)
crew.kickoff()
from crewai import Agent, Task, Crew
# Create agent with specific Google Sheets actions only
data_collector = Agent(
role="Data Collector",
goal="Collect and organize data in spreadsheets",
backstory="An AI assistant that focuses on data collection and organization.",
apps=[
'google_sheets/get_values',
'google_sheets/update_values'
]
)
# Task to collect and organize data
data_collection = Task(
description="Retrieve current inventory data and add new product entries to the inventory spreadsheet",
agent=data_collector,
expected_output="Inventory data retrieved and new products added successfully"
)
crew = Crew(
agents=[data_collector],
tasks=[data_collection]
)
crew.kickoff()
from crewai import Agent, Task, Crew
data_analyst = Agent(
role="Data Analyst",
goal="Analyze spreadsheet data and generate insights",
backstory="An experienced data analyst who extracts insights from spreadsheet data.",
apps=['google_sheets']
)
# Task to analyze data and create reports
analysis_task = Task(
description="""
1. Retrieve all sales data from the current month's spreadsheet
2. Analyze the data for trends and patterns
3. Create a summary report in a new row with key metrics
""",
agent=data_analyst,
expected_output="Sales data analyzed and summary report created with key insights"
)
crew = Crew(
agents=[data_analyst],
tasks=[analysis_task]
)
crew.kickoff()
from crewai import Agent, Task, Crew
spreadsheet_manager = Agent(
role="Spreadsheet Manager",
goal="Create and manage spreadsheets efficiently",
backstory="An AI assistant that specializes in creating and organizing spreadsheets.",
apps=['google_sheets']
)
# Task to create and set up new spreadsheets
setup_task = Task(
description="""
1. Create a new spreadsheet for quarterly reports
2. Set up proper headers and structure
3. Add initial data and formatting
""",
agent=spreadsheet_manager,
expected_output="New quarterly report spreadsheet created and properly structured"
)
crew = Crew(
agents=[spreadsheet_manager],
tasks=[setup_task]
)
crew.kickoff()