Skip to main content

Overview

Enable your agents to create, read, and manage Word documents and text files in OneDrive or SharePoint. Automate document creation, retrieve content, manage document properties, and streamline your document workflows with AI-powered automation.

Prerequisites

Before using the Microsoft Word integration, ensure you have:
  • A CrewAI AMP account with an active subscription
  • A Microsoft account with Word and OneDrive/SharePoint access
  • Connected your Microsoft account through the Integrations page

Setting Up Microsoft Word Integration

1. Connect Your Microsoft Account

  1. Navigate to CrewAI AMP Integrations
  2. Find Microsoft Word in the Authentication Integrations section
  3. Click Connect and complete the OAuth flow
  4. Grant the necessary permissions for file access
  5. Copy your Enterprise Token from Integration Settings

2. Install Required Package

uv add crewai-tools

Available Actions

Description: Get all Word documents from OneDrive or SharePoint.Parameters:
  • select (string, optional): Select specific properties to return.
  • filter (string, optional): Filter results using OData syntax.
  • expand (string, optional): Expand related resources inline.
  • top (integer, optional): Number of items to return (min 1, max 999).
  • orderby (string, optional): Order results by specified properties.
Description: Create a text document (.txt) with content. RECOMMENDED for programmatic content creation that needs to be readable and editable.Parameters:
  • file_name (string, required): Name of the text document (should end with .txt).
  • content (string, optional): Text content for the document. Default is “This is a new text document created via API.”
Description: Get the content of a document (works best with text files).Parameters:
  • file_id (string, required): The ID of the document.
Description: Get properties and metadata of a document.Parameters:
  • file_id (string, required): The ID of the document.
Description: Delete a document.Parameters:
  • file_id (string, required): The ID of the document to delete.

Usage Examples

Basic Microsoft Word Agent Setup

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()

Reading and Managing Documents

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()

Document Cleanup and Organization

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()

Troubleshooting

Common Issues

Authentication Errors
  • Ensure your Microsoft account has the necessary permissions for file access (e.g., Files.Read.All, Files.ReadWrite.All).
  • Verify that the OAuth connection includes all required scopes.
File Creation Issues
  • When creating text documents, ensure the file_name ends with .txt extension.
  • Verify that you have write permissions to the target location (OneDrive/SharePoint).
Document Access Issues
  • Double-check document IDs for correctness when accessing specific documents.
  • Ensure the referenced documents exist and are accessible.
  • Note that this integration works best with text files (.txt) for content operations.
Content Retrieval Limitations
  • The get_document_content action works best with text files (.txt).
  • For complex Word documents (.docx), consider using the document properties action to get metadata.

Getting Help

Need Help?

Contact our support team for assistance with Microsoft Word integration setup or troubleshooting.
I