[PR #30929] feat: configurable extra model parameters with env & node variable support #33018

Closed
opened 2026-02-21 20:52:30 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/30929

State: closed
Merged: No


Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Fixes #30172

Summary

This PR implements a more flexible solution for customizing model requests compared to the original "Headers field in LLM node" proposal.
Instead of adding a dedicated Headers field in the LLM node as mentioned in #30172, this change enables extra model parameters to be defined in the model's YAML configuration file (e.g., extra_headers) and referenced from other node variables or environment variables.

Key changes:

  1. Frontend

    • Updated configuration UI for four node types: LLM node, Question Classifier node, Variable Extractor node, and Agent node.
    • Allow string-type parameters to reference other node variables or Agent environment variables.
    • Pass the resolved parameters to the dify-api backend and then pass parameters to model plugins
  2. Backend

    • Parse and resolve variables from node references or environment variables.
    • Pass the actual resolved values to model plugins.
  3. Model Plugin

    • Allow custom parameters defined in the model YAML (e.g., extra_headers) to control model behavior.
  4. Testing

    • Added Python unit tests for backend variable resolution logic.
    • Verified Docker startup and ensured all four node types can pass extra parameters through to the plugin.
    • Debug logs confirm parameters are correctly delivered to model plugins.

Compatibility:

  • Default behavior remains unchanged if extra parameters are not defined or enabled.
  • Models without extra settings behave exactly as before.
  • When enabled and defined in YAML, extra parameters such as extra_headers can integrate seamlessly with existing node/environment variable references.

This approach improves extensibility and enables integration with API providers like Alibaba Bailian that require specific headers or custom parameters. see Alibaba Bailian API , Some customized headers need to refer variables of inputs.

Screenshots

Before

Model Parameters can not reference variables and environment variables
image

After

All of string model parameters of Nodes related to model plugins(such as LLM node, Parameter Extractor, Agent, Question classifier) could reference variables and environment variables.

LLM node

image

Question Classifier

image

Parameter Extractor with extra parameters

image

Parameter Extractor without extra paremeters

image

And of course the model plugins could read the correct values of model parameter referred to node variables or environment variables.

print model paramters referred to environmental variable

image

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/30929 **State:** closed **Merged:** No --- > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 1. Ensure there is an associated issue and you have been assigned to it > 1. Use the correct syntax to link this PR: `Fixes #<issue number>`. Fixes #30172 ## Summary <!-- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. --> This PR implements a more flexible solution for customizing model requests compared to the original "Headers field in LLM node" proposal. Instead of adding a dedicated `Headers` field in the LLM node as mentioned in #30172, this change enables **extra model parameters** to be defined in the model's YAML configuration file (e.g., `extra_headers`) and referenced from other node variables or environment variables. **Key changes:** 1. **Frontend** - Updated configuration UI for four node types: LLM node, Question Classifier node, Variable Extractor node, and Agent node. - Allow string-type parameters to reference other node variables or Agent environment variables. - Pass the resolved parameters to the dify-api backend and then pass parameters to model plugins 2. **Backend** - Parse and resolve variables from node references or environment variables. - Pass the actual resolved values to model plugins. 3. **Model Plugin** - Allow custom parameters defined in the model YAML (e.g., `extra_headers`) to control model behavior. 4. **Testing** - Added Python unit tests for backend variable resolution logic. - Verified Docker startup and ensured all four node types can pass extra parameters through to the plugin. - Debug logs confirm parameters are correctly delivered to model plugins. **Compatibility:** - Default behavior remains unchanged if extra parameters are not defined or enabled. - Models without extra settings behave exactly as before. - When enabled and defined in YAML, extra parameters such as `extra_headers` can integrate seamlessly with existing node/environment variable references. This approach improves **extensibility** and enables integration with API providers like Alibaba Bailian that require specific headers or custom parameters. see [Alibaba Bailian API](https://bailian.console.aliyun.com/?utm_content=se_1021228007&gclid=CjwKCAiA9aPKBhBhEiwAyz82J6pnn96iZzUWYwP3at5yDSIT50a7asy3xE9D3tL1wrv9jEZaJScQARoC6KcQAvD_BwE&tab=api#/api/?type=model&url=2712576) , Some customized headers need to refer variables of inputs. ## Screenshots ### Before Model Parameters can not reference variables and environment variables <img width="1552" height="904" alt="image" src="https://github.com/user-attachments/assets/ec215a3c-7ebf-4f49-ad02-54159c99b99b" /> ### After All of string model parameters of Nodes related to model plugins(such as LLM node, Parameter Extractor, Agent, Question classifier) could reference variables and environment variables. #### LLM node <img width="2382" height="1186" alt="image" src="https://github.com/user-attachments/assets/21212eae-a014-4ad7-9e23-c87104e90f0f" /> #### Question Classifier <img width="1566" height="1024" alt="image" src="https://github.com/user-attachments/assets/9ed096d8-04a6-4b61-8d23-b7316cb224ca" /> #### Parameter Extractor with extra parameters <img width="1584" height="1160" alt="image" src="https://github.com/user-attachments/assets/d95b48df-cc96-467d-a947-8f9a3a9aa6a1" /> #### Parameter Extractor without extra paremeters <img width="1586" height="960" alt="image" src="https://github.com/user-attachments/assets/a6382332-53fa-47ef-9d78-8c79b78d7dfe" /> And of course the model plugins could read the correct values of model parameter referred to node variables or environment variables. #### print model paramters referred to environmental variable <img width="2766" height="178" alt="image" src="https://github.com/user-attachments/assets/d9bbcba3-49be-47b0-b466-1f9036219d98" /> ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `make lint` and `make type-check` (backend) and `cd web && npx lint-staged` (frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:52:30 -05:00
yindo closed this issue 2026-02-21 20:52:30 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#33018