Agent Node Data Models#
Dify's workflow engine has two versions of the Agent node, both sharing BuiltinNodeTypes.AGENT as their node_type but distinguished by a version string. Their Pydantic node-data models live in separate modules:
| Version | Class | Module |
|---|---|---|
| V1 (legacy) | AgentNodeData | api/core/workflow/nodes/agent/entities.py |
| V2 | DifyAgentNodeData | api/core/workflow/nodes/agent_v2/entities.py |
Both inherit from graphon.entities.base_node_data.BaseNodeData (external graphon==0.6.0 package), which supplies the common type and version fields.
V1: AgentNodeData#
AgentNodeData is the model for legacy plugin-strategy–based agent nodes.
Optional fields (with defaults)#
| Field | Type | Default | Notes |
|---|---|---|---|
agent_strategy_provider_name | str | "" | Provider owning the strategy (e.g. plugin name) |
agent_strategy_name | str | "" | Strategy identifier |
agent_strategy_label | str | "" | Human-readable label |
agent_parameters | dict[str, AgentInput] | {} | Per-parameter inputs keyed by parameter name |
memory | MemoryConfig | None | None | Conversation window + role-prefix config |
tool_node_version | str | None | None | None → legacy parameter-parsing rules apply |
Nested: AgentInput#
Each value in agent_parameters is an AgentInput:
| Field | Type |
|---|---|
value | list[str] | list[ToolSelector] | Any |
type | Literal["mixed", "variable", "constant"] |
Supporting enums#
ParamsAutoGenerated(IntEnum) —CLOSE=0,OPEN=1: signals whether agent parameters were auto-generated.AgentOldVersionModelFeatures(StrEnum) : LLM capability flags used when resolving model compatibility for older SDK versions —TOOL_CALL,MULTI_TOOL_CALL,AGENT_THOUGHT,VISION,STREAM_TOOL_CALL,DOCUMENT,VIDEO,AUDIO.
Referenced types#
MemoryConfig(fromgraphon) —window: WindowConfig(enabled: bool,size: int | None) and optionalrole_prefix: RolePrefix(user: str,assistant: str).ToolSelector(fromapi/core/tools/entities/tool_entities.py) — holdsprovider_id,tool_name,tool_description,tool_configuration,tool_parameters, and optionalcredential_id.
V2: DifyAgentNodeData#
DifyAgentNodeData is intentionally minimal — it represents the node slot only; all agent configuration is stored externally.
Fields#
| Field | Type | Default | Notes |
|---|---|---|---|
type | NodeType | BuiltinNodeTypes.AGENT | Inherited override |
agent_node_kind | Literal["dify_agent"] | REQUIRED | Discriminator tag; must be explicitly set to "dify_agent" |
Validation#
A @model_validator(mode="after") enforces version == "2" . Deserializing a node with a different version raises a ValueError immediately.
The required agent_node_kind field allows historical type=agent, version=2 nodes (which used a V2 tool-parameter format but preceded the Dify Agent feature) to be distinguished from new Dify Agent nodes. Historical nodes lacking this field are routed to the legacy Agent V1 implementation at dispatch and validation .
V2 carries no agent configuration directly. The actual agent identity and settings are stored in a separate Agent Soul (AgentSoulConfig) JSON snapshot in AgentConfigSnapshot.config_snapshot, linked via a WorkflowAgentNodeBinding row. The bound agent and its configuration are resolved separately at validation and runtime .
Validation Behavior for Unconfigured Nodes#
Because DifyAgentNodeData has no binding fields, an unbound V2 node is schema-valid at the Pydantic level. Binding enforcement is layered on top by WorkflowAgentNodeValidator:
- Draft validation (
validate_draft_workflow) — validates the node schema viaDifyAgentNodeData.model_validatebut silently skips a missing binding. An unconfigured node is not an error in a draft. - Publish validation (
validate_published_workflow) — a missing binding is a hard error; the workflow cannot be published with an unbound V2 agent node.
Key Source Files#
| File | Role |
|---|---|
api/core/workflow/nodes/agent/entities.py | V1: AgentNodeData, AgentInput, ParamsAutoGenerated, AgentOldVersionModelFeatures |
api/core/workflow/nodes/agent_v2/entities.py | V2: DifyAgentNodeData |
api/core/tools/entities/tool_entities.py | ToolSelector used in V1 AgentInput.value |
api/models/agent_config_entities.py | AgentSoulConfig — full agent config snapshot linked from V2 nodes |
api/core/workflow/nodes/agent_v2/validators.py | V2 draft/publish binding validation |