Plugin backwards invocation for knowledge base operations (documents, metadata, pipeline runs)
Self Checks
- [x] I have read the Contributing Guide and Language Policy.
- [x] I have searched for existing issues search for existing issues, including closed ones.
- [x] I confirm that I am using English to submit this report, otherwise it will be closed.
- [x] Please do not modify this template :) and fill in all the required fields.
1. Is this request related to a challenge you're experiencing? Tell me about your story.
We keep two pipeline knowledge bases in sync with an external system: records are added, edited and removed there, and Dify should follow (one-way) within a few minutes. The setup is entirely on the Dify side:
- an
online_documentdatasource plugin that lists the external records as pages and returns their content, - a tool plugin that compares the pages with the documents already in the knowledge base, runs the published pipeline for new or changed pages, and deletes documents whose record changed or disappeared,
- a workflow with a Schedule trigger that calls the tool every 5 minutes.
It works, but the tool cannot do any of this through the plugin SDK. Backwards invocation covers models, tools, apps, workflow nodes, storage and files, but nothing for knowledge bases. So a plugin running inside Dify has to call Dify's own Service API over HTTP:
- every tool instance needs the Dify API base URL as seen from the plugin daemon (
http://api:5001in docker compose, something else in other deployments), plus a knowledge base API key. That key is workspace-wide and has to be stored as a tool parameter. Neither should be needed for a plugin to work with the workspace it is installed in. - going through a workflow HTTP Request node instead does not help: it goes through the SSRF proxy, which blocks private addresses unless
SSRF_PROXY_ALLOW_PRIVATE_IPSis changed.
What we would like is backwards invocation for common knowledge base operations, scoped to the plugin's tenant and gated by a manifest permission like the existing tool / model / app ones. For example, a self.session.knowledge namespace offering:
- list documents of a dataset, with indexing status and metadata (paginated),
- delete a document,
- create metadata fields and set document metadata,
- run the published knowledge pipeline for a list of datasource items, and re-run it for an existing document in place (
original_document_id), - get the indexing status of a batch,
- retrieve chunks (this would also cover langgenius/dify-plugin-sdks#129).
2. Additional context or comments
Related limitations we ran into while building this, which shaped the request above:
- No in-place update through the Service API.
POST /v1/datasets/{id}/pipeline/rundoes not acceptoriginal_document_id, so every run creates a new document. The console endpointPOST /console/api/rag/pipelines/{id}/workflows/published/runaccepts it and replaces the document in place. Over the Service API, an update means: create a new document, wait for indexing, then delete the old one. To match documents to records again, we track both in custom metadata (record_id, content hash). - No re-sync for pipeline
online_documentdocuments.document_indexing_sync_taskonly handles legacynotion_importdocuments and is triggered manually. Documents imported through a datasource plugin (including the official Notion datasource) are never refreshed, so every integration needs its own sync tool. - A datasource and a tool cannot ship in one package (
datasource and tool, model, endpoint, trigger, or agent_strategy cannot be provided at the same time). The sync logic therefore lives in a second plugin. Since that plugin cannot use the datasource directly, it gets the page list by callingPOST /v1/datasets/{id}/pipeline/datasource/nodes/{node_id}/runover HTTP. - Minor, possibly a separate bug: on 1.19.0, running an
online_documentpipeline through the Service API withoutcredential_idindatasource_info_listfails withinvalid input syntax for type uuid: ""instead of using the default credential.
Environment: self-hosted Dify 1.19.0 (docker compose), plugin daemon 0.6.14, dify_plugin 0.10.2. We also checked the 1.17.1 source: the Service API endpoints above are the same there.
3. Can you help us with this feature?
- [ ] I am interested in contributing to this feature.
This is indeed a missing piece in the plugin architecture. Right now, backward invocation routes via dify-plugin-daemon directly to core through inner_api endpoints, but dataset and knowledge pipeline operations were never wired into the inner API or exposed via dify-plugin-sdks.
Until self.session.knowledge (or equivalent dataset RPC dispatching) is implemented in core, here is the cleanest way to handle this without fighting the SSRF proxy:
- Bypass SSRF for internal calls:
In your
.env, set:
Patch Preview (First 3 lines of verified fix):
NO_PROXY=api,plugin_daemon,localhost,127.0.0.1
# ... [TRUNCATED — Full production patch & verification steps locked below]