fix: preserve template values in custom component updates (#5821)

* fix: preserve template values in custom component updates

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Ítalo Johnny 2025-01-20 22:28:13 -03:00 committed by GitHub
commit f34ba4cd95
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 4094 additions and 2984 deletions

View file

@ -720,6 +720,7 @@ async def custom_component_update(
user_id=user.id,
)
template_data = code_request.model_dump().get("template", {}).copy()
component_node["tool_mode"] = code_request.tool_mode
if hasattr(cc_instance, "set_attributes"):
@ -747,6 +748,13 @@ async def custom_component_update(
field_name=code_request.field,
)
component_node["template"] = updated_build_config
# Preserve previous field values by merging filtered template data into
# the component node's template. Only include entries where the value
# is a dictionary containing the key "value".
filtered_data = {k: v for k, v in template_data.items() if isinstance(v, dict) and "value" in v}
component_node["template"] |= filtered_data
if isinstance(cc_instance, Component):
await cc_instance.run_and_validate_update_outputs(
frontend_node=component_node,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,86 @@
{
"data": {
"edges": [
{
"animated": false,
"className": "",
"data": {
"sourceHandle": {
"dataType": "Agent",
"id": "Agent-LDhCf",
"name": "response",
"output_types": [
"Message"
]
},
"targetHandle": {
"fieldName": "input_value",
"id": "ChatOutput-YQ7Vi",
"inputTypes": [
"Message"
],
"type": "str"
}
},
"id": "reactflow__edge-Agent-LDhCf{œdataTypeœ:œAgentœ,œidœ:œAgent-LDhCfœ,œnameœ:œresponseœ,œoutput_typesœ:[œMessageœ]}-ChatOutput-YQ7Vi{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-YQ7Viœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
"source": "Agent-LDhCf",
"sourceHandle": "{œdataTypeœ: œAgentœ, œidœ: œAgent-LDhCfœ, œnameœ: œresponseœ, œoutput_typesœ: [œMessageœ]}",
"target": "ChatOutput-YQ7Vi",
"targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œChatOutput-YQ7Viœ, œinputTypesœ: [œMessageœ], œtypeœ: œstrœ}"
},
{
"animated": false,
"className": "",
"data": {
"sourceHandle": {
"dataType": "Prompt",
"id": "Prompt-Pe4nO",
"name": "prompt",
"output_types": [
"Message"
]
},
"targetHandle": {
"fieldName": "input_value",
"id": "Agent-LDhCf",
"inputTypes": [
"Message"
],
"type": "str"
}
},
"id": "reactflow__edge-Prompt-Pe4nO{œdataTypeœ:œPromptœ,œidœ:œPrompt-Pe4nOœ,œnameœ:œpromptœ,œoutput_typesœ:[œMessageœ]}-Agent-LDhCf{œfieldNameœ:œinput_valueœ,œidœ:œAgent-LDhCfœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
"source": "Prompt-Pe4nO",
"sourceHandle": "{œdataTypeœ: œPromptœ, œidœ: œPrompt-Pe4nOœ, œnameœ: œpromptœ, œoutput_typesœ: [œMessageœ]}",
"target": "Agent-LDhCf",
"targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œAgent-LDhCfœ, œinputTypesœ: [œMessageœ], œtypeœ: œstrœ}"
},
{
"data": {
"sourceHandle": {
"dataType": "CalculatorComponent",
"id": "CalculatorComponent-unDLj",
"name": "component_as_tool",
"output_types": [
"Tool"
]
},
"targetHandle": {
"fieldName": "tools",
"id": "Agent-LDhCf",
"inputTypes": [
"Tool"
],
"type": "other"
}
},
"id": "xy-edge__CalculatorComponent-unDLj{œdataTypeœ:œCalculatorComponentœ,œidœ:œCalculatorComponent-unDLjœ,œnameœ:œcomponent_as_toolœ,œoutput_typesœ:[œToolœ]}-Agent-LDhCf{œfieldNameœ:œtoolsœ,œidœ:œAgent-LDhCfœ,œinputTypesœ:[œToolœ],œtypeœ:œotherœ}",
"source": "CalculatorComponent-unDLj",
"sourceHandle": "{œdataTypeœ: œCalculatorComponentœ, œidœ: œCalculatorComponent-unDLjœ, œnameœ: œcomponent_as_toolœ, œoutput_typesœ: [œToolœ]}",
"target": "Agent-LDhCf",
"targetHandle": "{œfieldNameœ: œtoolsœ, œidœ: œAgent-LDhCfœ, œinputTypesœ: [œToolœ], œtypeœ: œotherœ}"
}
],
"nodes": [
{
"data": {
@ -7,7 +88,9 @@
"display_name": "Prompt",
"id": "Prompt-Pe4nO",
"node": {
"base_classes": ["Message"],
"base_classes": [
"Message"
],
"beta": false,
"conditional_paths": [],
"custom_fields": {
@ -23,7 +106,9 @@
"display_name": "Prompt",
"documentation": "",
"edited": false,
"field_order": ["template"],
"field_order": [
"template"
],
"frozen": false,
"icon": "prompts",
"legacy": false,
@ -37,7 +122,9 @@
"method": "build_prompt",
"name": "prompt",
"selected": "Message",
"types": ["Message"],
"types": [
"Message"
],
"value": "__UNDEFINED__"
}
],
@ -70,7 +157,10 @@
"fileTypes": [],
"file_path": "",
"info": "",
"input_types": ["Message", "Text"],
"input_types": [
"Message",
"Text"
],
"list": false,
"load_from_db": false,
"multiline": true,
@ -90,7 +180,10 @@
"fileTypes": [],
"file_path": "",
"info": "",
"input_types": ["Message", "Text"],
"input_types": [
"Message",
"Text"
],
"list": false,
"load_from_db": false,
"multiline": true,
@ -110,7 +203,10 @@
"fileTypes": [],
"file_path": "",
"info": "",
"input_types": ["Message", "Text"],
"input_types": [
"Message",
"Text"
],
"list": false,
"load_from_db": false,
"multiline": true,
@ -130,7 +226,10 @@
"fileTypes": [],
"file_path": "",
"info": "",
"input_types": ["Message", "Text"],
"input_types": [
"Message",
"Text"
],
"list": false,
"load_from_db": false,
"multiline": true,
@ -150,7 +249,10 @@
"fileTypes": [],
"file_path": "",
"info": "",
"input_types": ["Message", "Text"],
"input_types": [
"Message",
"Text"
],
"list": false,
"load_from_db": false,
"multiline": true,
@ -186,7 +288,9 @@
"display_name": "Tool Placeholder",
"dynamic": false,
"info": "A placeholder input for tool mode.",
"input_types": ["Message"],
"input_types": [
"Message"
],
"list": false,
"load_from_db": false,
"name": "tool_placeholder",
@ -230,7 +334,9 @@
"display_name": "Chat Output",
"id": "ChatOutput-YQ7Vi",
"node": {
"base_classes": ["Message"],
"base_classes": [
"Message"
],
"beta": false,
"conditional_paths": [],
"custom_fields": {},
@ -262,7 +368,9 @@
"method": "message_response",
"name": "message",
"selected": "Message",
"types": ["Message"],
"types": [
"Message"
],
"value": "__UNDEFINED__"
}
],
@ -275,7 +383,9 @@
"display_name": "Background Color",
"dynamic": false,
"info": "The background color of the icon.",
"input_types": ["Message"],
"input_types": [
"Message"
],
"list": false,
"load_from_db": false,
"name": "background_color",
@ -295,7 +405,9 @@
"display_name": "Icon",
"dynamic": false,
"info": "The icon of the message.",
"input_types": ["Message"],
"input_types": [
"Message"
],
"list": false,
"load_from_db": false,
"name": "chat_icon",
@ -333,7 +445,9 @@
"display_name": "Data Template",
"dynamic": false,
"info": "Template to convert Data to Text. If left empty, it will be dynamically set to the Data's text key.",
"input_types": ["Message"],
"input_types": [
"Message"
],
"list": false,
"load_from_db": false,
"name": "data_template",
@ -353,7 +467,9 @@
"display_name": "Text",
"dynamic": false,
"info": "Message to be passed as output.",
"input_types": ["Message"],
"input_types": [
"Message"
],
"list": false,
"load_from_db": false,
"name": "input_value",
@ -374,7 +490,10 @@
"dynamic": false,
"info": "Type of sender.",
"name": "sender",
"options": ["Machine", "User"],
"options": [
"Machine",
"User"
],
"placeholder": "",
"required": false,
"show": true,
@ -390,7 +509,9 @@
"display_name": "Sender Name",
"dynamic": false,
"info": "Name of the sender.",
"input_types": ["Message"],
"input_types": [
"Message"
],
"list": false,
"load_from_db": false,
"name": "sender_name",
@ -410,7 +531,9 @@
"display_name": "Session ID",
"dynamic": false,
"info": "The session ID of the chat. If empty, the current session ID parameter will be used.",
"input_types": ["Message"],
"input_types": [
"Message"
],
"list": false,
"load_from_db": false,
"name": "session_id",
@ -446,7 +569,9 @@
"display_name": "Text Color",
"dynamic": false,
"info": "The text color of the name",
"input_types": ["Message"],
"input_types": [
"Message"
],
"list": false,
"load_from_db": false,
"name": "text_color",
@ -525,7 +650,9 @@
"display_name": "Agent",
"id": "Agent-LDhCf",
"node": {
"base_classes": ["Message"],
"base_classes": [
"Message"
],
"beta": false,
"conditional_paths": [],
"custom_fields": {},
@ -574,7 +701,9 @@
"method": "message_response",
"name": "response",
"selected": "Message",
"types": ["Message"],
"types": [
"Message"
],
"value": "__UNDEFINED__"
}
],
@ -603,7 +732,9 @@
"display_name": "Agent Description [Deprecated]",
"dynamic": false,
"info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically. This feature is deprecated and will be removed in future versions.",
"input_types": ["Message"],
"input_types": [
"Message"
],
"list": false,
"load_from_db": false,
"multiline": true,
@ -652,7 +783,9 @@
"display_name": "OpenAI API Key",
"dynamic": false,
"info": "The OpenAI API Key to use for the OpenAI model.",
"input_types": ["Message"],
"input_types": [
"Message"
],
"load_from_db": false,
"name": "api_key",
"password": true,
@ -703,7 +836,9 @@
"display_name": "Input",
"dynamic": false,
"info": "The input provided by the user for the agent to process.",
"input_types": ["Message"],
"input_types": [
"Message"
],
"list": false,
"load_from_db": false,
"name": "input_value",
@ -777,7 +912,9 @@
"display_name": "External Memory",
"dynamic": false,
"info": "Retrieve messages from an external memory. If empty, it will use the Langflow tables.",
"input_types": ["Memory"],
"input_types": [
"Memory"
],
"list": false,
"name": "memory",
"placeholder": "",
@ -871,7 +1008,10 @@
"dynamic": false,
"info": "Order of the messages.",
"name": "order",
"options": ["Ascending", "Descending"],
"options": [
"Ascending",
"Descending"
],
"placeholder": "",
"required": false,
"show": true,
@ -905,7 +1045,11 @@
"dynamic": false,
"info": "Filter by sender type.",
"name": "sender",
"options": ["Machine", "User", "Machine and User"],
"options": [
"Machine",
"User",
"Machine and User"
],
"placeholder": "",
"required": false,
"show": true,
@ -921,7 +1065,9 @@
"display_name": "Sender Name",
"dynamic": false,
"info": "Filter by sender name.",
"input_types": ["Message"],
"input_types": [
"Message"
],
"list": false,
"load_from_db": false,
"name": "sender_name",
@ -941,7 +1087,9 @@
"display_name": "Session ID",
"dynamic": false,
"info": "The session ID of the chat. If empty, the current session ID parameter will be used.",
"input_types": ["Message"],
"input_types": [
"Message"
],
"list": false,
"load_from_db": false,
"name": "session_id",
@ -961,7 +1109,9 @@
"display_name": "Agent Instructions",
"dynamic": false,
"info": "System Prompt: Initial instructions and context provided to guide the agent's behavior.",
"input_types": ["Message"],
"input_types": [
"Message"
],
"list": false,
"load_from_db": false,
"multiline": true,
@ -998,7 +1148,9 @@
"display_name": "Template",
"dynamic": false,
"info": "The template to use for formatting the data. It can contain the keys {text}, {sender} or any other key in the message data.",
"input_types": ["Message"],
"input_types": [
"Message"
],
"list": false,
"load_from_db": false,
"multiline": true,
@ -1019,7 +1171,9 @@
"display_name": "Tools",
"dynamic": false,
"info": "These are the tools that the agent can use to help with tasks.",
"input_types": ["Tool"],
"input_types": [
"Tool"
],
"list": true,
"name": "tools",
"placeholder": "",
@ -1074,7 +1228,9 @@
"data": {
"id": "CalculatorComponent-unDLj",
"node": {
"base_classes": ["Data"],
"base_classes": [
"Data"
],
"beta": false,
"category": "tools",
"conditional_paths": [],
@ -1083,7 +1239,9 @@
"display_name": "Calculator",
"documentation": "",
"edited": false,
"field_order": ["expression"],
"field_order": [
"expression"
],
"frozen": false,
"icon": "calculator",
"key": "CalculatorComponent",
@ -1093,15 +1251,17 @@
"output_types": [],
"outputs": [
{
"types": ["Tool"],
"selected": "Tool",
"name": "component_as_tool",
"hidden": null,
"display_name": "Toolset",
"method": "to_toolkit",
"value": "__UNDEFINED__",
"cache": true,
"required_inputs": null
"display_name": "Toolset",
"hidden": null,
"method": "to_toolkit",
"name": "component_as_tool",
"required_inputs": null,
"selected": "Tool",
"types": [
"Tool"
],
"value": "__UNDEFINED__"
}
],
"pinned": false,
@ -1132,7 +1292,9 @@
"display_name": "Expression",
"dynamic": false,
"info": "The arithmetic expression to evaluate (e.g., '4*4*(33/22)+12-20').",
"input_types": ["Message"],
"input_types": [
"Message"
],
"list": false,
"list_add_label": "Add More",
"load_from_db": false,
@ -1148,84 +1310,89 @@
"value": ""
},
"tools_metadata": {
"tool_mode": false,
"_input_type": "TableInput",
"advanced": false,
"display_name": "Edit tools",
"dynamic": false,
"info": "",
"is_list": true,
"list_add_label": "Add More",
"table_schema": {
"columns": [
{
"name": "name",
"display_name": "Tool Name",
"sortable": false,
"filterable": false,
"type": "text",
"description": "Specify the name of the tool.",
"disable_edit": false,
"edit_mode": "inline",
"formatter": "text"
},
{
"name": "description",
"display_name": "Tool Description",
"sortable": false,
"filterable": false,
"type": "text",
"description": "Describe the purpose of the tool.",
"disable_edit": false,
"edit_mode": "popover",
"formatter": "text"
},
{
"name": "tags",
"display_name": "Tool Identifiers",
"sortable": false,
"filterable": false,
"type": "text",
"description": "The default identifiers for the tools and cannot be changed.",
"disable_edit": true,
"edit_mode": "inline",
"formatter": "text"
}
]
},
"trigger_text": "",
"trigger_icon": "Hammer",
"name": "tools_metadata",
"placeholder": "",
"real_time_refresh": true,
"required": false,
"show": true,
"table_icon": "Hammer",
"table_options": {
"block_add": true,
"block_delete": true,
"block_edit": true,
"block_sort": true,
"block_filter": true,
"block_hide": true,
"block_select": true,
"hide_options": true,
"block_sort": true,
"description": "Modify tool names and descriptions to help agents understand when to use each tool.",
"field_parsers": {
"name": ["snake_case", "no_blank"],
"commands": "commands"
"commands": "commands",
"name": [
"snake_case",
"no_blank"
]
},
"description": "Modify tool names and descriptions to help agents understand when to use each tool."
"hide_options": true
},
"table_schema": {
"columns": [
{
"description": "Specify the name of the tool.",
"disable_edit": false,
"display_name": "Tool Name",
"edit_mode": "inline",
"filterable": false,
"formatter": "text",
"name": "name",
"sortable": false,
"type": "text"
},
{
"description": "Describe the purpose of the tool.",
"disable_edit": false,
"display_name": "Tool Description",
"edit_mode": "popover",
"filterable": false,
"formatter": "text",
"name": "description",
"sortable": false,
"type": "text"
},
{
"description": "The default identifiers for the tools and cannot be changed.",
"disable_edit": true,
"display_name": "Tool Identifiers",
"edit_mode": "inline",
"filterable": false,
"formatter": "text",
"name": "tags",
"sortable": false,
"type": "text"
}
]
},
"title_case": false,
"tool_mode": false,
"trace_as_metadata": true,
"required": false,
"placeholder": "",
"show": true,
"name": "tools_metadata",
"trigger_icon": "Hammer",
"trigger_text": "",
"type": "table",
"value": [
{
"description": "evaluate_expression() - Perform basic arithmetic operations on a given expression.",
"name": "None-evaluate_expression",
"tags": ["None-evaluate_expression"]
"tags": [
"None-evaluate_expression"
]
}
],
"display_name": "Edit tools",
"advanced": false,
"dynamic": false,
"info": "",
"real_time_refresh": true,
"title_case": false,
"type": "table",
"_input_type": "TableInput"
]
}
},
"tool_mode": true
@ -1247,75 +1414,6 @@
"type": "genericNode"
}
],
"edges": [
{
"animated": false,
"className": "",
"data": {
"sourceHandle": {
"dataType": "Agent",
"id": "Agent-LDhCf",
"name": "response",
"output_types": ["Message"]
},
"targetHandle": {
"fieldName": "input_value",
"id": "ChatOutput-YQ7Vi",
"inputTypes": ["Message"],
"type": "str"
}
},
"id": "reactflow__edge-Agent-LDhCf{œdataTypeœ:œAgentœ,œidœ:œAgent-LDhCfœ,œnameœ:œresponseœ,œoutput_typesœ:[œMessageœ]}-ChatOutput-YQ7Vi{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-YQ7Viœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
"source": "Agent-LDhCf",
"sourceHandle": "{œdataTypeœ:œAgentœ,œidœ:œAgent-LDhCfœ,œnameœ:œresponseœ,œoutput_typesœ:[œMessageœ]}",
"target": "ChatOutput-YQ7Vi",
"targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-YQ7Viœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}"
},
{
"animated": false,
"className": "",
"data": {
"sourceHandle": {
"dataType": "Prompt",
"id": "Prompt-Pe4nO",
"name": "prompt",
"output_types": ["Message"]
},
"targetHandle": {
"fieldName": "input_value",
"id": "Agent-LDhCf",
"inputTypes": ["Message"],
"type": "str"
}
},
"id": "reactflow__edge-Prompt-Pe4nO{œdataTypeœ:œPromptœ,œidœ:œPrompt-Pe4nOœ,œnameœ:œpromptœ,œoutput_typesœ:[œMessageœ]}-Agent-LDhCf{œfieldNameœ:œinput_valueœ,œidœ:œAgent-LDhCfœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
"source": "Prompt-Pe4nO",
"sourceHandle": "{œdataTypeœ:œPromptœ,œidœ:œPrompt-Pe4nOœ,œnameœ:œpromptœ,œoutput_typesœ:[œMessageœ]}",
"target": "Agent-LDhCf",
"targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œAgent-LDhCfœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}"
},
{
"source": "CalculatorComponent-unDLj",
"sourceHandle": "{œdataTypeœ:œCalculatorComponentœ,œidœ:œCalculatorComponent-unDLjœ,œnameœ:œcomponent_as_toolœ,œoutput_typesœ:[œToolœ]}",
"target": "Agent-LDhCf",
"targetHandle": "{œfieldNameœ:œtoolsœ,œidœ:œAgent-LDhCfœ,œinputTypesœ:[œToolœ],œtypeœ:œotherœ}",
"data": {
"targetHandle": {
"fieldName": "tools",
"id": "Agent-LDhCf",
"inputTypes": ["Tool"],
"type": "other"
},
"sourceHandle": {
"dataType": "CalculatorComponent",
"id": "CalculatorComponent-unDLj",
"name": "component_as_tool",
"output_types": ["Tool"]
}
},
"id": "xy-edge__CalculatorComponent-unDLj{œdataTypeœ:œCalculatorComponentœ,œidœ:œCalculatorComponent-unDLjœ,œnameœ:œcomponent_as_toolœ,œoutput_typesœ:[œToolœ]}-Agent-LDhCf{œfieldNameœ:œtoolsœ,œidœ:œAgent-LDhCfœ,œinputTypesœ:[œToolœ],œtypeœ:œotherœ}"
}
],
"viewport": {
"x": -412.6248764419154,
"y": 239.5139629945674,
@ -1330,5 +1428,8 @@
"is_component": false,
"last_tested_version": "1.1.1",
"name": "SaaS Pricing",
"tags": ["agents", "assistants"]
}
"tags": [
"agents",
"assistants"
]
}

File diff suppressed because one or more lines are too long