Step-by-Step Guides
FlowRunner Component
The CustomComponent class allows us to create components that interact with Langflow itself. In this example, we will make a component that runs other flows available in "My Collection".
We will cover how to:
List Collection flows using the
list_flows
method.Load a flow using the
load_flow
method.Configure a dropdown input field using the
options
parameter.
The typical structure of a Custom Component is composed of display_name
and description
attributes, build
and build_config
methods.
Let's start by defining our component's display_name
and description
.
Second, we will import Document
from the langchain.schema module. This will be the return type of the build
method.
Now, let's add the parameters and the return type to the build
method. The parameters added are:
flow_name
is the name of the flow we want to run.document
is the input document to be passed to that flow.Since
Document
is a Langchain type, it will add an input handle to the component (see more).
We can now start writing the build
method. Let's list available flows in "My Collection" using the list_flows
method.
CAUTION
From version 0.4.0, names are unique, which was not the case in previous versions. This might lead to unexpected results if using flows with the same name.
And retrieve a flow that matches the selected name (we'll make a dropdown input field for the user to choose among flow names).
You can load this flow using get_flow
and set a tweaks
dictionary to customize it. Find more about tweaks in our features guidelines.
We are using a Document
as input because it is a straightforward way to pass text data in Langflow (specifically because you can connect it to many loaders). Generally, a flow will take a string or a dictionary as input because that's what LangChain components expect. In case you are passing a dictionary, you need to build it according to the needs of the flow you are using.
The content of a document can be extracted using the page_content
attribute, which is a string, and passed as an argument to the selected flow.
CAUTION
Make sure that the field type is str and options values are strings.
Finally, we can add field customizations through the build_config
method. Here we added the options
key to make the flow_name
field a dropdown menu. Check out the custom component reference for a list of available keys.
Done! This is what our script and custom component looks like: