Skip to content

feat(google_docs): new Google Docs tool plugin with OAuth and Each user signs in (1.0.0) - #4197

Merged
crazywoola merged 2 commits into
langgenius:mainfrom
ForeignKeyCN:google-docs
Nov 2, 2026
Merged

crazywoola merged 2 commits into
langgenius:mainfrom
ForeignKeyCN:google-docs

Conversation

@ForeignKeyCN

Copy link
Copy Markdown
Contributor

Summary

A new Google Docs tool plugin (tools/google_docs). It reads, creates and edits documents from workflows and agents. Content goes in and comes out as Markdown, so an agent can write a formatted document and read it back. It is built like the other Google plugins: Calendar (#4173), Gmail (#4180), Drive (#4181) and Sheets (#4182).

Auth

  • OAuth from the Dify console: one Google account for the workspace.
  • Each user signs in: every chat user signs in with their own Google account.
    • Uses authorization code + PKCE through a plugin endpoint (GET /google_docs/callback) that only stores the one-time code.
    • The agent hands out a short link to that endpoint (?start=<id>), which redirects to Google. Agents retype links, and a long random state does not always survive that.
    • Per-user tokens are Fernet-encrypted in plugin storage, keyed by a hash of client_id | Dify user ID, and never appear in tool output.
    • After sign-in, the agent reports which account was used.
    • An unticked permission, invalid_grant or a 401 leads to a new sign-in.
    • The callback page warns about forwarded links.
    • google_docs_sign_out forgets the sign-in.
  • Scopes:
    • documents: read and write documents.
    • drive.metadata.readonly: only to find documents by name.

Tools (prefixed google_docs_: the new Agent rejects duplicate tool names across plugins)

Tool What it does
google_docs_find_documents Find documents by name (newest first, across shared drives)
google_docs_get_document A document as Markdown: headings, bullet and numbered lists (nested), tables, bold/italic, links. Also returns its title and headings
google_docs_create_document Create a document, optionally with Markdown content
google_docs_append_content Add Markdown content at the end (optionally on a new page) or at the start
google_docs_replace_text Replace every occurrence of a text, or several at once from a JSON object (template filling); optional match case; reports how many were changed
google_docs_insert_table Add a table at the end from a JSON grid, with an optional bold header row
  • Markdown written:

    • #/##/### headings;
    • -/* bullets and 1. numbered lists;
    • **bold**, *italic* and [text](https://link).

    Everything else becomes normal paragraphs.

  • Writing: one batchUpdate per call. The inserted text is reset to normal style first, so it doesn't inherit the style around it.

  • Tables: cells are filled bottom-up, so earlier indexes stay valid (limit 2000 cells).

  • Document IDs: tools accept an ID or a URL.

  • Output variables: every tool returns typed output variables (success / error plus its fields).

Release Notes

  • New plugin: Google Docs tools.
    • Find, read (as Markdown) and create documents.
    • Append formatted content.
    • Replace text, for example to fill a template.
    • Insert tables.
  • Two ways to authorize: OAuth (one shared account), and Each user signs in for chat agents, where each person works on their own documents.

Change Type

  • Documentation / non-plugin change
  • Non-LLM plugin (tools, extensions, datasource, etc.)
  • LLM plugin

Screenshots / Videos

None yet; the README describes the setup and what users see.

Testing

  • Unit tests: 31 passed (pytest tests). They cover:
    • The sign-in flow, including the short link (redirect, mistyped, expired).
    • The Markdown parser and the request indexes when writing at the end or at the start.
    • Reading back as Markdown: headings, lists, links and tables.
    • The document URL accepted as an ID.
    • Each tool:
      • create with content;
      • append with a page break;
      • replace pairs;
      • insert a table filled bottom-up;
      • find.
    • Every tool's output variables, the manifest and provider.
  • Self-hosted Dify (Community), Each user signs in, real Google account, in an agent chat:
    • signed in through the short link;
    • created a document with Markdown content;
    • appended a section;
    • replaced text;
    • inserted a table;
    • read the document back;
    • found it by name.
  • Not run against Google: google_docs_sign_out and OAuth mode (unit tests only).

Checklist

  • I have read the contribution guidelines
  • New plugin, version 1.0.0

@crazywoola crazywoola left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the plugin and corrected Google Docs text offsets to use UTF-16 code units. All 34 plugin tests pass, including three regressions for emoji in inline styles, paragraph/list ranges, and table headers.

@crazywoola
crazywoola deployed to tools/google_docs November 2, 2026 16:18 — with GitHub Actions Active
@crazywoola
crazywoola merged commit 3189f89 into langgenius:main Nov 2, 2026
4 checks passed

This branch was successfully deployed

1 active deployment
tools/google_docs — 24d914e7 Deployed Nov 2, 2026 by crazywoola via test (tools/google_docs) #2959
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants