Microsoft Word Integration
Overview
Section titled “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
Section titled “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
Section titled “Setting Up Microsoft Word Integration”1. Connect Your Microsoft Account
Section titled “1. Connect Your Microsoft Account”- Navigate to CrewAI AMP Integrations
- Find Microsoft Word in the Authentication Integrations section
- Click Connect and complete the OAuth flow
- Grant the necessary permissions for file access
- Copy your Enterprise Token from Integration Settings
2. Install Required Package
Section titled “2. Install Required Package”uv add crewai-tools3. Environment Variable Setup
Section titled “3. Environment Variable Setup”export CREWAI_PLATFORM_INTEGRATION_TOKEN="your_enterprise_token"Or add it to your .env file:
CREWAI_PLATFORM_INTEGRATION_TOKEN=your_enterprise_tokenAvailable Actions
Section titled “Available Actions”microsoft_word/get_documents
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.
microsoft_word/create_text_document
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.”
microsoft_word/get_document_content
Description: Get the content of a document (works best with text files).
Parameters:
file_id(string, required): The ID of the document.
microsoft_word/get_document_properties
Description: Get properties and metadata of a document.
Parameters:
file_id(string, required): The ID of the document.
microsoft_word/delete_document
Description: Delete a document.
Parameters:
file_id(string, required): The ID of the document to delete.
microsoft_word/copy_document
Description: Copy a document to a new location in OneDrive.
Parameters:
file_id(string, required): The ID of the document to copyname(string, optional): New name for the copied documentparent_id(string, optional): The ID of the destination folder (defaults to root)
microsoft_word/move_document
Description: Move a document to a new location in OneDrive.
Parameters:
file_id(string, required): The ID of the document to moveparent_id(string, required): The ID of the destination foldername(string, optional): New name for the moved document
Usage Examples
Section titled “Usage Examples”Basic Microsoft Word Agent Setup
Section titled “Basic Microsoft Word Agent Setup”from crewai import Agent, Task, Crew
# Create an agent with Microsoft Word capabilitiesword_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 documentcreate_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 taskcrew = Crew( agents=[word_agent], tasks=[create_doc_task])
crew.kickoff()Reading and Managing Documents
Section titled “Reading and Managing Documents”from crewai import Agent, Task, Crew
# Create an agent focused on document operationsdocument_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 documentsread_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
Section titled “Document Cleanup and Organization”from crewai import Agent, Task, Crew
# Create an agent for document managementdocument_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 documentsorganize_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
Section titled “Troubleshooting”Common Issues
Section titled “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_nameends with.txtextension. - 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_contentaction works best with text files (.txt). - For complex Word documents (.docx), consider using the document properties action to get metadata.
Getting Help
Section titled “Getting Help”Need Help?
Contact our support team for assistance with Microsoft Word integration setup or troubleshooting.