Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
fix(agent): preserve plugin-declared model parameters through Agent Soul (#40163)
chelsealong7522ae14b25f
diff --git a/api/clients/agent_backend/request_builder.py b/api/clients/agent_backend/request_builder.pyindex b55957e163a..61d74eb4a4b 100644--- a/api/clients/agent_backend/request_builder.py+++ b/api/clients/agent_backend/request_builder.py@@ -159,8 +159,12 @@ class AgentBackendModelConfig(BaseModel):# ``DifyPluginLLMLayerConfig.model_settings`` is pydantic_ai's ``ModelSettings``# TypedDict (closed: unknown keys are rejected, explicit ``None`` values fail the# per-field type checks). Agent Soul model settings carry a wider, nullable shape-# (``stop`` / ``response_format`` plus null-padded fields), so the layer config-# only receives the keys the runtime contract accepts.+# (``stop`` / ``response_format`` plus null-padded fields, plus arbitrary+# plugin-declared parameters such as Qwen's ``enable_thinking``), so the layer+# config only receives the keys the runtime contract accepts directly; anything+# else is forwarded through ``extra_body``, the TypedDict's own escape hatch for+# provider-specific parameters (see+# ``dify_agent.adapters.llm.model._map_model_settings_to_parameters``)._AGENT_MODEL_SETTINGS_PASSTHROUGH_KEYS = ("temperature","top_p",@@ -168,6 +172,7 @@ _AGENT_MODEL_SETTINGS_PASSTHROUGH_KEYS = ("frequency_penalty","max_tokens",)+_AGENT_MODEL_SETTINGS_KNOWN_KEYS = frozenset({*_AGENT_MODEL_SETTINGS_PASSTHROUGH_KEYS, "stop", "response_format"})def _agent_model_settings(settings: Mapping[str, JsonValue]) -> dict[str, JsonValue] | None:@@ -177,6 +182,15 @@ def _agent_model_settings(settings: Mapping[str, JsonValue]) -> dict[str, JsonVastop = settings.get("stop")if isinstance(stop, list) and stop:sanitized["stop_sequences"] = stop++ extra_body: dict[str, JsonValue] = {+ key: value+ for key, value in settings.items()+ if key not in _AGENT_MODEL_SETTINGS_KNOWN_KEYS and value is not None+ }+ if extra_body:+ sanitized["extra_body"] = extra_body+return sanitized or Nonediff --git a/api/models/agent_config_entities.py b/api/models/agent_config_entities.pyindex b919eaed602..fc845144e68 100644--- a/api/models/agent_config_entities.py+++ b/api/models/agent_config_entities.py@@ -538,8 +538,14 @@ class AgentModelResponseFormatConfig(AgentFlexibleConfig):type: str | None = Field(default=None, max_length=64)-class AgentSoulModelSettings(BaseModel):- model_config = ConfigDict(extra="ignore")+class AgentSoulModelSettings(AgentFlexibleConfig):+ """Model parameters for the Agent Soul model.++ Model plugins can declare arbitrary parameters via ``parameter_rules``+ (e.g. Qwen/Tongyi's ``enable_thinking``) beyond the common OpenAI-style+ fields typed below, so extra keys must round-trip through persistence+ rather than being dropped.+ """temperature: float | None = Nonetop_p: float | None = Nonediff --git a/api/openapi/markdown/console-openapi.md b/api/openapi/markdown/console-openapi.mdindex 2745eacd15f..cce365e6f33 100644--- a/api/openapi/markdown/console-openapi.md+++ b/api/openapi/markdown/console-openapi.md@@ -14933,6 +14933,13 @@ Reference to model credentials resolved only at runtime.#### AgentSoulModelSettings+Model parameters for the Agent Soul model.++Model plugins can declare arbitrary parameters via ``parameter_rules``+(e.g. Qwen/Tongyi's ``enable_thinking``) beyond the common OpenAI-style+fields typed below, so extra keys must round-trip through persistence+rather than being dropped.+| Name | Type | Description | Required || ---- | ---- | ----------- | -------- || frequency_penalty | number | | No |diff --git a/api/tests/unit_tests/clients/agent_backend/test_request_builder.py b/api/tests/unit_tests/clients/agent_backend/test_request_builder.pyindex afbd5c195f2..6f2a10452c5 100644--- a/api/tests/unit_tests/clients/agent_backend/test_request_builder.py+++ b/api/tests/unit_tests/clients/agent_backend/test_request_builder.py@@ -119,6 +119,29 @@ def test_request_builder_separates_agent_soul_and_workflow_job_prompt():assert dumped["composition"]["layers"][2]["config"]["user"] == "Summarize the report."+def test_request_builder_forwards_plugin_specific_model_settings_via_extra_body():+ run_input = _run_input().model_copy(+ update={+ "model": AgentBackendModelConfig(+ plugin_id="langgenius/tongyi",+ model_provider="tongyi",+ model="qwen-plus-latest",+ credentials={"api_key": "secret-key"},+ model_settings={"temperature": 0.7, "enable_thinking": True, "thinking_budget": 4096},+ )+ }+ )++ request = AgentBackendRunRequestBuilder().build_for_workflow_node(run_input)+ layers = {layer.name: layer for layer in request.composition.layers}+ model_config = cast(DifyPluginLLMLayerConfig, layers[DIFY_AGENT_MODEL_LAYER_ID].config)++ assert model_config.model_settings == {+ "temperature": 0.7,+ "extra_body": {"enable_thinking": True, "thinking_budget": 4096},+ }++@pytest.mark.parametrize("agent_config_version_kind", ["snapshot", "draft"])def test_agent_app_request_builder_keeps_agent_soul_prompt_for_snapshot_and_draft(agent_config_version_kind: str,diff --git a/api/tests/unit_tests/models/test_agent_config_entities.py b/api/tests/unit_tests/models/test_agent_config_entities.pyindex d95b7130f5c..70b98ea2f36 100644--- a/api/tests/unit_tests/models/test_agent_config_entities.py+++ b/api/tests/unit_tests/models/test_agent_config_entities.py@@ -2,6 +2,7 @@ import pytestfrom core.workflow.file_reference import build_file_referencefrom models.agent_config_entities import (+ AgentSoulModelSettings,DeclaredArrayItem,DeclaredOutputChildConfig,DeclaredOutputConfig,@@ -9,6 +10,22 @@ from models.agent_config_entities import ()+def test_agent_soul_model_settings_preserves_plugin_declared_parameters() -> None:+ settings = AgentSoulModelSettings.model_validate(+ {+ "temperature": 0.7,+ "enable_thinking": True,+ "thinking_budget": 4096,+ }+ )++ dumped = settings.model_dump(mode="json", exclude_none=True)++ assert dumped["temperature"] == 0.7+ assert dumped["enable_thinking"] is True+ assert dumped["thinking_budget"] == 4096++def test_file_default_value_accepts_canonical_reference_mapping() -> None:reference = build_file_reference(record_id="tool-file-1")diff --git a/packages/contracts/generated/api/console/agent/types.gen.ts b/packages/contracts/generated/api/console/agent/types.gen.tsindex fa33c2698b3..1a10436b734 100644--- a/packages/contracts/generated/api/console/agent/types.gen.ts+++ b/packages/contracts/generated/api/console/agent/types.gen.ts@@ -1586,6 +1586,7 @@ export type AgentSoulModelSettings = {stop?: Array<string> | nulltemperature?: number | nulltop_p?: number | null+ [key: string]: unknown}export type AgentSandboxProviderConfig = {diff --git a/packages/contracts/generated/api/console/agent/zod.gen.ts b/packages/contracts/generated/api/console/agent/zod.gen.tsindex 9b9c8878a2a..d3fc03ef81e 100644--- a/packages/contracts/generated/api/console/agent/zod.gen.ts+++ b/packages/contracts/generated/api/console/agent/zod.gen.ts@@ -2037,6 +2037,13 @@ export const zAgentModelResponseFormatConfig = z.object({/*** AgentSoulModelSettings+ *+ * Model parameters for the Agent Soul model.+ *+ * Model plugins can declare arbitrary parameters via ``parameter_rules``+ * (e.g. Qwen/Tongyi's ``enable_thinking``) beyond the common OpenAI-style+ * fields typed below, so extra keys must round-trip through persistence+ * rather than being dropped.*/export const zAgentSoulModelSettings = z.object({frequency_penalty: z.number().nullish(),diff --git a/packages/contracts/generated/api/console/apps/types.gen.ts b/packages/contracts/generated/api/console/apps/types.gen.tsindex 1c5202c86ee..7778a9d768a 100644--- a/packages/contracts/generated/api/console/apps/types.gen.ts+++ b/packages/contracts/generated/api/console/apps/types.gen.ts@@ -2846,6 +2846,7 @@ export type AgentSoulModelSettings = {stop?: Array<string> | nulltemperature?: number | nulltop_p?: number | null+ [key: string]: unknown}export type AgentSandboxProviderConfig = {diff --git a/packages/contracts/generated/api/console/apps/zod.gen.ts b/packages/contracts/generated/api/console/apps/zod.gen.tsindex 41ce64d22be..6fe308d4fd5 100644--- a/packages/contracts/generated/api/console/apps/zod.gen.ts+++ b/packages/contracts/generated/api/console/apps/zod.gen.ts@@ -3643,6 +3643,13 @@ export const zAgentModelResponseFormatConfig = z.object({/*** AgentSoulModelSettings+ *+ * Model parameters for the Agent Soul model.+ *+ * Model plugins can declare arbitrary parameters via ``parameter_rules``+ * (e.g. Qwen/Tongyi's ``enable_thinking``) beyond the common OpenAI-style+ * fields typed below, so extra keys must round-trip through persistence+ * rather than being dropped.*/export const zAgentSoulModelSettings = z.object({frequency_penalty: z.number().nullish(),diff --git a/packages/contracts/generated/api/console/snippets/types.gen.ts b/packages/contracts/generated/api/console/snippets/types.gen.tsindex 28b48d12ceb..a1731d32168 100644--- a/packages/contracts/generated/api/console/snippets/types.gen.ts+++ b/packages/contracts/generated/api/console/snippets/types.gen.ts@@ -924,6 +924,7 @@ export type AgentSoulModelSettings = {stop?: Array<string> | nulltemperature?: number | nulltop_p?: number | null+ [key: string]: unknown}export type AgentSandboxProviderConfig = {diff --git a/packages/contracts/generated/api/console/snippets/zod.gen.ts b/packages/contracts/generated/api/console/snippets/zod.gen.tsindex 31c5ee2e3d1..d58b3028350 100644--- a/packages/contracts/generated/api/console/snippets/zod.gen.ts+++ b/packages/contracts/generated/api/console/snippets/zod.gen.ts@@ -1155,6 +1155,13 @@ export const zAgentModelResponseFormatConfig = z.object({/*** AgentSoulModelSettings+ *+ * Model parameters for the Agent Soul model.+ *+ * Model plugins can declare arbitrary parameters via ``parameter_rules``+ * (e.g. Qwen/Tongyi's ``enable_thinking``) beyond the common OpenAI-style+ * fields typed below, so extra keys must round-trip through persistence+ * rather than being dropped.*/export const zAgentSoulModelSettings = z.object({frequency_penalty: z.number().nullish(),