Skip to main content

Helpers

Helper components provide utility functions to help manage data and perform simple tasks in your flow.

Calculator

The Calculator component performs basic arithmetic operations on mathematical expressions. It supports addition, subtraction, multiplication, division, and exponentiation operations.

For an example of using this component in a flow, see the Python Interpreter component.

Calculator parameters

NameTypeDescription
expressionStringInput parameter. The arithmetic expression to evaluate, such as 4*4*(33/22)+12-20.
resultDataOutput parameter. The calculation result as a Data object containing the evaluated expression.

Current Date

The Current Date component returns the current date and time in a selected timezone. This component provides a flexible way to obtain timezone-specific date and time information within a Langflow pipeline.

Current Date parameters

NameTypeDescription
timezoneStringInput parameter. The timezone for the current date and time.
current_dateStringOutput parameter. The resulting current date and time in the selected timezone.

Message History

The Message History component provides combined chat history and message storage functionality. It can store and retrieve chat messages from either Langflow storage or a dedicated chat memory database like Mem0 or Redis.

tip

The Agent component has built-in chat memory that is enabled by default and uses Langflow storage. This built-in chat memory functionality is sufficient for most use cases.

Use the Message History component for the following use cases:

  • You need to store and retrieve chat memory for a language model component (not an agent).
  • You need to retrieve chat memories outside the chat context, such as a sentiment analysis flow that retrieves and analyzes recently stored memories.
  • You want to store memories in a specific database that is separate from Langflow storage.

For more information, see Store chat memory.

Use the Message History component in a flow

The Message History component has two modes, depending on where you want to use it in your flow:

  • Retrieve mode: The component retrieves chat messages from your Langflow database or external memory.
  • Store mode: The component stores chat messages in your Langflow database or external memory.

This means that you need multiple Message History components in your flow if you want to both store and retrieve chat messages.

The following steps explain how to create a chat-based flow that uses Message History components to store and retrieve chat memory from your Langflow installation's database:

  1. Create or edit a flow where you want to use chat memory.

  2. At the beginning of the flow, add a Message History component, and then set it to Retrieve mode.

  3. Optional: In the Message History component's header menu, click Controls to enable parameters for memory sorting, filtering, and limits.

  4. Add a Prompt Template component, add a {memory} variable to the Template field, and then connect the Message History output to the memory input.

    The Prompt Template component supplies instructions and context to LLMs, separate from chat messages passed through a Chat Input component. The template can include any text and variables that you want to supply to the LLM, for example:


    _10
    You are a helpful assistant that answers questions.
    _10
    _10
    Use markdown to format your answer, properly embedding images and urls.
    _10
    _10
    History:
    _10
    _10
    {memory}

    Variables ({variable}) in the template dynamically add fields to the Prompt Template component so that your flow can receive definitions for those values from elsewhere, such as other components, Langflow global variables, or runtime input. For more information, see Define variables in prompts.

    In this example, the {memory} variable is populated by the retrieved chat memories, which are then passed to a Language Model or Agent component to provide additional context to the LLM.

  5. Connect the Prompt Template component's output to a Language Model component's System Message input.

    This example uses the Language Model core component as the central chat driver, but you can also use another language model component or the Agent component.

  6. Add a Chat Input component, and then connect it to the Language Model component's Input field.

  7. Connect the Language Model component's output to a Chat Output component.

  8. At the end of the flow, add another Message History component, and then set it to Store mode.

    Configure any additional parameters in the second Message History component as needed, taking into consideration that this particular component will store chat messages rather than retrieve them.

  9. Connect the Chat Output component's output to the Message History component's Message input.

    Each response from the LLM is output from the Language Model component to the Chat Output component, and then stored in chat memory by the final Message History component.

Message History parameters

Some parameters are hidden by default in the visual editor. You can modify all parameters through the Controls in the component's header menu.

The available parameters depend on whether the component is in Retrieve or Store mode.

NameTypeDescription
Template (template)StringInput parameter. The template to use for formatting the data. It can contain the keys {text}, {sender} or any other key in the message data.
External Memory (memory)External MemoryInput parameter. Retrieve messages from an external memory. If empty, Langflow storage is used.
Number of Messages (n_messages)IntegerInput parameter. The number of messages to retrieve. Default: 100.
Order (order)StringInput parameter. The order of the messages. Default: Ascending.
Sender Type (sender_type)StringInput parameter. Filter by sender type, one of User, Machine, or Machine and User (default).
Session ID (session_id)StringInput parameter. The session ID of the chat memories to retrieve. If omitted or empty, the current session ID for the flow run is used.

Message History output

Memories can be retrieved in one of two formats:

  • Message: Retrieve memories as Message objects, including messages_text containing retrieved chat message text. This is the typical output format used to pass memories as chat messages to another component.

  • DataFrame: Returns memories as a DataFrame containing the message data. Useful for cases where you need to retrieve memories in a tabular format rather than as chat messages.

You can set the output type near the component's output port.

Legacy Helper components

Legacy components are longer supported and can be removed in a future release. You can continue to use them in existing flows, but it is recommended that you replace them with supported components as soon as possible. Suggested replacements are included in the Legacy banner on components in your flows. They are also given in release notes and Langflow documentation whenever possible.

If you aren't sure how to replace a legacy component, Search for components by provider, service, or component name. The component may have been deprecated in favor of a completely new component, a similar component, or a new version of the same component in a different category.

If there is no obvious replacement, consider whether another component can be adapted to your use case. For example, many Core components provide generic functionality that can support multiple providers and use cases, such as the API Request component.

If neither of these options are viable, you could use the legacy component's code to create your own custom component, or start a discussion about the legacy component.

To discourage use of legacy components in new flows, these components are hidden by default. In the visual editor, you can click Component settings to toggle the Legacy filter.

The following Helper components are in legacy status:

  • Message Store: Replaced by the Message History component

  • Create List: Replace with Processing components

  • ID Generator: Replace with a component that executes arbitrary code to generate an ID or embed an ID generator script your application code (external to your Langflow flows).

  • Output Parser: Replace with the Structured Output component and Parser component. The components you need depend on the data types and complexity of the parsing task.

    The Output Parser component transformed the output of a language model into comma-separated values (CSV) format, such as ["item1", "item2", "item3"], using LangChain's CommaSeparatedListOutputParser. The Structured Output component is a good alternative for this component because it also formats LLM responses with support for custom schemas and more complex parsing.

    Parsing components only provide formatting instructions and parsing functionality. They don't include prompts. You must connect parsers to Prompt Template components to create prompts that LLMs can use.

Search