Created
August 27, 2025 03:43
-
-
Save andysign/c84945144d35c40f4a0c6fb943f6463a to your computer and use it in GitHub Desktop.
Simple-Ollama-Agent.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "data": { | |
| "edges": [ | |
| { | |
| "animated": false, | |
| "className": "", | |
| "data": { | |
| "sourceHandle": { | |
| "dataType": "Agent", | |
| "id": "Agent-HN65G", | |
| "name": "response", | |
| "output_types": [ | |
| "Message" | |
| ] | |
| }, | |
| "targetHandle": { | |
| "fieldName": "input_value", | |
| "id": "ChatOutput-4w4oZ", | |
| "inputTypes": [ | |
| "Data", | |
| "DataFrame", | |
| "Message" | |
| ], | |
| "type": "other" | |
| } | |
| }, | |
| "id": "reactflow__edge-Agent-HN65G{œdataTypeœ:œAgentœ,œidœ:œAgent-HN65Gœ,œnameœ:œresponseœ,œoutput_typesœ:[œMessageœ]}-ChatOutput-4w4oZ{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-4w4oZœ,œinputTypesœ:[œDataœ,œDataFrameœ,œMessageœ],œtypeœ:œotherœ}", | |
| "selected": false, | |
| "source": "Agent-HN65G", | |
| "sourceHandle": "{œdataTypeœ:œAgentœ,œidœ:œAgent-HN65Gœ,œnameœ:œresponseœ,œoutput_typesœ:[œMessageœ]}", | |
| "target": "ChatOutput-4w4oZ", | |
| "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-4w4oZœ,œinputTypesœ:[œDataœ,œDataFrameœ,œMessageœ],œtypeœ:œotherœ}" | |
| }, | |
| { | |
| "animated": false, | |
| "className": "", | |
| "data": { | |
| "sourceHandle": { | |
| "dataType": "CalculatorComponent", | |
| "id": "CalculatorComponent-vqUo8", | |
| "name": "component_as_tool", | |
| "output_types": [ | |
| "Tool" | |
| ] | |
| }, | |
| "targetHandle": { | |
| "fieldName": "tools", | |
| "id": "Agent-HN65G", | |
| "inputTypes": [ | |
| "Tool" | |
| ], | |
| "type": "other" | |
| } | |
| }, | |
| "id": "reactflow__edge-CalculatorComponent-vqUo8{œdataTypeœ:œCalculatorComponentœ,œidœ:œCalculatorComponent-vqUo8œ,œnameœ:œcomponent_as_toolœ,œoutput_typesœ:[œToolœ]}-Agent-HN65G{œfieldNameœ:œtoolsœ,œidœ:œAgent-HN65Gœ,œinputTypesœ:[œToolœ],œtypeœ:œotherœ}", | |
| "selected": false, | |
| "source": "CalculatorComponent-vqUo8", | |
| "sourceHandle": "{œdataTypeœ:œCalculatorComponentœ,œidœ:œCalculatorComponent-vqUo8œ,œnameœ:œcomponent_as_toolœ,œoutput_typesœ:[œToolœ]}", | |
| "target": "Agent-HN65G", | |
| "targetHandle": "{œfieldNameœ:œtoolsœ,œidœ:œAgent-HN65Gœ,œinputTypesœ:[œToolœ],œtypeœ:œotherœ}" | |
| }, | |
| { | |
| "animated": false, | |
| "className": "", | |
| "data": { | |
| "sourceHandle": { | |
| "dataType": "ChatInput", | |
| "id": "ChatInput-GpvuR", | |
| "name": "message", | |
| "output_types": [ | |
| "Message" | |
| ] | |
| }, | |
| "targetHandle": { | |
| "fieldName": "input_value", | |
| "id": "OllamaModel-prrNR", | |
| "inputTypes": [ | |
| "Message" | |
| ], | |
| "type": "str" | |
| } | |
| }, | |
| "id": "xy-edge__ChatInput-GpvuR{œdataTypeœ:œChatInputœ,œidœ:œChatInput-GpvuRœ,œnameœ:œmessageœ,œoutput_typesœ:[œMessageœ]}-OllamaModel-prrNR{œfieldNameœ:œinput_valueœ,œidœ:œOllamaModel-prrNRœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}", | |
| "selected": false, | |
| "source": "ChatInput-GpvuR", | |
| "sourceHandle": "{œdataTypeœ:œChatInputœ,œidœ:œChatInput-GpvuRœ,œnameœ:œmessageœ,œoutput_typesœ:[œMessageœ]}", | |
| "target": "OllamaModel-prrNR", | |
| "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œOllamaModel-prrNRœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}" | |
| }, | |
| { | |
| "animated": false, | |
| "className": "", | |
| "data": { | |
| "sourceHandle": { | |
| "dataType": "OllamaModel", | |
| "id": "OllamaModel-prrNR", | |
| "name": "model_output", | |
| "output_types": [ | |
| "LanguageModel" | |
| ] | |
| }, | |
| "targetHandle": { | |
| "fieldName": "agent_llm", | |
| "id": "Agent-HN65G", | |
| "inputTypes": [ | |
| "LanguageModel" | |
| ], | |
| "type": "str" | |
| } | |
| }, | |
| "id": "xy-edge__OllamaModel-prrNR{œdataTypeœ:œOllamaModelœ,œidœ:œOllamaModel-prrNRœ,œnameœ:œmodel_outputœ,œoutput_typesœ:[œLanguageModelœ]}-Agent-HN65G{œfieldNameœ:œagent_llmœ,œidœ:œAgent-HN65Gœ,œinputTypesœ:[œLanguageModelœ],œtypeœ:œstrœ}", | |
| "selected": false, | |
| "source": "OllamaModel-prrNR", | |
| "sourceHandle": "{œdataTypeœ:œOllamaModelœ,œidœ:œOllamaModel-prrNRœ,œnameœ:œmodel_outputœ,œoutput_typesœ:[œLanguageModelœ]}", | |
| "target": "Agent-HN65G", | |
| "targetHandle": "{œfieldNameœ:œagent_llmœ,œidœ:œAgent-HN65Gœ,œinputTypesœ:[œLanguageModelœ],œtypeœ:œstrœ}" | |
| } | |
| ], | |
| "nodes": [ | |
| { | |
| "data": { | |
| "id": "CalculatorComponent-vqUo8", | |
| "node": { | |
| "base_classes": [ | |
| "Data" | |
| ], | |
| "beta": false, | |
| "category": "tools", | |
| "conditional_paths": [], | |
| "custom_fields": {}, | |
| "description": "Perform basic arithmetic operations on a given expression.", | |
| "display_name": "Calculator", | |
| "documentation": "", | |
| "edited": false, | |
| "field_order": [ | |
| "expression" | |
| ], | |
| "frozen": false, | |
| "icon": "calculator", | |
| "key": "CalculatorComponent", | |
| "last_updated": "2025-08-26T21:10:55.194Z", | |
| "legacy": false, | |
| "lf_version": "1.5.0", | |
| "metadata": {}, | |
| "minimized": false, | |
| "output_types": [], | |
| "outputs": [ | |
| { | |
| "allows_loop": false, | |
| "cache": true, | |
| "display_name": "Toolset", | |
| "group_outputs": false, | |
| "hidden": false, | |
| "method": "to_toolkit", | |
| "name": "component_as_tool", | |
| "options": null, | |
| "required_inputs": null, | |
| "selected": "Tool", | |
| "tool_mode": true, | |
| "types": [ | |
| "Tool" | |
| ], | |
| "value": "__UNDEFINED__" | |
| } | |
| ], | |
| "pinned": false, | |
| "score": 0.001, | |
| "template": { | |
| "_type": "Component", | |
| "code": { | |
| "advanced": true, | |
| "dynamic": true, | |
| "fileTypes": [], | |
| "file_path": "", | |
| "info": "", | |
| "list": false, | |
| "load_from_db": false, | |
| "multiline": true, | |
| "name": "code", | |
| "password": false, | |
| "placeholder": "", | |
| "required": true, | |
| "show": true, | |
| "title_case": false, | |
| "type": "code", | |
| "value": "import ast\nimport operator\nfrom collections.abc import Callable\n\nfrom langflow.custom.custom_component.component import Component\nfrom langflow.inputs.inputs import MessageTextInput\nfrom langflow.io import Output\nfrom langflow.schema.data import Data\n\n\nclass CalculatorComponent(Component):\n display_name = \"Calculator\"\n description = \"Perform basic arithmetic operations on a given expression.\"\n documentation: str = \"https://docs.langflow.org/components-helpers#calculator\"\n icon = \"calculator\"\n\n # Cache operators dictionary as a class variable\n OPERATORS: dict[type[ast.operator], Callable] = {\n ast.Add: operator.add,\n ast.Sub: operator.sub,\n ast.Mult: operator.mul,\n ast.Div: operator.truediv,\n ast.Pow: operator.pow,\n }\n\n inputs = [\n MessageTextInput(\n name=\"expression\",\n display_name=\"Expression\",\n info=\"The arithmetic expression to evaluate (e.g., '4*4*(33/22)+12-20').\",\n tool_mode=True,\n ),\n ]\n\n outputs = [\n Output(display_name=\"Data\", name=\"result\", type_=Data, method=\"evaluate_expression\"),\n ]\n\n def _eval_expr(self, node: ast.AST) -> float:\n \"\"\"Evaluate an AST node recursively.\"\"\"\n if isinstance(node, ast.Constant):\n if isinstance(node.value, int | float):\n return float(node.value)\n error_msg = f\"Unsupported constant type: {type(node.value).__name__}\"\n raise TypeError(error_msg)\n if isinstance(node, ast.Num): # For backwards compatibility\n if isinstance(node.n, int | float):\n return float(node.n)\n error_msg = f\"Unsupported number type: {type(node.n).__name__}\"\n raise TypeError(error_msg)\n\n if isinstance(node, ast.BinOp):\n op_type = type(node.op)\n if op_type not in self.OPERATORS:\n error_msg = f\"Unsupported binary operator: {op_type.__name__}\"\n raise TypeError(error_msg)\n\n left = self._eval_expr(node.left)\n right = self._eval_expr(node.right)\n return self.OPERATORS[op_type](left, right)\n\n error_msg = f\"Unsupported operation or expression type: {type(node).__name__}\"\n raise TypeError(error_msg)\n\n def evaluate_expression(self) -> Data:\n \"\"\"Evaluate the mathematical expression and return the result.\"\"\"\n try:\n tree = ast.parse(self.expression, mode=\"eval\")\n result = self._eval_expr(tree.body)\n\n formatted_result = f\"{float(result):.6f}\".rstrip(\"0\").rstrip(\".\")\n self.log(f\"Calculation result: {formatted_result}\")\n\n self.status = formatted_result\n return Data(data={\"result\": formatted_result})\n\n except ZeroDivisionError:\n error_message = \"Error: Division by zero\"\n self.status = error_message\n return Data(data={\"error\": error_message, \"input\": self.expression})\n\n except (SyntaxError, TypeError, KeyError, ValueError, AttributeError, OverflowError) as e:\n error_message = f\"Invalid expression: {e!s}\"\n self.status = error_message\n return Data(data={\"error\": error_message, \"input\": self.expression})\n\n def build(self):\n \"\"\"Return the main evaluation function.\"\"\"\n return self.evaluate_expression\n" | |
| }, | |
| "expression": { | |
| "_input_type": "MessageTextInput", | |
| "advanced": false, | |
| "display_name": "Expression", | |
| "dynamic": false, | |
| "info": "The arithmetic expression to evaluate (e.g., '4*4*(33/22)+12-20').", | |
| "input_types": [ | |
| "Message" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "name": "expression", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": true, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "" | |
| }, | |
| "tools_metadata": { | |
| "_input_type": "ToolsInput", | |
| "advanced": false, | |
| "display_name": "Actions", | |
| "dynamic": false, | |
| "info": "Modify tool names and descriptions to help agents understand when to use each tool.", | |
| "is_list": true, | |
| "list_add_label": "Add More", | |
| "name": "tools_metadata", | |
| "placeholder": "", | |
| "real_time_refresh": true, | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "tools", | |
| "value": [ | |
| { | |
| "args": { | |
| "expression": { | |
| "default": "", | |
| "description": "The arithmetic expression to evaluate (e.g., '4*4*(33/22)+12-20').", | |
| "title": "Expression", | |
| "type": "string" | |
| } | |
| }, | |
| "description": "CalculatorComponent. evaluate_expression() - Perform basic arithmetic operations on a given expression.", | |
| "display_description": "CalculatorComponent. evaluate_expression() - Perform basic arithmetic operations on a given expression.", | |
| "display_name": "evaluate_expression", | |
| "name": "evaluate_expression", | |
| "status": true, | |
| "tags": [ | |
| "evaluate_expression" | |
| ] | |
| } | |
| ] | |
| } | |
| }, | |
| "tool_mode": true | |
| }, | |
| "selected_output": "component_as_tool", | |
| "showNode": false, | |
| "type": "CalculatorComponent" | |
| }, | |
| "dragging": false, | |
| "id": "CalculatorComponent-vqUo8", | |
| "measured": { | |
| "height": 48, | |
| "width": 192 | |
| }, | |
| "position": { | |
| "x": 1398.3963532345767, | |
| "y": 786.036373186948 | |
| }, | |
| "selected": false, | |
| "type": "genericNode" | |
| }, | |
| { | |
| "data": { | |
| "id": "ChatOutput-4w4oZ", | |
| "node": { | |
| "base_classes": [ | |
| "Message" | |
| ], | |
| "beta": false, | |
| "category": "outputs", | |
| "conditional_paths": [], | |
| "custom_fields": {}, | |
| "description": "Display a chat message in the Playground.", | |
| "display_name": "Chat Output", | |
| "documentation": "", | |
| "edited": false, | |
| "field_order": [ | |
| "input_value", | |
| "should_store_message", | |
| "sender", | |
| "sender_name", | |
| "session_id", | |
| "data_template", | |
| "background_color", | |
| "chat_icon", | |
| "text_color", | |
| "clean_data" | |
| ], | |
| "frozen": false, | |
| "icon": "MessagesSquare", | |
| "key": "ChatOutput", | |
| "legacy": false, | |
| "lf_version": "1.5.0", | |
| "metadata": {}, | |
| "minimized": true, | |
| "output_types": [], | |
| "outputs": [ | |
| { | |
| "allows_loop": false, | |
| "cache": true, | |
| "display_name": "Output Message", | |
| "group_outputs": false, | |
| "method": "message_response", | |
| "name": "message", | |
| "selected": "Message", | |
| "tool_mode": true, | |
| "types": [ | |
| "Message" | |
| ], | |
| "value": "__UNDEFINED__" | |
| } | |
| ], | |
| "pinned": false, | |
| "score": 0.003169567463043492, | |
| "template": { | |
| "_type": "Component", | |
| "background_color": { | |
| "_input_type": "MessageTextInput", | |
| "advanced": true, | |
| "display_name": "Background Color", | |
| "dynamic": false, | |
| "info": "The background color of the icon.", | |
| "input_types": [ | |
| "Message" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "name": "background_color", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "" | |
| }, | |
| "chat_icon": { | |
| "_input_type": "MessageTextInput", | |
| "advanced": true, | |
| "display_name": "Icon", | |
| "dynamic": false, | |
| "info": "The icon of the message.", | |
| "input_types": [ | |
| "Message" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "name": "chat_icon", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "" | |
| }, | |
| "clean_data": { | |
| "_input_type": "BoolInput", | |
| "advanced": true, | |
| "display_name": "Basic Clean Data", | |
| "dynamic": false, | |
| "info": "Whether to clean the data", | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "clean_data", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "bool", | |
| "value": true | |
| }, | |
| "code": { | |
| "advanced": true, | |
| "dynamic": true, | |
| "fileTypes": [], | |
| "file_path": "", | |
| "info": "", | |
| "list": false, | |
| "load_from_db": false, | |
| "multiline": true, | |
| "name": "code", | |
| "password": false, | |
| "placeholder": "", | |
| "required": true, | |
| "show": true, | |
| "title_case": false, | |
| "type": "code", | |
| "value": "from collections.abc import Generator\nfrom typing import Any\n\nimport orjson\nfrom fastapi.encoders import jsonable_encoder\n\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.helpers.data import safe_convert\nfrom langflow.inputs.inputs import BoolInput, DropdownInput, HandleInput, MessageTextInput\nfrom langflow.schema.data import Data\nfrom langflow.schema.dataframe import DataFrame\nfrom langflow.schema.message import Message\nfrom langflow.schema.properties import Source\nfrom langflow.template.field.base import Output\nfrom langflow.utils.constants import (\n MESSAGE_SENDER_AI,\n MESSAGE_SENDER_NAME_AI,\n MESSAGE_SENDER_USER,\n)\n\n\nclass ChatOutput(ChatComponent):\n display_name = \"Chat Output\"\n description = \"Display a chat message in the Playground.\"\n documentation: str = \"https://docs.langflow.org/components-io#chat-output\"\n icon = \"MessagesSquare\"\n name = \"ChatOutput\"\n minimized = True\n\n inputs = [\n HandleInput(\n name=\"input_value\",\n display_name=\"Inputs\",\n info=\"Message to be passed as output.\",\n input_types=[\"Data\", \"DataFrame\", \"Message\"],\n required=True,\n ),\n BoolInput(\n name=\"should_store_message\",\n display_name=\"Store Messages\",\n info=\"Store the message in the history.\",\n value=True,\n advanced=True,\n ),\n DropdownInput(\n name=\"sender\",\n display_name=\"Sender Type\",\n options=[MESSAGE_SENDER_AI, MESSAGE_SENDER_USER],\n value=MESSAGE_SENDER_AI,\n advanced=True,\n info=\"Type of sender.\",\n ),\n MessageTextInput(\n name=\"sender_name\",\n display_name=\"Sender Name\",\n info=\"Name of the sender.\",\n value=MESSAGE_SENDER_NAME_AI,\n advanced=True,\n ),\n MessageTextInput(\n name=\"session_id\",\n display_name=\"Session ID\",\n info=\"The session ID of the chat. If empty, the current session ID parameter will be used.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"data_template\",\n display_name=\"Data Template\",\n value=\"{text}\",\n advanced=True,\n info=\"Template to convert Data to Text. If left empty, it will be dynamically set to the Data's text key.\",\n ),\n MessageTextInput(\n name=\"background_color\",\n display_name=\"Background Color\",\n info=\"The background color of the icon.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"chat_icon\",\n display_name=\"Icon\",\n info=\"The icon of the message.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"text_color\",\n display_name=\"Text Color\",\n info=\"The text color of the name\",\n advanced=True,\n ),\n BoolInput(\n name=\"clean_data\",\n display_name=\"Basic Clean Data\",\n value=True,\n info=\"Whether to clean the data\",\n advanced=True,\n ),\n ]\n outputs = [\n Output(\n display_name=\"Output Message\",\n name=\"message\",\n method=\"message_response\",\n ),\n ]\n\n def _build_source(self, id_: str | None, display_name: str | None, source: str | None) -> Source:\n source_dict = {}\n if id_:\n source_dict[\"id\"] = id_\n if display_name:\n source_dict[\"display_name\"] = display_name\n if source:\n # Handle case where source is a ChatOpenAI object\n if hasattr(source, \"model_name\"):\n source_dict[\"source\"] = source.model_name\n elif hasattr(source, \"model\"):\n source_dict[\"source\"] = str(source.model)\n else:\n source_dict[\"source\"] = str(source)\n return Source(**source_dict)\n\n async def message_response(self) -> Message:\n # First convert the input to string if needed\n text = self.convert_to_string()\n\n # Get source properties\n source, icon, display_name, source_id = self.get_properties_from_source_component()\n background_color = self.background_color\n text_color = self.text_color\n if self.chat_icon:\n icon = self.chat_icon\n\n # Create or use existing Message object\n if isinstance(self.input_value, Message):\n message = self.input_value\n # Update message properties\n message.text = text\n else:\n message = Message(text=text)\n\n # Set message properties\n message.sender = self.sender\n message.sender_name = self.sender_name\n message.session_id = self.session_id\n message.flow_id = self.graph.flow_id if hasattr(self, \"graph\") else None\n message.properties.source = self._build_source(source_id, display_name, source)\n message.properties.icon = icon\n message.properties.background_color = background_color\n message.properties.text_color = text_color\n\n # Store message if needed\n if self.session_id and self.should_store_message:\n stored_message = await self.send_message(message)\n self.message.value = stored_message\n message = stored_message\n\n self.status = message\n return message\n\n def _serialize_data(self, data: Data) -> str:\n \"\"\"Serialize Data object to JSON string.\"\"\"\n # Convert data.data to JSON-serializable format\n serializable_data = jsonable_encoder(data.data)\n # Serialize with orjson, enabling pretty printing with indentation\n json_bytes = orjson.dumps(serializable_data, option=orjson.OPT_INDENT_2)\n # Convert bytes to string and wrap in Markdown code blocks\n return \"```json\\n\" + json_bytes.decode(\"utf-8\") + \"\\n```\"\n\n def _validate_input(self) -> None:\n \"\"\"Validate the input data and raise ValueError if invalid.\"\"\"\n if self.input_value is None:\n msg = \"Input data cannot be None\"\n raise ValueError(msg)\n if isinstance(self.input_value, list) and not all(\n isinstance(item, Message | Data | DataFrame | str) for item in self.input_value\n ):\n invalid_types = [\n type(item).__name__\n for item in self.input_value\n if not isinstance(item, Message | Data | DataFrame | str)\n ]\n msg = f\"Expected Data or DataFrame or Message or str, got {invalid_types}\"\n raise TypeError(msg)\n if not isinstance(\n self.input_value,\n Message | Data | DataFrame | str | list | Generator | type(None),\n ):\n type_name = type(self.input_value).__name__\n msg = f\"Expected Data or DataFrame or Message or str, Generator or None, got {type_name}\"\n raise TypeError(msg)\n\n def convert_to_string(self) -> str | Generator[Any, None, None]:\n \"\"\"Convert input data to string with proper error handling.\"\"\"\n self._validate_input()\n if isinstance(self.input_value, list):\n return \"\\n\".join([safe_convert(item, clean_data=self.clean_data) for item in self.input_value])\n if isinstance(self.input_value, Generator):\n return self.input_value\n return safe_convert(self.input_value)\n" | |
| }, | |
| "data_template": { | |
| "_input_type": "MessageTextInput", | |
| "advanced": true, | |
| "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" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "name": "data_template", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "{text}" | |
| }, | |
| "input_value": { | |
| "_input_type": "HandleInput", | |
| "advanced": false, | |
| "display_name": "Inputs", | |
| "dynamic": false, | |
| "info": "Message to be passed as output.", | |
| "input_types": [ | |
| "Data", | |
| "DataFrame", | |
| "Message" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "input_value", | |
| "placeholder": "", | |
| "required": true, | |
| "show": true, | |
| "title_case": false, | |
| "trace_as_metadata": true, | |
| "type": "other", | |
| "value": "" | |
| }, | |
| "sender": { | |
| "_input_type": "DropdownInput", | |
| "advanced": true, | |
| "combobox": false, | |
| "dialog_inputs": {}, | |
| "display_name": "Sender Type", | |
| "dynamic": false, | |
| "info": "Type of sender.", | |
| "name": "sender", | |
| "options": [ | |
| "Machine", | |
| "User" | |
| ], | |
| "options_metadata": [], | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "Machine" | |
| }, | |
| "sender_name": { | |
| "_input_type": "MessageTextInput", | |
| "advanced": true, | |
| "display_name": "Sender Name", | |
| "dynamic": false, | |
| "info": "Name of the sender.", | |
| "input_types": [ | |
| "Message" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "name": "sender_name", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "AI" | |
| }, | |
| "session_id": { | |
| "_input_type": "MessageTextInput", | |
| "advanced": true, | |
| "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" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "name": "session_id", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "" | |
| }, | |
| "should_store_message": { | |
| "_input_type": "BoolInput", | |
| "advanced": true, | |
| "display_name": "Store Messages", | |
| "dynamic": false, | |
| "info": "Store the message in the history.", | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "should_store_message", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "bool", | |
| "value": true | |
| }, | |
| "text_color": { | |
| "_input_type": "MessageTextInput", | |
| "advanced": true, | |
| "display_name": "Text Color", | |
| "dynamic": false, | |
| "info": "The text color of the name", | |
| "input_types": [ | |
| "Message" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "name": "text_color", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "" | |
| } | |
| }, | |
| "tool_mode": false | |
| }, | |
| "showNode": false, | |
| "type": "ChatOutput" | |
| }, | |
| "dragging": false, | |
| "id": "ChatOutput-4w4oZ", | |
| "measured": { | |
| "height": 48, | |
| "width": 192 | |
| }, | |
| "position": { | |
| "x": 2001.577867037061, | |
| "y": 679.227220639498 | |
| }, | |
| "selected": false, | |
| "type": "genericNode" | |
| }, | |
| { | |
| "data": { | |
| "id": "Agent-HN65G", | |
| "node": { | |
| "base_classes": [ | |
| "Message" | |
| ], | |
| "beta": false, | |
| "conditional_paths": [], | |
| "custom_fields": {}, | |
| "description": "Define the agent's instructions, then enter a task to complete using tools.", | |
| "display_name": "Agent", | |
| "documentation": "", | |
| "edited": false, | |
| "field_order": [ | |
| "agent_llm", | |
| "max_tokens", | |
| "model_kwargs", | |
| "json_mode", | |
| "model_name", | |
| "openai_api_base", | |
| "api_key", | |
| "temperature", | |
| "seed", | |
| "max_retries", | |
| "timeout", | |
| "system_prompt", | |
| "n_messages", | |
| "tools", | |
| "input_value", | |
| "handle_parsing_errors", | |
| "verbose", | |
| "max_iterations", | |
| "agent_description", | |
| "add_current_date_tool" | |
| ], | |
| "frozen": false, | |
| "icon": "bot", | |
| "last_updated": "2025-08-26T21:10:55.203Z", | |
| "legacy": false, | |
| "lf_version": "1.5.0", | |
| "metadata": {}, | |
| "minimized": false, | |
| "output_types": [], | |
| "outputs": [ | |
| { | |
| "allows_loop": false, | |
| "cache": true, | |
| "display_name": "Response", | |
| "group_outputs": false, | |
| "hidden": null, | |
| "method": "message_response", | |
| "name": "response", | |
| "options": null, | |
| "required_inputs": null, | |
| "selected": "Message", | |
| "tool_mode": true, | |
| "types": [ | |
| "Message" | |
| ], | |
| "value": "__UNDEFINED__" | |
| } | |
| ], | |
| "pinned": false, | |
| "template": { | |
| "_type": "Component", | |
| "add_current_date_tool": { | |
| "_input_type": "BoolInput", | |
| "advanced": true, | |
| "display_name": "Current Date", | |
| "dynamic": false, | |
| "info": "If true, will add a tool to the agent that returns the current date.", | |
| "input_types": [], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "add_current_date_tool", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "bool", | |
| "value": true | |
| }, | |
| "agent_description": { | |
| "_input_type": "MultilineInput", | |
| "advanced": true, | |
| "copy_field": false, | |
| "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" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "multiline": true, | |
| "name": "agent_description", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "A helpful assistant with access to the following tools:" | |
| }, | |
| "agent_llm": { | |
| "_input_type": "DropdownInput", | |
| "advanced": false, | |
| "combobox": false, | |
| "dialog_inputs": {}, | |
| "display_name": "Language Model", | |
| "dynamic": false, | |
| "info": "", | |
| "input_types": [ | |
| "LanguageModel" | |
| ], | |
| "name": "agent_llm", | |
| "options": [ | |
| "Anthropic", | |
| "Google Generative AI", | |
| "Groq", | |
| "OpenAI", | |
| "Custom" | |
| ], | |
| "options_metadata": [ | |
| { | |
| "icon": "Anthropic" | |
| }, | |
| { | |
| "icon": "GoogleGenerativeAI" | |
| }, | |
| { | |
| "icon": "Groq" | |
| }, | |
| { | |
| "icon": "OpenAI" | |
| }, | |
| { | |
| "icon": "brain" | |
| } | |
| ], | |
| "placeholder": "", | |
| "real_time_refresh": true, | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "toggle": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "" | |
| }, | |
| "code": { | |
| "advanced": true, | |
| "dynamic": true, | |
| "fileTypes": [], | |
| "file_path": "", | |
| "info": "", | |
| "input_types": [], | |
| "list": false, | |
| "load_from_db": false, | |
| "multiline": true, | |
| "name": "code", | |
| "password": false, | |
| "placeholder": "", | |
| "required": true, | |
| "show": true, | |
| "title_case": false, | |
| "type": "code", | |
| "value": "from langchain_core.tools import StructuredTool\n\nfrom langflow.base.agents.agent import LCToolsAgentComponent\nfrom langflow.base.agents.events import ExceptionWithMessageError\nfrom langflow.base.models.model_input_constants import (\n ALL_PROVIDER_FIELDS,\n MODEL_DYNAMIC_UPDATE_FIELDS,\n MODEL_PROVIDERS,\n MODEL_PROVIDERS_DICT,\n MODELS_METADATA,\n)\nfrom langflow.base.models.model_utils import get_model_name\nfrom langflow.components.helpers.current_date import CurrentDateComponent\nfrom langflow.components.helpers.memory import MemoryComponent\nfrom langflow.components.langchain_utilities.tool_calling import ToolCallingAgentComponent\nfrom langflow.custom.custom_component.component import _get_component_toolkit\nfrom langflow.custom.utils import update_component_build_config\nfrom langflow.field_typing import Tool\nfrom langflow.io import BoolInput, DropdownInput, IntInput, MultilineInput, Output\nfrom langflow.logging import logger\nfrom langflow.schema.dotdict import dotdict\nfrom langflow.schema.message import Message\n\n\ndef set_advanced_true(component_input):\n component_input.advanced = True\n return component_input\n\n\nMODEL_PROVIDERS_LIST = [\"Anthropic\", \"Google Generative AI\", \"Groq\", \"OpenAI\"]\n\n\nclass AgentComponent(ToolCallingAgentComponent):\n display_name: str = \"Agent\"\n description: str = \"Define the agent's instructions, then enter a task to complete using tools.\"\n documentation: str = \"https://docs.langflow.org/agents\"\n icon = \"bot\"\n beta = False\n name = \"Agent\"\n\n memory_inputs = [set_advanced_true(component_input) for component_input in MemoryComponent().inputs]\n\n inputs = [\n DropdownInput(\n name=\"agent_llm\",\n display_name=\"Model Provider\",\n info=\"The provider of the language model that the agent will use to generate responses.\",\n options=[*MODEL_PROVIDERS_LIST, \"Custom\"],\n value=\"OpenAI\",\n real_time_refresh=True,\n input_types=[],\n options_metadata=[MODELS_METADATA[key] for key in MODEL_PROVIDERS_LIST] + [{\"icon\": \"brain\"}],\n ),\n *MODEL_PROVIDERS_DICT[\"OpenAI\"][\"inputs\"],\n MultilineInput(\n name=\"system_prompt\",\n display_name=\"Agent Instructions\",\n info=\"System Prompt: Initial instructions and context provided to guide the agent's behavior.\",\n value=\"You are a helpful assistant that can use tools to answer questions and perform tasks.\",\n advanced=False,\n ),\n IntInput(\n name=\"n_messages\",\n display_name=\"Number of Chat History Messages\",\n value=100,\n info=\"Number of chat history messages to retrieve.\",\n advanced=True,\n show=True,\n ),\n *LCToolsAgentComponent._base_inputs,\n # removed memory inputs from agent component\n # *memory_inputs,\n BoolInput(\n name=\"add_current_date_tool\",\n display_name=\"Current Date\",\n advanced=True,\n info=\"If true, will add a tool to the agent that returns the current date.\",\n value=True,\n ),\n ]\n outputs = [Output(name=\"response\", display_name=\"Response\", method=\"message_response\")]\n\n async def message_response(self) -> Message:\n try:\n # Get LLM model and validate\n llm_model, display_name = self.get_llm()\n if llm_model is None:\n msg = \"No language model selected. Please choose a model to proceed.\"\n raise ValueError(msg)\n self.model_name = get_model_name(llm_model, display_name=display_name)\n\n # Get memory data\n self.chat_history = await self.get_memory_data()\n if isinstance(self.chat_history, Message):\n self.chat_history = [self.chat_history]\n\n # Add current date tool if enabled\n if self.add_current_date_tool:\n if not isinstance(self.tools, list): # type: ignore[has-type]\n self.tools = []\n current_date_tool = (await CurrentDateComponent(**self.get_base_args()).to_toolkit()).pop(0)\n if not isinstance(current_date_tool, StructuredTool):\n msg = \"CurrentDateComponent must be converted to a StructuredTool\"\n raise TypeError(msg)\n self.tools.append(current_date_tool)\n # note the tools are not required to run the agent, hence the validation removed.\n\n # Set up and run agent\n self.set(\n llm=llm_model,\n tools=self.tools or [],\n chat_history=self.chat_history,\n input_value=self.input_value,\n system_prompt=self.system_prompt,\n )\n agent = self.create_agent_runnable()\n return await self.run_agent(agent)\n\n except (ValueError, TypeError, KeyError) as e:\n logger.error(f\"{type(e).__name__}: {e!s}\")\n raise\n except ExceptionWithMessageError as e:\n logger.error(f\"ExceptionWithMessageError occurred: {e}\")\n raise\n except Exception as e:\n logger.error(f\"Unexpected error: {e!s}\")\n raise\n\n async def get_memory_data(self):\n # TODO: This is a temporary fix to avoid message duplication. We should develop a function for this.\n messages = (\n await MemoryComponent(**self.get_base_args())\n .set(session_id=self.graph.session_id, order=\"Ascending\", n_messages=self.n_messages)\n .retrieve_messages()\n )\n return [\n message for message in messages if getattr(message, \"id\", None) != getattr(self.input_value, \"id\", None)\n ]\n\n def get_llm(self):\n if not isinstance(self.agent_llm, str):\n return self.agent_llm, None\n\n try:\n provider_info = MODEL_PROVIDERS_DICT.get(self.agent_llm)\n if not provider_info:\n msg = f\"Invalid model provider: {self.agent_llm}\"\n raise ValueError(msg)\n\n component_class = provider_info.get(\"component_class\")\n display_name = component_class.display_name\n inputs = provider_info.get(\"inputs\")\n prefix = provider_info.get(\"prefix\", \"\")\n\n return self._build_llm_model(component_class, inputs, prefix), display_name\n\n except Exception as e:\n logger.error(f\"Error building {self.agent_llm} language model: {e!s}\")\n msg = f\"Failed to initialize language model: {e!s}\"\n raise ValueError(msg) from e\n\n def _build_llm_model(self, component, inputs, prefix=\"\"):\n model_kwargs = {}\n for input_ in inputs:\n if hasattr(self, f\"{prefix}{input_.name}\"):\n model_kwargs[input_.name] = getattr(self, f\"{prefix}{input_.name}\")\n return component.set(**model_kwargs).build_model()\n\n def set_component_params(self, component):\n provider_info = MODEL_PROVIDERS_DICT.get(self.agent_llm)\n if provider_info:\n inputs = provider_info.get(\"inputs\")\n prefix = provider_info.get(\"prefix\")\n model_kwargs = {input_.name: getattr(self, f\"{prefix}{input_.name}\") for input_ in inputs}\n\n return component.set(**model_kwargs)\n return component\n\n def delete_fields(self, build_config: dotdict, fields: dict | list[str]) -> None:\n \"\"\"Delete specified fields from build_config.\"\"\"\n for field in fields:\n build_config.pop(field, None)\n\n def update_input_types(self, build_config: dotdict) -> dotdict:\n \"\"\"Update input types for all fields in build_config.\"\"\"\n for key, value in build_config.items():\n if isinstance(value, dict):\n if value.get(\"input_types\") is None:\n build_config[key][\"input_types\"] = []\n elif hasattr(value, \"input_types\") and value.input_types is None:\n value.input_types = []\n return build_config\n\n async def update_build_config(\n self, build_config: dotdict, field_value: str, field_name: str | None = None\n ) -> dotdict:\n # Iterate over all providers in the MODEL_PROVIDERS_DICT\n # Existing logic for updating build_config\n if field_name in (\"agent_llm\",):\n build_config[\"agent_llm\"][\"value\"] = field_value\n provider_info = MODEL_PROVIDERS_DICT.get(field_value)\n if provider_info:\n component_class = provider_info.get(\"component_class\")\n if component_class and hasattr(component_class, \"update_build_config\"):\n # Call the component class's update_build_config method\n build_config = await update_component_build_config(\n component_class, build_config, field_value, \"model_name\"\n )\n\n provider_configs: dict[str, tuple[dict, list[dict]]] = {\n provider: (\n MODEL_PROVIDERS_DICT[provider][\"fields\"],\n [\n MODEL_PROVIDERS_DICT[other_provider][\"fields\"]\n for other_provider in MODEL_PROVIDERS_DICT\n if other_provider != provider\n ],\n )\n for provider in MODEL_PROVIDERS_DICT\n }\n if field_value in provider_configs:\n fields_to_add, fields_to_delete = provider_configs[field_value]\n\n # Delete fields from other providers\n for fields in fields_to_delete:\n self.delete_fields(build_config, fields)\n\n # Add provider-specific fields\n if field_value == \"OpenAI\" and not any(field in build_config for field in fields_to_add):\n build_config.update(fields_to_add)\n else:\n build_config.update(fields_to_add)\n # Reset input types for agent_llm\n build_config[\"agent_llm\"][\"input_types\"] = []\n elif field_value == \"Custom\":\n # Delete all provider fields\n self.delete_fields(build_config, ALL_PROVIDER_FIELDS)\n # Update with custom component\n custom_component = DropdownInput(\n name=\"agent_llm\",\n display_name=\"Language Model\",\n options=[*sorted(MODEL_PROVIDERS), \"Custom\"],\n value=\"Custom\",\n real_time_refresh=True,\n input_types=[\"LanguageModel\"],\n options_metadata=[MODELS_METADATA[key] for key in sorted(MODELS_METADATA.keys())]\n + [{\"icon\": \"brain\"}],\n )\n build_config.update({\"agent_llm\": custom_component.to_dict()})\n # Update input types for all fields\n build_config = self.update_input_types(build_config)\n\n # Validate required keys\n default_keys = [\n \"code\",\n \"_type\",\n \"agent_llm\",\n \"tools\",\n \"input_value\",\n \"add_current_date_tool\",\n \"system_prompt\",\n \"agent_description\",\n \"max_iterations\",\n \"handle_parsing_errors\",\n \"verbose\",\n ]\n missing_keys = [key for key in default_keys if key not in build_config]\n if missing_keys:\n msg = f\"Missing required keys in build_config: {missing_keys}\"\n raise ValueError(msg)\n if (\n isinstance(self.agent_llm, str)\n and self.agent_llm in MODEL_PROVIDERS_DICT\n and field_name in MODEL_DYNAMIC_UPDATE_FIELDS\n ):\n provider_info = MODEL_PROVIDERS_DICT.get(self.agent_llm)\n if provider_info:\n component_class = provider_info.get(\"component_class\")\n component_class = self.set_component_params(component_class)\n prefix = provider_info.get(\"prefix\")\n if component_class and hasattr(component_class, \"update_build_config\"):\n # Call each component class's update_build_config method\n # remove the prefix from the field_name\n if isinstance(field_name, str) and isinstance(prefix, str):\n field_name = field_name.replace(prefix, \"\")\n build_config = await update_component_build_config(\n component_class, build_config, field_value, \"model_name\"\n )\n return dotdict({k: v.to_dict() if hasattr(v, \"to_dict\") else v for k, v in build_config.items()})\n\n async def _get_tools(self) -> list[Tool]:\n component_toolkit = _get_component_toolkit()\n tools_names = self._build_tools_names()\n agent_description = self.get_tool_description()\n # TODO: Agent Description Depreciated Feature to be removed\n description = f\"{agent_description}{tools_names}\"\n tools = component_toolkit(component=self).get_tools(\n tool_name=\"Call_Agent\", tool_description=description, callbacks=self.get_langchain_callbacks()\n )\n if hasattr(self, \"tools_metadata\"):\n tools = component_toolkit(component=self, metadata=self.tools_metadata).update_tools_metadata(tools=tools)\n return tools\n" | |
| }, | |
| "handle_parsing_errors": { | |
| "_input_type": "BoolInput", | |
| "advanced": true, | |
| "display_name": "Handle Parse Errors", | |
| "dynamic": false, | |
| "info": "Should the Agent fix errors when reading user input for better processing?", | |
| "input_types": [], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "handle_parsing_errors", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "bool", | |
| "value": true | |
| }, | |
| "input_value": { | |
| "_input_type": "MessageTextInput", | |
| "advanced": false, | |
| "display_name": "Input", | |
| "dynamic": false, | |
| "info": "The input provided by the user for the agent to process.", | |
| "input_types": [ | |
| "Message" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "name": "input_value", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": true, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "" | |
| }, | |
| "max_iterations": { | |
| "_input_type": "IntInput", | |
| "advanced": true, | |
| "display_name": "Max Iterations", | |
| "dynamic": false, | |
| "info": "The maximum number of attempts the agent can make to complete its task before it stops.", | |
| "input_types": [], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "max_iterations", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "int", | |
| "value": 15 | |
| }, | |
| "n_messages": { | |
| "_input_type": "IntInput", | |
| "advanced": true, | |
| "display_name": "Number of Chat History Messages", | |
| "dynamic": false, | |
| "info": "Number of chat history messages to retrieve.", | |
| "input_types": [], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "n_messages", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "int", | |
| "value": 100 | |
| }, | |
| "system_prompt": { | |
| "_input_type": "MultilineInput", | |
| "advanced": false, | |
| "copy_field": false, | |
| "display_name": "Agent Instructions", | |
| "dynamic": false, | |
| "info": "System Prompt: Initial instructions and context provided to guide the agent's behavior.", | |
| "input_types": [ | |
| "Message" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "multiline": true, | |
| "name": "system_prompt", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "You are a helpful assistant that can use tools to answer questions and perform tasks." | |
| }, | |
| "tools": { | |
| "_input_type": "HandleInput", | |
| "advanced": false, | |
| "display_name": "Tools", | |
| "dynamic": false, | |
| "info": "These are the tools that the agent can use to help with tasks.", | |
| "input_types": [ | |
| "Tool" | |
| ], | |
| "list": true, | |
| "list_add_label": "Add More", | |
| "name": "tools", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "trace_as_metadata": true, | |
| "type": "other", | |
| "value": "" | |
| }, | |
| "verbose": { | |
| "_input_type": "BoolInput", | |
| "advanced": true, | |
| "display_name": "Verbose", | |
| "dynamic": false, | |
| "info": "", | |
| "input_types": [], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "verbose", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "bool", | |
| "value": true | |
| } | |
| }, | |
| "tool_mode": false | |
| }, | |
| "selected_output": "response", | |
| "showNode": true, | |
| "type": "Agent" | |
| }, | |
| "dragging": false, | |
| "id": "Agent-HN65G", | |
| "measured": { | |
| "height": 427, | |
| "width": 320 | |
| }, | |
| "position": { | |
| "x": 1641.6239626366948, | |
| "y": 301.10345101561927 | |
| }, | |
| "selected": false, | |
| "type": "genericNode" | |
| }, | |
| { | |
| "data": { | |
| "id": "OllamaModel-prrNR", | |
| "node": { | |
| "base_classes": [ | |
| "LanguageModel", | |
| "Message" | |
| ], | |
| "beta": false, | |
| "category": "ollama", | |
| "conditional_paths": [], | |
| "custom_fields": {}, | |
| "description": "Generate text using Ollama Local LLMs.", | |
| "display_name": "Ollama", | |
| "documentation": "", | |
| "edited": false, | |
| "field_order": [ | |
| "base_url", | |
| "model_name", | |
| "temperature", | |
| "format", | |
| "metadata", | |
| "mirostat", | |
| "mirostat_eta", | |
| "mirostat_tau", | |
| "num_ctx", | |
| "num_gpu", | |
| "num_thread", | |
| "repeat_last_n", | |
| "repeat_penalty", | |
| "tfs_z", | |
| "timeout", | |
| "top_k", | |
| "top_p", | |
| "verbose", | |
| "tags", | |
| "stop_tokens", | |
| "system", | |
| "tool_model_enabled", | |
| "template", | |
| "input_value", | |
| "system_message", | |
| "stream" | |
| ], | |
| "frozen": false, | |
| "icon": "Ollama", | |
| "key": "OllamaModel", | |
| "last_updated": "2025-08-26T21:10:55.196Z", | |
| "legacy": false, | |
| "lf_version": "1.5.0", | |
| "metadata": { | |
| "keywords": [ | |
| "model", | |
| "llm", | |
| "language model", | |
| "large language model" | |
| ] | |
| }, | |
| "minimized": false, | |
| "output_types": [], | |
| "outputs": [ | |
| { | |
| "allows_loop": false, | |
| "cache": true, | |
| "display_name": "Model Response", | |
| "group_outputs": false, | |
| "method": "text_response", | |
| "name": "text_output", | |
| "options": null, | |
| "required_inputs": null, | |
| "selected": "Message", | |
| "tool_mode": true, | |
| "types": [ | |
| "Message" | |
| ], | |
| "value": "__UNDEFINED__" | |
| }, | |
| { | |
| "allows_loop": false, | |
| "cache": true, | |
| "display_name": "Language Model", | |
| "group_outputs": false, | |
| "method": "build_model", | |
| "name": "model_output", | |
| "options": null, | |
| "required_inputs": null, | |
| "selected": "LanguageModel", | |
| "tool_mode": true, | |
| "types": [ | |
| "LanguageModel" | |
| ], | |
| "value": "__UNDEFINED__" | |
| } | |
| ], | |
| "pinned": false, | |
| "score": 2.556823146079367e-32, | |
| "template": { | |
| "_type": "Component", | |
| "base_url": { | |
| "_input_type": "MessageTextInput", | |
| "advanced": false, | |
| "display_name": "Base URL", | |
| "dynamic": false, | |
| "info": "Endpoint of the Ollama API.", | |
| "input_types": [ | |
| "Message" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "name": "base_url", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "http://localhost:11434" | |
| }, | |
| "code": { | |
| "advanced": true, | |
| "dynamic": true, | |
| "fileTypes": [], | |
| "file_path": "", | |
| "info": "", | |
| "list": false, | |
| "load_from_db": false, | |
| "multiline": true, | |
| "name": "code", | |
| "password": false, | |
| "placeholder": "", | |
| "required": true, | |
| "show": true, | |
| "title_case": false, | |
| "type": "code", | |
| "value": "import asyncio\nfrom typing import Any\nfrom urllib.parse import urljoin\n\nimport httpx\nfrom langchain_ollama import ChatOllama\n\nfrom langflow.base.models.model import LCModelComponent\nfrom langflow.base.models.ollama_constants import URL_LIST\nfrom langflow.field_typing import LanguageModel\nfrom langflow.field_typing.range_spec import RangeSpec\nfrom langflow.io import BoolInput, DictInput, DropdownInput, FloatInput, IntInput, MessageTextInput, SliderInput\nfrom langflow.logging import logger\n\nHTTP_STATUS_OK = 200\n\n\nclass ChatOllamaComponent(LCModelComponent):\n display_name = \"Ollama\"\n description = \"Generate text using Ollama Local LLMs.\"\n icon = \"Ollama\"\n name = \"OllamaModel\"\n\n # Define constants for JSON keys\n JSON_MODELS_KEY = \"models\"\n JSON_NAME_KEY = \"name\"\n JSON_CAPABILITIES_KEY = \"capabilities\"\n DESIRED_CAPABILITY = \"completion\"\n TOOL_CALLING_CAPABILITY = \"tools\"\n\n inputs = [\n MessageTextInput(\n name=\"base_url\",\n display_name=\"Base URL\",\n info=\"Endpoint of the Ollama API.\",\n value=\"\",\n ),\n DropdownInput(\n name=\"model_name\",\n display_name=\"Model Name\",\n options=[],\n info=\"Refer to https://ollama.com/library for more models.\",\n refresh_button=True,\n real_time_refresh=True,\n ),\n SliderInput(\n name=\"temperature\",\n display_name=\"Temperature\",\n value=0.1,\n range_spec=RangeSpec(min=0, max=1, step=0.01),\n advanced=True,\n ),\n MessageTextInput(\n name=\"format\", display_name=\"Format\", info=\"Specify the format of the output (e.g., json).\", advanced=True\n ),\n DictInput(name=\"metadata\", display_name=\"Metadata\", info=\"Metadata to add to the run trace.\", advanced=True),\n DropdownInput(\n name=\"mirostat\",\n display_name=\"Mirostat\",\n options=[\"Disabled\", \"Mirostat\", \"Mirostat 2.0\"],\n info=\"Enable/disable Mirostat sampling for controlling perplexity.\",\n value=\"Disabled\",\n advanced=True,\n real_time_refresh=True,\n ),\n FloatInput(\n name=\"mirostat_eta\",\n display_name=\"Mirostat Eta\",\n info=\"Learning rate for Mirostat algorithm. (Default: 0.1)\",\n advanced=True,\n ),\n FloatInput(\n name=\"mirostat_tau\",\n display_name=\"Mirostat Tau\",\n info=\"Controls the balance between coherence and diversity of the output. (Default: 5.0)\",\n advanced=True,\n ),\n IntInput(\n name=\"num_ctx\",\n display_name=\"Context Window Size\",\n info=\"Size of the context window for generating tokens. (Default: 2048)\",\n advanced=True,\n ),\n IntInput(\n name=\"num_gpu\",\n display_name=\"Number of GPUs\",\n info=\"Number of GPUs to use for computation. (Default: 1 on macOS, 0 to disable)\",\n advanced=True,\n ),\n IntInput(\n name=\"num_thread\",\n display_name=\"Number of Threads\",\n info=\"Number of threads to use during computation. (Default: detected for optimal performance)\",\n advanced=True,\n ),\n IntInput(\n name=\"repeat_last_n\",\n display_name=\"Repeat Last N\",\n info=\"How far back the model looks to prevent repetition. (Default: 64, 0 = disabled, -1 = num_ctx)\",\n advanced=True,\n ),\n FloatInput(\n name=\"repeat_penalty\",\n display_name=\"Repeat Penalty\",\n info=\"Penalty for repetitions in generated text. (Default: 1.1)\",\n advanced=True,\n ),\n FloatInput(name=\"tfs_z\", display_name=\"TFS Z\", info=\"Tail free sampling value. (Default: 1)\", advanced=True),\n IntInput(name=\"timeout\", display_name=\"Timeout\", info=\"Timeout for the request stream.\", advanced=True),\n IntInput(\n name=\"top_k\", display_name=\"Top K\", info=\"Limits token selection to top K. (Default: 40)\", advanced=True\n ),\n FloatInput(name=\"top_p\", display_name=\"Top P\", info=\"Works together with top-k. (Default: 0.9)\", advanced=True),\n BoolInput(name=\"verbose\", display_name=\"Verbose\", info=\"Whether to print out response text.\", advanced=True),\n MessageTextInput(\n name=\"tags\",\n display_name=\"Tags\",\n info=\"Comma-separated list of tags to add to the run trace.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"stop_tokens\",\n display_name=\"Stop Tokens\",\n info=\"Comma-separated list of tokens to signal the model to stop generating text.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"system\", display_name=\"System\", info=\"System to use for generating text.\", advanced=True\n ),\n BoolInput(\n name=\"tool_model_enabled\",\n display_name=\"Tool Model Enabled\",\n info=\"Whether to enable tool calling in the model.\",\n value=True,\n real_time_refresh=True,\n ),\n MessageTextInput(\n name=\"template\", display_name=\"Template\", info=\"Template to use for generating text.\", advanced=True\n ),\n *LCModelComponent._base_inputs,\n ]\n\n def build_model(self) -> LanguageModel: # type: ignore[type-var]\n # Mapping mirostat settings to their corresponding values\n mirostat_options = {\"Mirostat\": 1, \"Mirostat 2.0\": 2}\n\n # Default to 0 for 'Disabled'\n mirostat_value = mirostat_options.get(self.mirostat, 0)\n\n # Set mirostat_eta and mirostat_tau to None if mirostat is disabled\n if mirostat_value == 0:\n mirostat_eta = None\n mirostat_tau = None\n else:\n mirostat_eta = self.mirostat_eta\n mirostat_tau = self.mirostat_tau\n\n # Mapping system settings to their corresponding values\n llm_params = {\n \"base_url\": self.base_url,\n \"model\": self.model_name,\n \"mirostat\": mirostat_value,\n \"format\": self.format,\n \"metadata\": self.metadata,\n \"tags\": self.tags.split(\",\") if self.tags else None,\n \"mirostat_eta\": mirostat_eta,\n \"mirostat_tau\": mirostat_tau,\n \"num_ctx\": self.num_ctx or None,\n \"num_gpu\": self.num_gpu or None,\n \"num_thread\": self.num_thread or None,\n \"repeat_last_n\": self.repeat_last_n or None,\n \"repeat_penalty\": self.repeat_penalty or None,\n \"temperature\": self.temperature or None,\n \"stop\": self.stop_tokens.split(\",\") if self.stop_tokens else None,\n \"system\": self.system,\n \"tfs_z\": self.tfs_z or None,\n \"timeout\": self.timeout or None,\n \"top_k\": self.top_k or None,\n \"top_p\": self.top_p or None,\n \"verbose\": self.verbose,\n \"template\": self.template,\n }\n\n # Remove parameters with None values\n llm_params = {k: v for k, v in llm_params.items() if v is not None}\n\n try:\n output = ChatOllama(**llm_params)\n except Exception as e:\n msg = (\n \"Unable to connect to the Ollama API. \",\n \"Please verify the base URL, ensure the relevant Ollama model is pulled, and try again.\",\n )\n raise ValueError(msg) from e\n\n return output\n\n async def is_valid_ollama_url(self, url: str) -> bool:\n try:\n async with httpx.AsyncClient() as client:\n return (await client.get(urljoin(url, \"api/tags\"))).status_code == HTTP_STATUS_OK\n except httpx.RequestError:\n return False\n\n async def update_build_config(self, build_config: dict, field_value: Any, field_name: str | None = None):\n if field_name == \"mirostat\":\n if field_value == \"Disabled\":\n build_config[\"mirostat_eta\"][\"advanced\"] = True\n build_config[\"mirostat_tau\"][\"advanced\"] = True\n build_config[\"mirostat_eta\"][\"value\"] = None\n build_config[\"mirostat_tau\"][\"value\"] = None\n\n else:\n build_config[\"mirostat_eta\"][\"advanced\"] = False\n build_config[\"mirostat_tau\"][\"advanced\"] = False\n\n if field_value == \"Mirostat 2.0\":\n build_config[\"mirostat_eta\"][\"value\"] = 0.2\n build_config[\"mirostat_tau\"][\"value\"] = 10\n else:\n build_config[\"mirostat_eta\"][\"value\"] = 0.1\n build_config[\"mirostat_tau\"][\"value\"] = 5\n\n if field_name in {\"base_url\", \"model_name\"}:\n if build_config[\"base_url\"].get(\"load_from_db\", False):\n base_url_value = await self.get_variables(build_config[\"base_url\"].get(\"value\", \"\"), \"base_url\")\n else:\n base_url_value = build_config[\"base_url\"].get(\"value\", \"\")\n\n if not await self.is_valid_ollama_url(base_url_value):\n # Check if any URL in the list is valid\n valid_url = \"\"\n check_urls = URL_LIST\n if self.base_url:\n check_urls = [self.base_url, *URL_LIST]\n for url in check_urls:\n if await self.is_valid_ollama_url(url):\n valid_url = url\n break\n if valid_url != \"\":\n build_config[\"base_url\"][\"value\"] = valid_url\n else:\n msg = \"No valid Ollama URL found.\"\n raise ValueError(msg)\n if field_name in {\"model_name\", \"base_url\", \"tool_model_enabled\"}:\n if await self.is_valid_ollama_url(self.base_url):\n tool_model_enabled = build_config[\"tool_model_enabled\"].get(\"value\", False) or self.tool_model_enabled\n build_config[\"model_name\"][\"options\"] = await self.get_models(self.base_url, tool_model_enabled)\n elif await self.is_valid_ollama_url(build_config[\"base_url\"].get(\"value\", \"\")):\n tool_model_enabled = build_config[\"tool_model_enabled\"].get(\"value\", False) or self.tool_model_enabled\n build_config[\"model_name\"][\"options\"] = await self.get_models(\n build_config[\"base_url\"].get(\"value\", \"\"), tool_model_enabled\n )\n else:\n build_config[\"model_name\"][\"options\"] = []\n if field_name == \"keep_alive_flag\":\n if field_value == \"Keep\":\n build_config[\"keep_alive\"][\"value\"] = \"-1\"\n build_config[\"keep_alive\"][\"advanced\"] = True\n elif field_value == \"Immediately\":\n build_config[\"keep_alive\"][\"value\"] = \"0\"\n build_config[\"keep_alive\"][\"advanced\"] = True\n else:\n build_config[\"keep_alive\"][\"advanced\"] = False\n\n return build_config\n\n async def get_models(self, base_url_value: str, tool_model_enabled: bool | None = None) -> list[str]:\n \"\"\"Fetches a list of models from the Ollama API that do not have the \"embedding\" capability.\n\n Args:\n base_url_value (str): The base URL of the Ollama API.\n tool_model_enabled (bool | None, optional): If True, filters the models further to include\n only those that support tool calling. Defaults to None.\n\n Returns:\n list[str]: A list of model names that do not have the \"embedding\" capability. If\n `tool_model_enabled` is True, only models supporting tool calling are included.\n\n Raises:\n ValueError: If there is an issue with the API request or response, or if the model\n names cannot be retrieved.\n \"\"\"\n try:\n # Normalize the base URL to avoid the repeated \"/\" at the end\n base_url = base_url_value.rstrip(\"/\") + \"/\"\n\n # Ollama REST API to return models\n tags_url = urljoin(base_url, \"api/tags\")\n\n # Ollama REST API to return model capabilities\n show_url = urljoin(base_url, \"api/show\")\n\n async with httpx.AsyncClient() as client:\n # Fetch available models\n tags_response = await client.get(tags_url)\n tags_response.raise_for_status()\n models = tags_response.json()\n if asyncio.iscoroutine(models):\n models = await models\n logger.debug(f\"Available models: {models}\")\n\n # Filter models that are NOT embedding models\n model_ids = []\n for model in models[self.JSON_MODELS_KEY]:\n model_name = model[self.JSON_NAME_KEY]\n logger.debug(f\"Checking model: {model_name}\")\n\n payload = {\"model\": model_name}\n show_response = await client.post(show_url, json=payload)\n show_response.raise_for_status()\n json_data = show_response.json()\n if asyncio.iscoroutine(json_data):\n json_data = await json_data\n capabilities = json_data.get(self.JSON_CAPABILITIES_KEY, [])\n logger.debug(f\"Model: {model_name}, Capabilities: {capabilities}\")\n\n if self.DESIRED_CAPABILITY in capabilities and (\n not tool_model_enabled or self.TOOL_CALLING_CAPABILITY in capabilities\n ):\n model_ids.append(model_name)\n\n except (httpx.RequestError, ValueError) as e:\n msg = \"Could not get model names from Ollama.\"\n raise ValueError(msg) from e\n\n return model_ids\n" | |
| }, | |
| "format": { | |
| "_input_type": "MessageTextInput", | |
| "advanced": true, | |
| "display_name": "Format", | |
| "dynamic": false, | |
| "info": "Specify the format of the output (e.g., json).", | |
| "input_types": [ | |
| "Message" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "name": "format", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "" | |
| }, | |
| "input_value": { | |
| "_input_type": "MessageInput", | |
| "advanced": false, | |
| "display_name": "Input", | |
| "dynamic": false, | |
| "info": "", | |
| "input_types": [ | |
| "Message" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "name": "input_value", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "" | |
| }, | |
| "metadata": { | |
| "_input_type": "DictInput", | |
| "advanced": true, | |
| "display_name": "Metadata", | |
| "dynamic": false, | |
| "info": "Metadata to add to the run trace.", | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "metadata", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "type": "dict", | |
| "value": {} | |
| }, | |
| "mirostat": { | |
| "_input_type": "DropdownInput", | |
| "advanced": true, | |
| "combobox": false, | |
| "dialog_inputs": {}, | |
| "display_name": "Mirostat", | |
| "dynamic": false, | |
| "info": "Enable/disable Mirostat sampling for controlling perplexity.", | |
| "name": "mirostat", | |
| "options": [ | |
| "Disabled", | |
| "Mirostat", | |
| "Mirostat 2.0" | |
| ], | |
| "options_metadata": [], | |
| "placeholder": "", | |
| "real_time_refresh": true, | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "toggle": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "Disabled" | |
| }, | |
| "mirostat_eta": { | |
| "_input_type": "FloatInput", | |
| "advanced": true, | |
| "display_name": "Mirostat Eta", | |
| "dynamic": false, | |
| "info": "Learning rate for Mirostat algorithm. (Default: 0.1)", | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "mirostat_eta", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "float", | |
| "value": "" | |
| }, | |
| "mirostat_tau": { | |
| "_input_type": "FloatInput", | |
| "advanced": true, | |
| "display_name": "Mirostat Tau", | |
| "dynamic": false, | |
| "info": "Controls the balance between coherence and diversity of the output. (Default: 5.0)", | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "mirostat_tau", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "float", | |
| "value": "" | |
| }, | |
| "model_name": { | |
| "_input_type": "DropdownInput", | |
| "advanced": false, | |
| "combobox": false, | |
| "dialog_inputs": {}, | |
| "display_name": "Model Name", | |
| "dynamic": false, | |
| "info": "Refer to https://ollama.com/library for more models.", | |
| "name": "model_name", | |
| "options": [ | |
| "qwen3:4b", | |
| "gpt-oss:20b", | |
| "gpt-oss:latest", | |
| "qwen3:1.7b", | |
| "qwenthree42:30b", | |
| "qwenthree42:latest", | |
| "mychen76/qwen3_cline_roocode:30b", | |
| "mychen76/qwen3_cline_roocode:14b", | |
| "qwen3:0.6b", | |
| "qwen2.5-coder:0.5b", | |
| "devstral:latest", | |
| "devstral:24b", | |
| "devstral:24b-small-2505-q4_K_M", | |
| "qwen3:latest", | |
| "qwen3:30b-a3b", | |
| "qwen3:8b", | |
| "qwen3:14b", | |
| "qwen3:30b", | |
| "qwen2.5:7b", | |
| "nvjob/DeepSeek-R1-32B-Cline:latest", | |
| "qwen2.5-coder:1.5b", | |
| "llama3.1:latest", | |
| "llama3.1:8b" | |
| ], | |
| "options_metadata": [], | |
| "placeholder": "", | |
| "real_time_refresh": true, | |
| "refresh_button": true, | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "toggle": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "qwen3:1.7b" | |
| }, | |
| "num_ctx": { | |
| "_input_type": "IntInput", | |
| "advanced": true, | |
| "display_name": "Context Window Size", | |
| "dynamic": false, | |
| "info": "Size of the context window for generating tokens. (Default: 2048)", | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "num_ctx", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "int", | |
| "value": "" | |
| }, | |
| "num_gpu": { | |
| "_input_type": "IntInput", | |
| "advanced": true, | |
| "display_name": "Number of GPUs", | |
| "dynamic": false, | |
| "info": "Number of GPUs to use for computation. (Default: 1 on macOS, 0 to disable)", | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "num_gpu", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "int", | |
| "value": "" | |
| }, | |
| "num_thread": { | |
| "_input_type": "IntInput", | |
| "advanced": true, | |
| "display_name": "Number of Threads", | |
| "dynamic": false, | |
| "info": "Number of threads to use during computation. (Default: detected for optimal performance)", | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "num_thread", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "int", | |
| "value": "" | |
| }, | |
| "repeat_last_n": { | |
| "_input_type": "IntInput", | |
| "advanced": true, | |
| "display_name": "Repeat Last N", | |
| "dynamic": false, | |
| "info": "How far back the model looks to prevent repetition. (Default: 64, 0 = disabled, -1 = num_ctx)", | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "repeat_last_n", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "int", | |
| "value": "" | |
| }, | |
| "repeat_penalty": { | |
| "_input_type": "FloatInput", | |
| "advanced": true, | |
| "display_name": "Repeat Penalty", | |
| "dynamic": false, | |
| "info": "Penalty for repetitions in generated text. (Default: 1.1)", | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "repeat_penalty", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "float", | |
| "value": "" | |
| }, | |
| "stop_tokens": { | |
| "_input_type": "MessageTextInput", | |
| "advanced": true, | |
| "display_name": "Stop Tokens", | |
| "dynamic": false, | |
| "info": "Comma-separated list of tokens to signal the model to stop generating text.", | |
| "input_types": [ | |
| "Message" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "name": "stop_tokens", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "" | |
| }, | |
| "stream": { | |
| "_input_type": "BoolInput", | |
| "advanced": true, | |
| "display_name": "Stream", | |
| "dynamic": false, | |
| "info": "Stream the response from the model. Streaming works only in Chat.", | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "stream", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "bool", | |
| "value": false | |
| }, | |
| "system": { | |
| "_input_type": "MessageTextInput", | |
| "advanced": true, | |
| "display_name": "System", | |
| "dynamic": false, | |
| "info": "System to use for generating text.", | |
| "input_types": [ | |
| "Message" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "name": "system", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "" | |
| }, | |
| "system_message": { | |
| "_input_type": "MultilineInput", | |
| "advanced": false, | |
| "copy_field": false, | |
| "display_name": "System Message", | |
| "dynamic": false, | |
| "info": "System message to pass to the model.", | |
| "input_types": [ | |
| "Message" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "multiline": true, | |
| "name": "system_message", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "" | |
| }, | |
| "tags": { | |
| "_input_type": "MessageTextInput", | |
| "advanced": true, | |
| "display_name": "Tags", | |
| "dynamic": false, | |
| "info": "Comma-separated list of tags to add to the run trace.", | |
| "input_types": [ | |
| "Message" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "name": "tags", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "" | |
| }, | |
| "temperature": { | |
| "_input_type": "SliderInput", | |
| "advanced": true, | |
| "display_name": "Temperature", | |
| "dynamic": false, | |
| "info": "", | |
| "max_label": "", | |
| "max_label_icon": "", | |
| "min_label": "", | |
| "min_label_icon": "", | |
| "name": "temperature", | |
| "placeholder": "", | |
| "range_spec": { | |
| "max": 1, | |
| "min": 0, | |
| "step": 0.01, | |
| "step_type": "float" | |
| }, | |
| "required": false, | |
| "show": true, | |
| "slider_buttons": false, | |
| "slider_buttons_options": [], | |
| "slider_input": false, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "type": "slider", | |
| "value": 0.1 | |
| }, | |
| "template": { | |
| "_input_type": "MessageTextInput", | |
| "advanced": true, | |
| "display_name": "Template", | |
| "dynamic": false, | |
| "info": "Template to use for generating text.", | |
| "input_types": [ | |
| "Message" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "name": "template", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "" | |
| }, | |
| "tfs_z": { | |
| "_input_type": "FloatInput", | |
| "advanced": true, | |
| "display_name": "TFS Z", | |
| "dynamic": false, | |
| "info": "Tail free sampling value. (Default: 1)", | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "tfs_z", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "float", | |
| "value": "" | |
| }, | |
| "timeout": { | |
| "_input_type": "IntInput", | |
| "advanced": true, | |
| "display_name": "Timeout", | |
| "dynamic": false, | |
| "info": "Timeout for the request stream.", | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "timeout", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "int", | |
| "value": "" | |
| }, | |
| "tool_model_enabled": { | |
| "_input_type": "BoolInput", | |
| "advanced": false, | |
| "display_name": "Tool Model Enabled", | |
| "dynamic": false, | |
| "info": "Whether to enable tool calling in the model.", | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "tool_model_enabled", | |
| "placeholder": "", | |
| "real_time_refresh": true, | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "bool", | |
| "value": true | |
| }, | |
| "top_k": { | |
| "_input_type": "IntInput", | |
| "advanced": true, | |
| "display_name": "Top K", | |
| "dynamic": false, | |
| "info": "Limits token selection to top K. (Default: 40)", | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "top_k", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "int", | |
| "value": "" | |
| }, | |
| "top_p": { | |
| "_input_type": "FloatInput", | |
| "advanced": true, | |
| "display_name": "Top P", | |
| "dynamic": false, | |
| "info": "Works together with top-k. (Default: 0.9)", | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "top_p", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "float", | |
| "value": "" | |
| }, | |
| "verbose": { | |
| "_input_type": "BoolInput", | |
| "advanced": true, | |
| "display_name": "Verbose", | |
| "dynamic": false, | |
| "info": "Whether to print out response text.", | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "verbose", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "bool", | |
| "value": false | |
| } | |
| }, | |
| "tool_mode": false | |
| }, | |
| "selected_output": "model_output", | |
| "showNode": true, | |
| "type": "OllamaModel" | |
| }, | |
| "dragging": false, | |
| "id": "OllamaModel-prrNR", | |
| "measured": { | |
| "height": 491, | |
| "width": 320 | |
| }, | |
| "position": { | |
| "x": 1263.78562754362, | |
| "y": 271.046697742648 | |
| }, | |
| "selected": false, | |
| "type": "genericNode" | |
| }, | |
| { | |
| "data": { | |
| "id": "ChatInput-GpvuR", | |
| "node": { | |
| "base_classes": [ | |
| "Message" | |
| ], | |
| "beta": false, | |
| "category": "input_output", | |
| "conditional_paths": [], | |
| "custom_fields": {}, | |
| "description": "Get chat inputs from the Playground.", | |
| "display_name": "Chat Input", | |
| "documentation": "https://docs.langflow.org/components-io#chat-input", | |
| "edited": false, | |
| "field_order": [ | |
| "input_value", | |
| "should_store_message", | |
| "sender", | |
| "sender_name", | |
| "session_id", | |
| "files", | |
| "background_color", | |
| "chat_icon", | |
| "text_color" | |
| ], | |
| "frozen": false, | |
| "icon": "MessagesSquare", | |
| "key": "ChatInput", | |
| "legacy": false, | |
| "lf_version": "1.5.0", | |
| "metadata": {}, | |
| "minimized": true, | |
| "output_types": [], | |
| "outputs": [ | |
| { | |
| "allows_loop": false, | |
| "cache": true, | |
| "display_name": "Chat Message", | |
| "group_outputs": false, | |
| "method": "message_response", | |
| "name": "message", | |
| "selected": "Message", | |
| "tool_mode": true, | |
| "types": [ | |
| "Message" | |
| ], | |
| "value": "__UNDEFINED__" | |
| } | |
| ], | |
| "pinned": false, | |
| "score": 0.0020353564437605998, | |
| "template": { | |
| "_type": "Component", | |
| "background_color": { | |
| "_input_type": "MessageTextInput", | |
| "advanced": true, | |
| "display_name": "Background Color", | |
| "dynamic": false, | |
| "info": "The background color of the icon.", | |
| "input_types": [ | |
| "Message" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "name": "background_color", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "" | |
| }, | |
| "chat_icon": { | |
| "_input_type": "MessageTextInput", | |
| "advanced": true, | |
| "display_name": "Icon", | |
| "dynamic": false, | |
| "info": "The icon of the message.", | |
| "input_types": [ | |
| "Message" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "name": "chat_icon", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "" | |
| }, | |
| "code": { | |
| "advanced": true, | |
| "dynamic": true, | |
| "fileTypes": [], | |
| "file_path": "", | |
| "info": "", | |
| "list": false, | |
| "load_from_db": false, | |
| "multiline": true, | |
| "name": "code", | |
| "password": false, | |
| "placeholder": "", | |
| "required": true, | |
| "show": true, | |
| "title_case": false, | |
| "type": "code", | |
| "value": "from langflow.base.data.utils import IMG_FILE_TYPES, TEXT_FILE_TYPES\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.inputs.inputs import BoolInput\nfrom langflow.io import (\n DropdownInput,\n FileInput,\n MessageTextInput,\n MultilineInput,\n Output,\n)\nfrom langflow.schema.message import Message\nfrom langflow.utils.constants import (\n MESSAGE_SENDER_AI,\n MESSAGE_SENDER_NAME_USER,\n MESSAGE_SENDER_USER,\n)\n\n\nclass ChatInput(ChatComponent):\n display_name = \"Chat Input\"\n description = \"Get chat inputs from the Playground.\"\n documentation: str = \"https://docs.langflow.org/components-io#chat-input\"\n icon = \"MessagesSquare\"\n name = \"ChatInput\"\n minimized = True\n\n inputs = [\n MultilineInput(\n name=\"input_value\",\n display_name=\"Input Text\",\n value=\"\",\n info=\"Message to be passed as input.\",\n input_types=[],\n ),\n BoolInput(\n name=\"should_store_message\",\n display_name=\"Store Messages\",\n info=\"Store the message in the history.\",\n value=True,\n advanced=True,\n ),\n DropdownInput(\n name=\"sender\",\n display_name=\"Sender Type\",\n options=[MESSAGE_SENDER_AI, MESSAGE_SENDER_USER],\n value=MESSAGE_SENDER_USER,\n info=\"Type of sender.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"sender_name\",\n display_name=\"Sender Name\",\n info=\"Name of the sender.\",\n value=MESSAGE_SENDER_NAME_USER,\n advanced=True,\n ),\n MessageTextInput(\n name=\"session_id\",\n display_name=\"Session ID\",\n info=\"The session ID of the chat. If empty, the current session ID parameter will be used.\",\n advanced=True,\n ),\n FileInput(\n name=\"files\",\n display_name=\"Files\",\n file_types=TEXT_FILE_TYPES + IMG_FILE_TYPES,\n info=\"Files to be sent with the message.\",\n advanced=True,\n is_list=True,\n temp_file=True,\n ),\n MessageTextInput(\n name=\"background_color\",\n display_name=\"Background Color\",\n info=\"The background color of the icon.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"chat_icon\",\n display_name=\"Icon\",\n info=\"The icon of the message.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"text_color\",\n display_name=\"Text Color\",\n info=\"The text color of the name\",\n advanced=True,\n ),\n ]\n outputs = [\n Output(display_name=\"Chat Message\", name=\"message\", method=\"message_response\"),\n ]\n\n async def message_response(self) -> Message:\n background_color = self.background_color\n text_color = self.text_color\n icon = self.chat_icon\n\n message = await Message.create(\n text=self.input_value,\n sender=self.sender,\n sender_name=self.sender_name,\n session_id=self.session_id,\n files=self.files,\n properties={\n \"background_color\": background_color,\n \"text_color\": text_color,\n \"icon\": icon,\n },\n )\n if self.session_id and isinstance(message, Message) and self.should_store_message:\n stored_message = await self.send_message(\n message,\n )\n self.message.value = stored_message\n message = stored_message\n\n self.status = message\n return message\n" | |
| }, | |
| "files": { | |
| "_input_type": "FileInput", | |
| "advanced": true, | |
| "display_name": "Files", | |
| "dynamic": false, | |
| "fileTypes": [ | |
| "txt", | |
| "md", | |
| "mdx", | |
| "csv", | |
| "json", | |
| "yaml", | |
| "yml", | |
| "xml", | |
| "html", | |
| "htm", | |
| "pdf", | |
| "docx", | |
| "py", | |
| "sh", | |
| "sql", | |
| "js", | |
| "ts", | |
| "tsx", | |
| "jpg", | |
| "jpeg", | |
| "png", | |
| "bmp", | |
| "image" | |
| ], | |
| "file_path": "", | |
| "info": "Files to be sent with the message.", | |
| "list": true, | |
| "list_add_label": "Add More", | |
| "name": "files", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "temp_file": true, | |
| "title_case": false, | |
| "trace_as_metadata": true, | |
| "type": "file", | |
| "value": "" | |
| }, | |
| "input_value": { | |
| "_input_type": "MultilineInput", | |
| "advanced": false, | |
| "copy_field": false, | |
| "display_name": "Input Text", | |
| "dynamic": false, | |
| "info": "Message to be passed as input.", | |
| "input_types": [], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "multiline": true, | |
| "name": "input_value", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "" | |
| }, | |
| "sender": { | |
| "_input_type": "DropdownInput", | |
| "advanced": true, | |
| "combobox": false, | |
| "dialog_inputs": {}, | |
| "display_name": "Sender Type", | |
| "dynamic": false, | |
| "info": "Type of sender.", | |
| "name": "sender", | |
| "options": [ | |
| "Machine", | |
| "User" | |
| ], | |
| "options_metadata": [], | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "toggle": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "User" | |
| }, | |
| "sender_name": { | |
| "_input_type": "MessageTextInput", | |
| "advanced": true, | |
| "display_name": "Sender Name", | |
| "dynamic": false, | |
| "info": "Name of the sender.", | |
| "input_types": [ | |
| "Message" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "name": "sender_name", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "User" | |
| }, | |
| "session_id": { | |
| "_input_type": "MessageTextInput", | |
| "advanced": true, | |
| "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" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "name": "session_id", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "" | |
| }, | |
| "should_store_message": { | |
| "_input_type": "BoolInput", | |
| "advanced": true, | |
| "display_name": "Store Messages", | |
| "dynamic": false, | |
| "info": "Store the message in the history.", | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "name": "should_store_message", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_metadata": true, | |
| "type": "bool", | |
| "value": true | |
| }, | |
| "text_color": { | |
| "_input_type": "MessageTextInput", | |
| "advanced": true, | |
| "display_name": "Text Color", | |
| "dynamic": false, | |
| "info": "The text color of the name", | |
| "input_types": [ | |
| "Message" | |
| ], | |
| "list": false, | |
| "list_add_label": "Add More", | |
| "load_from_db": false, | |
| "name": "text_color", | |
| "placeholder": "", | |
| "required": false, | |
| "show": true, | |
| "title_case": false, | |
| "tool_mode": false, | |
| "trace_as_input": true, | |
| "trace_as_metadata": true, | |
| "type": "str", | |
| "value": "" | |
| } | |
| }, | |
| "tool_mode": false | |
| }, | |
| "showNode": false, | |
| "type": "ChatInput" | |
| }, | |
| "dragging": false, | |
| "id": "ChatInput-GpvuR", | |
| "measured": { | |
| "height": 48, | |
| "width": 192 | |
| }, | |
| "position": { | |
| "x": 1044.5942463197964, | |
| "y": 330.0369432744015 | |
| }, | |
| "selected": false, | |
| "type": "genericNode" | |
| } | |
| ], | |
| "viewport": { | |
| "x": -863.2852192136265, | |
| "y": -30.472936408502164, | |
| "zoom": 0.9992863827085035 | |
| } | |
| }, | |
| "description": "A simple but powerful starter Ollama agent.", | |
| "endpoint_name": null, | |
| "id": "b78704b5-482f-4777-bfe4-b6ea786c29a9", | |
| "is_component": false, | |
| "last_tested_version": "1.5.0", | |
| "name": "Simple Ollama Agent", | |
| "tags": [ | |
| "assistants", | |
| "agents" | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment