跳转到内容

Microsoft Word 集成

让你的智能体在 OneDrive 或 SharePoint 中创建、读取和管理 Word 文档与文本文件。借助 AI 驱动的自动化,你可以自动创建文档、检索内容、管理文档属性,并简化文档工作流。

在使用 Microsoft Word 集成之前,请确保你已具备:

  • 一个拥有有效订阅的 CrewAI AMP 账户
  • 一个可访问 Word 和 OneDrive/SharePoint 的 Microsoft 账户
  • 通过 集成页面 连接了你的 Microsoft 账户
  1. 访问 CrewAI AMP Integrations
  2. 在 Authentication Integrations 部分找到 Microsoft Word
  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
microsoft_word/get_documents

说明: 获取 OneDrive 或 SharePoint 中的所有 Word 文档。

参数:

  • select (string, optional): 选择要返回的特定属性。
  • filter (string, optional): 使用 OData 语法过滤结果。
  • expand (string, optional): 内联展开相关资源。
  • top (integer, optional): 要返回的项目数(最小 1,最大 999)。
  • orderby (string, optional): 按指定属性排序结果。
microsoft_word/create_text_document

说明: 使用内容创建一个文本文档(.txt)。对于需要可读、可编辑的程序化内容创建,推荐使用此操作。

参数:

  • file_name (string, required): 文本文档名称(应以 .txt 结尾)。
  • content (string, optional): 文档的文本内容。默认值为 “This is a new text document created via API.”
microsoft_word/get_document_content

说明: 获取文档内容(最适合文本文件)。

参数:

  • file_id (string, required): 文档的 ID。
microsoft_word/get_document_properties

说明: 获取文档的属性和元数据。

参数:

  • file_id (string, required): 文档的 ID。
microsoft_word/delete_document

说明: 删除文档。

参数:

  • file_id (string, required): 要删除的文档 ID。
microsoft_word/copy_document

说明: 将文档复制到 OneDrive 中的新位置。

参数:

  • file_id (string, required): 要复制的文档 ID
  • name (string, optional): 复制后文档的新名称
  • parent_id (string, optional): 目标文件夹的 ID(默认到根目录)
microsoft_word/move_document

说明: 将文档移动到 OneDrive 中的新位置。

参数:

  • file_id (string, required): 要移动的文档 ID
  • parent_id (string, required): 目标文件夹的 ID
  • name (string, optional): 移动后文档的新名称
from crewai import Agent, Task, Crew
# Create an agent with Microsoft Word capabilities
word_agent = Agent(
role="Document Manager",
goal="Manage Word documents and text files efficiently",
backstory="An AI assistant specialized in Microsoft Word document operations and content management.",
apps=['microsoft_word'] # All Word actions will be available
)
# Task to create a new text document
create_doc_task = Task(
description="Create a new text document named 'meeting_notes.txt' with content 'Meeting Notes from January 2024: Key discussion points and action items.'",
agent=word_agent,
expected_output="New text document 'meeting_notes.txt' created successfully."
)
# Run the task
crew = Crew(
agents=[word_agent],
tasks=[create_doc_task]
)
crew.kickoff()
from crewai import Agent, Task, Crew
# Create an agent focused on document operations
document_reader = Agent(
role="Document Reader",
goal="Retrieve and analyze document content and properties",
backstory="An AI assistant skilled in reading and analyzing document content.",
apps=['microsoft_word/get_documents', 'microsoft_word/get_document_content', 'microsoft_word/get_document_properties']
)
# Task to list and read documents
read_docs_task = Task(
description="List all Word documents in my OneDrive, then get the content and properties of the first document found.",
agent=document_reader,
expected_output="List of documents with content and properties of the first document."
)
crew = Crew(
agents=[document_reader],
tasks=[read_docs_task]
)
crew.kickoff()
from crewai import Agent, Task, Crew
# Create an agent for document management
document_organizer = Agent(
role="Document Organizer",
goal="Organize and clean up document collections",
backstory="An AI assistant that helps maintain organized document libraries.",
apps=['microsoft_word/get_documents', 'microsoft_word/get_document_properties', 'microsoft_word/delete_document']
)
# Task to organize documents
organize_task = Task(
description="List all documents, check their properties, and identify any documents that might be duplicates or outdated for potential cleanup.",
agent=document_organizer,
expected_output="Analysis of document library with recommendations for organization."
)
crew = Crew(
agents=[document_organizer],
tasks=[organize_task]
)
crew.kickoff()

认证错误

  • 确保你的 Microsoft 账户拥有文件访问所需权限(例如 Files.Read.All, Files.ReadWrite.All)。
  • 验证 OAuth 连接是否包含全部所需范围。

文件创建问题

  • 创建文本文档时,确保 file_name.txt 结尾。
  • 验证你是否对目标位置(OneDrive/SharePoint)具有写权限。

文档访问问题

  • 访问特定文档时,请再次检查文档 ID 是否正确。
  • 确保所引用的文档存在且可访问。
  • 注意该集成最适合用于文本文件(.txt)的内容操作。

内容检索限制

  • get_document_content 操作最适合文本文件(.txt)。
  • 对于复杂的 Word 文档(.docx),可以考虑使用文档属性操作获取元数据。

需要帮助?

联系我们的支持团队,获取 Microsoft Word 集成设置或故障排查方面的帮助。