Agent Strategy Plugin Architecture#
Agent strategies β the reasoning engines powering the Agent node (agent_v2) in Dify Workflows and Chatflows β are not built into the API process. They are plugins resolved at runtime through the Plugin Daemon, meaning strategy availability is determined entirely by which plugins are installed and whether required services are running. This is a deployment configuration difference, not an intentional Cloud-vs-self-hosted feature restriction.
Two agent surfaces coexist: The legacy Agent-type app (
mode: agent-chat) uses hard-coded in-process runners (BaseAgentRunner,CotAgentRunner,FunctionCallAgentRunner) and requires no additional services. Theagent_v2Workflow/Chatflow node uses the plugin-backed architecture described here.
Runtime Resolution Flow#
dify-agentmicroservice: The actual async execution of agent runs is handled by a dedicated FastAPI microservice (dify-agent) β distinct from the main API process β which communicates with the Plugin Daemon to resolve LLM providers and tools. It was introduced in PR #36087.
When an Agent node executes, the call chain is:
AgentNode._run()
β AgentStrategyResolver.resolve(provider, strategy_name)
β PluginAgentStrategy (parameter adapter)
β 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 β so plugins can be installed or updated without redeploying. -
PluginAgentStrategyis the strategy-pattern adapter. It holds thetenant_idandAgentStrategyEntitydeclaration, converts parameters to the plugin wire format, and delegates invocation toPluginAgentClient. -
PluginAgentClientmakes HTTP calls to the Plugin Daemon:- List providers:
GET /plugin/{tenant_id}/management/agent_strategies - Invoke:
POST /plugin/{tenant_id}/dispatch/agent_strategy/invoke - Responses are streamed as
AgentInvokeMessageobjects via SSE.
- List providers:
-
AgentService.list_agent_providers()andget_agent_provider()surface the samePluginAgentClientcalls as REST endpoints for the UI. -
The frontend
AgentStrategySelectorfetches available strategies viauseStrategyProvidersand renders a searchable picker. If a strategy's plugin is not installed, it shows a warning and an install button.
Plugin Structure & Installation#
An agent strategy plugin is a standard Dify plugin whose manifest.yaml includes the agent_strategy key. This automatically classifies it as PluginCategory.AgentStrategy in the PluginDeclaration model validator.
Installation sources follow the standard plugin model: Marketplace, GitHub, local package, or remote URL. Agent Skill plugins installed this way can be used inside both Workflow and Agent nodes.
Availability: Cloud vs Self-Hosted#
| Requirement | Cloud | Self-hosted β₯ v1.16.0 | Self-hosted < v1.16.0 |
|---|---|---|---|
| Plugin Daemon | Always running | In default stack | In default stack |
dify-agent backend | Always running | Wired in docker-compose.yaml | Not included β add manually |
| Agent strategy plugins | Pre-installed | Install via Plugins page | Install via Plugins page |
As of v1.16.0, agent_backend is a required service in docker/docker-compose.yaml, with api and worker depending on it at startup. Before v1.16.0, AGENT_BACKEND_BASE_URL was absent from the default stack, causing the Agent node to fail with base_url is required when creating a real Agent backend client.
In v1.16.1, Agent V2 nodes appear only in Workflow mode in the frontend node palette β Chatflow does not yet expose the Agent V2 node in the UI, though the backend supports both. Setting NEXT_PUBLIC_ENABLE_AGENT_V2=false restores the legacy Agent node for Chatflows.
Key Configuration Variables#
Defined in api/configs/extra/agent_backend_config.py :
| Variable | Purpose |
|---|---|
AGENT_BACKEND_BASE_URL | URL of the dify-agent microservice (default: http://agent_backend:5050) |
AGENT_BACKEND_API_TOKEN | Bearer token for API auth |
AGENT_BACKEND_USE_FAKE | Dev-only stub β returns hard-coded response, not a functional workaround |
AGENT_BACKEND_STREAM_READ_TIMEOUT_SECONDS | SSE read timeout (default: 30s) |
AGENT_BACKEND_STREAM_MAX_RECONNECTS | Max SSE reconnects (default: 3) |
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 |
The client factory at api/clients/agent_backend/factory.py instantiates either the real or fake backend client based on these settings.
Key Source Files#
| File | Role |
|---|---|
api/core/workflow/nodes/agent/agent_node.py | Workflow integration entry point (AgentNode) |
api/core/agent/strategy/plugin.py | PluginAgentStrategy β parameter adapter |
api/core/plugin/impl/agent.py | PluginAgentClient β HTTP calls to Plugin Daemon |
api/services/agent_service.py | REST API surface for listing/fetching agent providers |
api/configs/extra/agent_backend_config.py | AgentBackendConfig Pydantic settings |
api/clients/agent_backend/factory.py | Real/fake backend client factory |
web/.../agent-strategy-selector.tsx | Frontend strategy picker UI |