Google Docs Integration
Overview
Section titled “Overview”Enable your agents to create, edit, and manage Google Docs documents with text manipulation and formatting. Automate document creation, insert and replace text, manage content ranges, and streamline your document workflows with AI-powered automation.
Prerequisites
Section titled “Prerequisites”Before using the Google Docs integration, ensure you have:
- A CrewAI AMP account with an active subscription
- A Google account with Google Docs access
- Connected your Google account through the Integrations page
Setting Up Google Docs Integration
Section titled “Setting Up Google Docs Integration”1. Connect Your Google Account
Section titled “1. Connect Your Google Account”- Navigate to CrewAI AMP Integrations
- Find Google Docs in the Authentication Integrations section
- Click Connect and complete the OAuth flow
- Grant the necessary permissions for document 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”google_docs/create_document
Description: Create a new Google Document.
Parameters:
title(string, optional): The title for the new document.
google_docs/get_document
Description: Get the contents and metadata of a Google Document.
Parameters:
documentId(string, required): The ID of the document to retrieve.includeTabsContent(boolean, optional): Whether to include tab content. Default isfalse.suggestionsViewMode(string, optional): The suggestions view mode to apply to the document. Enum:DEFAULT_FOR_CURRENT_ACCESS,PREVIEW_SUGGESTIONS_ACCEPTED,PREVIEW_WITHOUT_SUGGESTIONS. Default isDEFAULT_FOR_CURRENT_ACCESS.
google_docs/batch_update
Description: Apply one or more updates to a Google Document.
Parameters:
documentId(string, required): The ID of the document to update.requests(array, required): A list of updates to apply to the document. Each item is an object representing a request.writeControl(object, optional): Provides control over how write requests are executed. ContainsrequiredRevisionId(string) andtargetRevisionId(string).
google_docs/insert_text
Description: Insert text into a Google Document at a specific location.
Parameters:
documentId(string, required): The ID of the document to update.text(string, required): The text to insert.index(integer, optional): The zero-based index where to insert the text. Default is1.
google_docs/replace_text
Description: Replace all instances of text in a Google Document.
Parameters:
documentId(string, required): The ID of the document to update.containsText(string, required): The text to find and replace.replaceText(string, required): The text to replace it with.matchCase(boolean, optional): Whether the search should respect case. Default isfalse.
google_docs/delete_content_range
Description: Delete content from a specific range in a Google Document.
Parameters:
documentId(string, required): The ID of the document to update.startIndex(integer, required): The start index of the range to delete.endIndex(integer, required): The end index of the range to delete.
google_docs/insert_page_break
Description: Insert a page break at a specific location in a Google Document.
Parameters:
documentId(string, required): The ID of the document to update.index(integer, optional): The zero-based index where to insert the page break. Default is1.
google_docs/create_named_range
Description: Create a named range in a Google Document.
Parameters:
documentId(string, required): The ID of the document to update.name(string, required): The name for the named range.startIndex(integer, required): The start index of the range.endIndex(integer, required): The end index of the range.
google_docs/create_document_with_content
Description: Create a new Google Document with content in one action.
Parameters:
title(string, required): The title for the new document. Appears at the top of the document and in Google Drive.content(string, optional): The text content to insert into the document. Use\nfor new paragraphs.
google_docs/append_text
Description: Append text to the end of a Google Document. Automatically inserts at the document end without needing to specify an index.
Parameters:
documentId(string, required): The document ID from create_document response or URL.text(string, required): Text to append at the end of the document. Use\nfor new paragraphs.
google_docs/set_text_bold
Description: Make text bold or remove bold formatting in a Google Document.
Parameters:
documentId(string, required): The document ID.startIndex(integer, required): Start position of text to format.endIndex(integer, required): End position of text to format (exclusive).bold(boolean, required): Settrueto make bold,falseto remove bold.
google_docs/set_text_italic
Description: Make text italic or remove italic formatting in a Google Document.
Parameters:
documentId(string, required): The document ID.startIndex(integer, required): Start position of text to format.endIndex(integer, required): End position of text to format (exclusive).italic(boolean, required): Settrueto make italic,falseto remove italic.
google_docs/set_text_underline
Description: Add or remove underline formatting from text in a Google Document.
Parameters:
documentId(string, required): The document ID.startIndex(integer, required): Start position of text to format.endIndex(integer, required): End position of text to format (exclusive).underline(boolean, required): Settrueto underline,falseto remove underline.
google_docs/set_text_strikethrough
Description: Add or remove strikethrough formatting from text in a Google Document.
Parameters:
documentId(string, required): The document ID.startIndex(integer, required): Start position of text to format.endIndex(integer, required): End position of text to format (exclusive).strikethrough(boolean, required): Settrueto add strikethrough,falseto remove.
google_docs/set_font_size
Description: Change the font size of text in a Google Document.
Parameters:
documentId(string, required): The document ID.startIndex(integer, required): Start position of text to format.endIndex(integer, required): End position of text to format (exclusive).fontSize(number, required): Font size in points. Common sizes: 10, 11, 12, 14, 16, 18, 24, 36.
google_docs/set_text_color
Description: Change the color of text using RGB values (0-1 scale) in a Google Document.
Parameters:
documentId(string, required): The document ID.startIndex(integer, required): Start position of text to format.endIndex(integer, required): End position of text to format (exclusive).red(number, required): Red component (0-1). Example:1for full red.green(number, required): Green component (0-1). Example:0.5for half green.blue(number, required): Blue component (0-1). Example:0for no blue.
google_docs/create_hyperlink
Description: Turn existing text into a clickable hyperlink in a Google Document.
Parameters:
documentId(string, required): The document ID.startIndex(integer, required): Start position of text to make into a link.endIndex(integer, required): End position of text to make into a link (exclusive).url(string, required): The URL the link should point to. Example:"https://example.com".
google_docs/apply_heading_style
Description: Apply a heading or paragraph style to a text range in a Google Document.
Parameters:
documentId(string, required): The document ID.startIndex(integer, required): Start position of paragraph(s) to style.endIndex(integer, required): End position of paragraph(s) to style.style(string, required): The style to apply. Enum:NORMAL_TEXT,TITLE,SUBTITLE,HEADING_1,HEADING_2,HEADING_3,HEADING_4,HEADING_5,HEADING_6.
google_docs/set_paragraph_alignment
Description: Set text alignment for paragraphs in a Google Document.
Parameters:
documentId(string, required): The document ID.startIndex(integer, required): Start position of paragraph(s) to align.endIndex(integer, required): End position of paragraph(s) to align.alignment(string, required): Text alignment. Enum:START(left),CENTER,END(right),JUSTIFIED.
google_docs/set_line_spacing
Description: Set line spacing for paragraphs in a Google Document.
Parameters:
documentId(string, required): The document ID.startIndex(integer, required): Start position of paragraph(s).endIndex(integer, required): End position of paragraph(s).lineSpacing(number, required): Line spacing as percentage.100= single,115= 1.15x,150= 1.5x,200= double.
google_docs/create_paragraph_bullets
Description: Convert paragraphs to a bulleted or numbered list in a Google Document.
Parameters:
documentId(string, required): The document ID.startIndex(integer, required): Start position of paragraphs to convert to list.endIndex(integer, required): End position of paragraphs to convert to list.bulletPreset(string, required): Bullet/numbering style. Enum:BULLET_DISC_CIRCLE_SQUARE,BULLET_DIAMONDX_ARROW3D_SQUARE,BULLET_CHECKBOX,BULLET_ARROW_DIAMOND_DISC,BULLET_STAR_CIRCLE_SQUARE,NUMBERED_DECIMAL_ALPHA_ROMAN,NUMBERED_DECIMAL_ALPHA_ROMAN_PARENS,NUMBERED_DECIMAL_NESTED,NUMBERED_UPPERALPHA_ALPHA_ROMAN,NUMBERED_UPPERROMAN_UPPERALPHA_DECIMAL.
google_docs/delete_paragraph_bullets
Description: Remove bullets or numbering from paragraphs in a Google Document.
Parameters:
documentId(string, required): The document ID.startIndex(integer, required): Start position of list paragraphs.endIndex(integer, required): End position of list paragraphs.
google_docs/insert_table_with_content
Description: Insert a table with content into a Google Document in one action. Provide content as a 2D array.
Parameters:
documentId(string, required): The document ID.rows(integer, required): Number of rows in the table.columns(integer, required): Number of columns in the table.index(integer, optional): Position to insert the table. If not provided, the table is inserted at the end of the document.content(array, required): Table content as a 2D array. Each inner array is a row. Example:[["Year", "Revenue"], ["2023", "$43B"], ["2024", "$45B"]].
google_docs/insert_table_row
Description: Insert a new row above or below a reference cell in an existing table.
Parameters:
documentId(string, required): The document ID.tableStartIndex(integer, required): The start index of the table. Get from get_document.rowIndex(integer, required): Row index (0-based) of reference cell.columnIndex(integer, optional): Column index (0-based) of reference cell. Default is0.insertBelow(boolean, optional): Iftrue, insert below the reference row. Iffalse, insert above. Default istrue.
google_docs/insert_table_column
Description: Insert a new column left or right of a reference cell in an existing table.
Parameters:
documentId(string, required): The document ID.tableStartIndex(integer, required): The start index of the table.rowIndex(integer, optional): Row index (0-based) of reference cell. Default is0.columnIndex(integer, required): Column index (0-based) of reference cell.insertRight(boolean, optional): Iftrue, insert to the right. Iffalse, insert to the left. Default istrue.
google_docs/delete_table_row
Description: Delete a row from an existing table in a Google Document.
Parameters:
documentId(string, required): The document ID.tableStartIndex(integer, required): The start index of the table.rowIndex(integer, required): Row index (0-based) to delete.columnIndex(integer, optional): Column index (0-based) of any cell in the row. Default is0.
google_docs/delete_table_column
Description: Delete a column from an existing table in a Google Document.
Parameters:
documentId(string, required): The document ID.tableStartIndex(integer, required): The start index of the table.rowIndex(integer, optional): Row index (0-based) of any cell in the column. Default is0.columnIndex(integer, required): Column index (0-based) to delete.
google_docs/merge_table_cells
Description: Merge a range of table cells into a single cell. Content from all cells is preserved.
Parameters:
documentId(string, required): The document ID.tableStartIndex(integer, required): The start index of the table.rowIndex(integer, required): Starting row index (0-based) for the merge.columnIndex(integer, required): Starting column index (0-based) for the merge.rowSpan(integer, required): Number of rows to merge.columnSpan(integer, required): Number of columns to merge.
google_docs/unmerge_table_cells
Description: Unmerge previously merged table cells back into individual cells.
Parameters:
documentId(string, required): The document ID.tableStartIndex(integer, required): The start index of the table.rowIndex(integer, required): Row index (0-based) of the merged cell.columnIndex(integer, required): Column index (0-based) of the merged cell.rowSpan(integer, required): Number of rows the merged cell spans.columnSpan(integer, required): Number of columns the merged cell spans.
google_docs/insert_inline_image
Description: Insert an image from a public URL into a Google Document. The image must be publicly accessible, under 50MB, and in PNG/JPEG/GIF format.
Parameters:
documentId(string, required): The document ID.uri(string, required): Public URL of the image. Must be accessible without authentication.index(integer, optional): Position to insert the image. If not provided, the image is inserted at the end of the document. Default is1.
google_docs/insert_section_break
Description: Insert a section break to create document sections with different formatting.
Parameters:
documentId(string, required): The document ID.index(integer, required): Position to insert the section break.sectionType(string, required): The type of section break. Enum:CONTINUOUS(stays on same page),NEXT_PAGE(starts a new page).
google_docs/create_header
Description: Create a header for the document. Returns a headerId which can be used with insert_text to add header content.
Parameters:
documentId(string, required): The document ID.type(string, optional): Header type. Enum:DEFAULT. Default isDEFAULT.
google_docs/create_footer
Description: Create a footer for the document. Returns a footerId which can be used with insert_text to add footer content.
Parameters:
documentId(string, required): The document ID.type(string, optional): Footer type. Enum:DEFAULT. Default isDEFAULT.
google_docs/delete_header
Description: Delete a header from the document. Use get_document to find the headerId.
Parameters:
documentId(string, required): The document ID.headerId(string, required): The header ID to delete. Get from get_document response.
google_docs/delete_footer
Description: Delete a footer from the document. Use get_document to find the footerId.
Parameters:
documentId(string, required): The document ID.footerId(string, required): The footer ID to delete. Get from get_document response.
Usage Examples
Section titled “Usage Examples”Basic Google Docs Agent Setup
Section titled “Basic Google Docs Agent Setup”from crewai import Agent, Task, Crew
# Create an agent with Google Docs capabilitiesdocs_agent = Agent( role="Document Creator", goal="Create and manage Google Docs documents efficiently", backstory="An AI assistant specialized in Google Docs document creation and editing.", apps=['google_docs'] # All Google Docs actions will be available)
# Task to create a new documentcreate_doc_task = Task( description="Create a new Google Document titled 'Project Status Report'", agent=docs_agent, expected_output="New Google Document 'Project Status Report' created successfully")
# Run the taskcrew = Crew( agents=[docs_agent], tasks=[create_doc_task])
crew.kickoff()Text Editing and Content Management
Section titled “Text Editing and Content Management”from crewai import Agent, Task, Crew
# Create an agent focused on text editingtext_editor = Agent( role="Document Editor", goal="Edit and update content in Google Docs documents", backstory="An AI assistant skilled in precise text editing and content management.", apps=['google_docs/insert_text', 'google_docs/replace_text', 'google_docs/delete_content_range'])
# Task to edit document contentedit_content_task = Task( description="In document 'your_document_id', insert the text 'Executive Summary: ' at the beginning, then replace all instances of 'TODO' with 'COMPLETED'.", agent=text_editor, expected_output="Document updated with new text inserted and TODO items replaced.")
crew = Crew( agents=[text_editor], tasks=[edit_content_task])
crew.kickoff()Advanced Document Operations
Section titled “Advanced Document Operations”from crewai import Agent, Task, Crew
# Create an agent for advanced document operationsdocument_formatter = Agent( role="Document Formatter", goal="Apply advanced formatting and structure to Google Docs", backstory="An AI assistant that handles complex document formatting and organization.", apps=['google_docs/batch_update', 'google_docs/insert_page_break', 'google_docs/create_named_range'])
# Task to format documentformat_doc_task = Task( description="In document 'your_document_id', insert a page break at position 100, create a named range called 'Introduction' for characters 1-50, and apply batch formatting updates.", agent=document_formatter, expected_output="Document formatted with page break, named range, and styling applied.")
crew = Crew( agents=[document_formatter], tasks=[format_doc_task])
crew.kickoff()Troubleshooting
Section titled “Troubleshooting”Common Issues
Section titled “Common Issues”Authentication Errors
- Ensure your Google account has the necessary permissions for Google Docs access.
- Verify that the OAuth connection includes all required scopes (
https://www.googleapis.com/auth/documents).
Document ID Issues
- Double-check document IDs for correctness.
- Ensure the document exists and is accessible to your account.
- Document IDs can be found in the Google Docs URL.
Text Insertion and Range Operations
- When using
insert_textordelete_content_range, ensure index positions are valid. - Remember that Google Docs uses zero-based indexing.
- The document must have content at the specified index positions.
Batch Update Request Formatting
- When using
batch_update, ensure therequestsarray is correctly formatted according to the Google Docs API documentation. - Complex updates require specific JSON structures for each request type.
Replace Text Operations
- For
replace_text, ensure thecontainsTextparameter exactly matches the text you want to replace. - Use
matchCaseparameter to control case sensitivity.
Getting Help
Section titled “Getting Help”Need Help?
Contact our support team for assistance with Google Docs integration setup or troubleshooting.