Agent Strategy Plugin Architecture#
Agent strategies — the reasoning engines that power Dify's Agent node in Workflows and Chatflows (agent_v2) — are not built into the API process. They are plugins resolved at runtime through the Plugin Daemon. This means strategy availability is entirely determined by which plugins are installed and whether the required services are running; it is not an intentional Cloud-vs-self-hosted feature restriction.
Two agent surfaces coexist: The legacy Agent-type app (
mode: agent-chat) runs entirely in-process with hard-coded CoT/Function-Calling runners (BaseAgentRunner,CotAgentRunner,FunctionCallAgentRunner) and requires no additional services. The newer Workflow/Chatflow Agent node (agent_v2) uses the plugin-backed architecture described here.
Runtime Resolution Flow#
When an Agent node executes inside a workflow, the resolution chain is:
AgentNode._run()
→ AgentStrategyResolver.resolve(provider, strategy_name)
→ PluginAgentStrategy (wraps invocation)
→ PluginAgentClient (HTTP → Plugin Daemon :5002)
→ Plugin Daemon loads & executes the agent strategy plugin
-
AgentNode._run()resolves the configured strategy at execution time (not at workflow load), allowing plugins to be installed or updated without redeploying. -
PluginAgentStrategyimplements the strategy pattern, converting parameters to the plugin wire format and delegating invocation toPluginAgentClient. -
PluginAgentClientmakes HTTP calls to the Plugin Daemon :- List providers:
GET /plugin/{tenant_id}/management/agent_strategy - Invoke:
POST /plugin/{tenant_id}/dispatch/agent_strategy/invoke
- List providers:
-
AgentService.list_agent_providers()andget_agent_provider()expose the samePluginAgentClientcalls as API endpoints for the UI.
The frontend AgentStrategySelector fetches available strategies via useStrategyProviders and renders them as a searchable picker. If a selected strategy's plugin is not installed, the selector shows a warning and optionally an install button.
Agent Strategy Plugin Structure#
An agent strategy plugin is a standard Dify plugin whose manifest.yaml has the agent_strategy key — automatically classified as PluginCategory.AgentStrategy by the PluginDeclaration model validator. Installation sources follow the standard plugin model: Marketplace, GitHub, local package, or remote URL.
The dify-agent backend service (introduced in PR #36087) handles the actual async execution of agent runs, communicating with the Plugin Daemon to resolve LLM providers and tools. It is a FastAPI microservice distinct from the API process.
Availability: Cloud vs Self-Hosted#
The availability gap between Cloud and self-hosted is a deployment configuration difference, not a feature gate:
| Requirement | Cloud | Self-hosted (≥ v1.16.0) | Self-hosted (< v1.16.0) |
|---|---|---|---|
| Plugin Daemon | Always running | Included in default stack | Included in default stack |
dify-agent backend | Always running | Included and wired in docker-compose.yaml | Not included — must add manually |
| Agent strategy plugins | Pre-installed | Must install via Plugins page | Must install via Plugins page |
As of v1.16.0, agent_backend is a fully wired, non-optional service in docker/docker-compose.yaml, with api and worker depending on it at startup. Before v1.16.0, AGENT_BACKEND_BASE_URL was not set in the default stack, causing the Agent node to fail immediately with base_url is required when creating a real Agent backend client.
AGENT_BACKEND_USE_FAKE=true is a development stub that returns a hard-coded response without calling any LLM or tools. It is not a functional workaround.
Key Configuration & Source References#
| Config variable | Purpose |
|---|---|
AGENT_BACKEND_BASE_URL | URL of the dify-agent microservice (default: http://agent_backend:5050) |
AGENT_BACKEND_USE_FAKE | Dev-only stub; bypasses real execution |
DIFY_AGENT_PLUGIN_DAEMON_URL | URL the dify-agent service uses to reach Plugin Daemon (default: :5002) |
DIFY_AGENT_PLUGIN_DAEMON_API_KEY | Auth key for Plugin Daemon access |
Key source files:
| File | Role |
|---|---|
api/configs/extra/agent_backend_config.py | AgentBackendConfig Pydantic settings |
api/clients/agent_backend/factory.py | Creates real or fake agent backend client |
api/core/plugin/impl/agent.py | PluginAgentClient — HTTP calls to Plugin Daemon |
api/core/agent/strategy/plugin.py | PluginAgentStrategy — strategy pattern wrapper |
api/core/workflow/nodes/agent/agent_node.py | AgentNode — workflow integration point |
api/services/agent_service.py | AgentService.list_agent_providers(), get_agent_provider() |
web/.../agent-strategy-selector.tsx | Frontend strategy picker with install/warn UX |