Skip to content

Commit 8c89672

Browse files
committed
add-content
1 parent 642edd3 commit 8c89672

2 files changed

Lines changed: 315 additions & 0 deletions

File tree

docs/docs/Flows/lfx.mdx

Lines changed: 310 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
1+
---
2+
title: Run flows with Langflow Executor (LFX)
3+
slug: /lfx-stateless-flows
4+
---
5+
6+
import Tabs from '@theme/Tabs';
7+
import TabItem from '@theme/TabItem';
8+
9+
The Langflow Executor (LFX) is a command-line tool that serves and runs flows statelessly from [flow JSON files](/concepts-flows-import) with minimal dependencies.
10+
11+
Flows are run without the flow builder UI or database, and any flow dependencies are automatically added to complete the run.
12+
The flow graph is stored in memory at all times, so there is less overhead for loading the graph from a database.
13+
Running a flow with LFX is similar to running flows with the [`--backend-only` environment variable](/environment-variables#server) enabled, but even more lightweight, because the Langflow package and all of its dependencies don't need to be installed.
14+
15+
Use LFX to share flows with other developers, test flows in different environments, and run flows in production applications without requiring the full Langflow UI or database setup.
16+
17+
LFX includes two commands for executing flows:
18+
19+
* [`lfx serve`](#serve): This command starts a FastAPI server hosting a Langflow API endpoint with your flow available at `/flows/{flow_id}/run`.
20+
* [`lfx run`](#run): This command executes a flow locally and returns the results to `stdout`.
21+
22+
## Prerequisites
23+
24+
- Install [Python](https://www.python.org/downloads/release/python-3100/)
25+
- Install [uv](https://docs.astral.sh/uv/getting-started/installation/)
26+
- Create or download a [flow JSON file](/concepts-flows)
27+
- Create an [OpenAI API key](https://platform.openai.com/api-keys)
28+
- Create a [Langflow API key](/api-keys-and-authentication)
29+
30+
## Install LFX
31+
32+
LFX can be installed in multiple ways.
33+
34+
<Tabs>
35+
<TabItem value="source" label="Clone repository" default>
36+
37+
1. Clone the Langflow repository:
38+
```bash
39+
git clone https://github.com/langflow-ai/langflow
40+
```
41+
42+
2. Change directory to `langflow/src/lfx`:
43+
```bash
44+
cd langflow/src/lfx
45+
```
46+
47+
3. Run LFX commands using `uv run`:
48+
```bash
49+
uv run lfx serve simple-agent-flow.json
50+
```
51+
52+
</TabItem>
53+
<TabItem value="pypi" label="Install from PyPI">
54+
55+
1. Create and activate a virtual environment.
56+
57+
```bash
58+
uv venv lfx-venv
59+
source lfx-venv/bin/activate
60+
```
61+
62+
2. Install the LFX package from PyPI:
63+
64+
```bash
65+
uv pip install lfx
66+
```
67+
68+
3. Run LFX commands using `uv run`:
69+
70+
```bash
71+
uv run lfx serve simple-agent-flow.json
72+
```
73+
74+
</TabItem>
75+
<TabItem value="uvx" label="Run without installing">
76+
77+
Run LFX without installing it using `uvx`:
78+
79+
```bash
80+
uvx lfx serve simple-agent-flow.json
81+
```
82+
83+
This command downloads and runs LFX in a temporary environment without permanent installation.
84+
85+
</TabItem>
86+
</Tabs>
87+
88+
## Serve the simple agent starter flow with `lfx serve` {#serve}
89+
90+
To serve a flow as a REST API endpoint, set a `LANGFLOW_API_KEY` and run the flow JSON.
91+
The API key is required for security because `lfx serve` can create a publicly accessible FastAPI server.
92+
To create a Langflow API key, see [API keys and authentication](/api-keys-and-authentication).
93+
94+
This example uses the **Agent** component's built-in OpenAI model, which requires an OpenAI API key.
95+
If you want to use a different provider, edit the model provider, model name, and credentials accordingly.
96+
97+
1. Set up your environment variables.
98+
99+
<Tabs>
100+
<TabItem value="env-file" label=".env file" default>
101+
102+
Create a `.env` file and populate it with your flow's variables.
103+
The `LANGFLOW_API_KEY` is required.
104+
This example assumes the flow requires an OpenAI API key.
105+
106+
```bash
107+
LANGFLOW_API_KEY="sk..."
108+
OPENAI_API_KEY="sk-..."
109+
```
110+
111+
</TabItem>
112+
<TabItem value="export" label="Export variables">
113+
114+
Export your variables in the same terminal session where you'll start the server.
115+
You must declare your variables before the server starts for the server to pick them up.
116+
117+
```bash
118+
export LANGFLOW_API_KEY="sk..."
119+
export OPENAI_API_KEY="sk-..."
120+
```
121+
122+
</TabItem>
123+
</Tabs>
124+
125+
2. Start the server with your variable values.
126+
127+
<Tabs>
128+
<TabItem value="env-file" label=".env file" default>
129+
130+
This example assumes your flow file and `.env` file are in the current directory:
131+
132+
```
133+
uv run lfx serve simple-agent-flow.json --env-file .env
134+
```
135+
136+
If your `.env` file is in a different location, provide the full or relative path:
137+
138+
```
139+
uv run lfx serve simple-agent-flow.json --env-file /path/to/.env
140+
```
141+
142+
</TabItem>
143+
<TabItem value="export" label="Export variables">
144+
145+
If you exported your variables, the command to start the server automatically picks up the values when it starts.
146+
147+
```
148+
uv run lfx serve simple-agent-flow.json
149+
```
150+
151+
To export new values, stop the server, export the variables, and start the server again.
152+
153+
</TabItem>
154+
</Tabs>
155+
156+
157+
158+
3. The startup process displays a `flow_id` value in the output.
159+
Copy the `flow_id` to use in the test API call in the next step.
160+
In this example, the `flow_id` is `c1dab29d-3364-58ef-8fef-99311d32ee42`.
161+
162+
```bash
163+
╭───────────────────────────── LFX Server ─────────────────────────────╮
164+
│ 🎯 Single Flow Served Successfully!
165+
│ │
166+
│ Source: /Users/mendonkissling/Downloads/simple-agent-flow.json │
167+
│ Server: http://127.0.0.1:8000 │
168+
│ API Key: sk-... │
169+
│ │
170+
│ Send POST requests to: │
171+
│ http://127.0.0.1:8000/flows/c1dab29d-3364-58ef-8fef-99311d32ee42/run │
172+
│ │
173+
│ With headers: │
174+
│ x-api-key: sk-... │
175+
│ │
176+
│ Or query parameter: │
177+
?x-api-key=sk-... │
178+
│ │
179+
│ Request body: │
180+
│ {'input_value': 'Your input message'} │
181+
╰──────────────────────────────────────────────────────────────────────╯
182+
```
183+
184+
4. In a new terminal, export your `flow_id` and Langflow API key values as variables.
185+
```bash
186+
export LANGFLOW_API_KEY="sk..."
187+
export FLOW_ID="c1dab29d-3364-58ef-8fef-99311d32ee42"
188+
```
189+
190+
5. Test the server with an API call to the `/flows/flow_id/run` endpoint.
191+
192+
```bash
193+
curl -X POST http://localhost:8000/flows/$FLOW_ID/run \
194+
-H "Content-Type: application/json" \
195+
-H "x-api-key: $LANGFLOW_API_KEY" \
196+
-d '{"input_value": "Hello, world!"}'
197+
```
198+
199+
Successful response:
200+
```json
201+
{
202+
"result": "Hello world! 👋\n\nHow can I help you today? If you have any questions or need assistance, just let me know!",
203+
"success": true,
204+
"logs": "\n\n\u001b[1m> Entering new None chain...\u001b[0m\n\u001b[32;1m\u001b[1;3mHello world! 👋\n\nHow can I help you today? If you have any questions or need assistance, just let me know!\u001b[0m\n\n\u001b[1m> Finished chain.\u001b[0m\n",
205+
"type": "message",
206+
"component": "Chat Output"
207+
}
208+
```
209+
210+
Your flow is now running as a lightweight API endpoint, with only the flow's required dependencies and no visual builder installed.
211+
Users who call your endpoint don't need to install Langflow or configure their own LLM provider keys.
212+
213+
To make your server publicly accessible, use a [tunneling service like ngrok](/deployment-public-server), or deploy to a public cloud provider such as [DigitalOcean](/deployment-nginx-ssl).
214+
215+
### LFX serve options
216+
217+
| Option | Description |
218+
|-----------------------------------------|-----------------------------------------------------------------------------------------------|
219+
| `--check-variables`/`--no-check-variables` | Check global variables for environment variables. |
220+
| `--env-file` | The path to the `.env` file. |
221+
| `--host`, `-h` | Host to bind server. Default: `127.0.0.1` (localhost only). Use `0.0.0.0` to make it publicly accessible from other machines. |
222+
| `--log-level` | Set logging level. Options are `debug`, `info`, `warning`, `error`, or `critical`. |
223+
| `--port`, `-p` | Port to bind server. Default:`8000`. |
224+
| `--verbose`, `-v` | Display diagnostic output. |
225+
226+
## Run the simple agent flow with `lfx run` {#run}
227+
228+
The `lfx run` command runs a flow from a JSON file without serving it, and the output is sent to `stdout`.
229+
Input to `lfx run` can be a path to the JSON file, inline JSON passed with `--input-value`, or read from `stdin`.
230+
No Langflow API key is required.
231+
232+
This example uses the **Agent** component's built-in OpenAI model, which requires an OpenAI API key.
233+
If you want to use a different provider, edit the model provider, model name, and credentials accordingly.
234+
235+
1. Export your variables in the same terminal session where you'll run the flow.
236+
```bash
237+
export OPENAI_API_KEY="sk-..."
238+
```
239+
240+
2. Run the flow from a flow JSON file.
241+
```bash
242+
uv run lfx run simple-agent-flow.json "Hello world"
243+
```
244+
245+
This flow expects a [Message](/data-types#message) input, which is a simple text string. The simple agent flow includes Calculator and URL tools, it can answer questions such as `"What is 15 multiplied by 23?"` or `"Can you fetch information from https://example.com?"`.
246+
247+
If your flow expects multiple structured input fields, you can pass structured JSON with the `--input-value` flag. The field names must match what your flow expects:
248+
```bash
249+
uv run lfx run structured-input-flow.json \
250+
--input-value '{"question": "What is the weather in Paris?", "context": "weather"}'
251+
```
252+
253+
In addition to running flows from JSON files, `lfx run` supports other input methods, which are described in the sections below.
254+
255+
### Run flows from stdin
256+
257+
The `--stdin` option allows you to run flows that come from dynamic sources such as APIs or databases, or when you want to modify a flow before execution.
258+
The command reads the flow's JSON definition from `stdin`, validates the JSON structure, and runs the flow.
259+
260+
This example reads a flow JSON from stdin.
261+
Provide the input value to the flow with the `--input-value` flag.
262+
```bash
263+
cat simple-agent-flow.json | uv run lfx run --stdin \
264+
--input-value "Hello world" \
265+
--format json | jq '.result'
266+
```
267+
268+
This example fetches a flow JSON from a remote API endpoint and runs it:
269+
```bash
270+
curl https://api.example.com/flows/my-agent-flow | uv run lfx run --stdin \
271+
--input-value "Hello world"
272+
```
273+
274+
Running a flow with `stdin` allows you to modify flows created in the visual builder before execution.
275+
This example demonstrates changing the OpenAI model to `gpt-4o` before running the flow:
276+
```bash
277+
cat simple-agent-flow.json | jq '(.data.nodes[] | select(.data.node.template.model_name.value) | .data.node.template.model_name.value) = "gpt-4o"' | \
278+
uv run lfx run --stdin \
279+
--input-value "Hello world" \
280+
--format json | jq '.result'
281+
```
282+
283+
### Run flows with inline JSON
284+
285+
Instead of piping from `stdin` or reading from a JSON file, you can pass the flow JSON directly as a string argument:
286+
```bash
287+
uv run lfx run --flow-json '{"data": {"nodes": [...], "edges": [...]}}' \
288+
--input-value "Hello world"
289+
```
290+
291+
### LFX run options
292+
293+
| Option | Description |
294+
|------------------------------------------------|--------------------------------------------------------------------------------------------------|
295+
| `--check-variables`/`--no-check-variables` | Validates the flow's global variables. Default: check. |
296+
| `--flow-json` | Loads inline JSON flow content as a string. |
297+
| `--format`, `-f` | Output format. Accepts `json`, `text`, `message`, or `result`. Default: `json`. |
298+
| `--input-value` | Input value to pass to the graph. |
299+
| `--stdin` | Read JSON flow content from `stdin`. |
300+
| `--timing` | Include detailed timing information in output. |
301+
| `--verbose`, `-v` | Show basic progress information and diagnostic output. |
302+
| `-vv` | Show detailed progress and debug information. |
303+
| `-vvv` | Show full debugging output including component logs. |
304+
305+
### Use LFX run to create an application
306+
307+
In addition to running flows from JSON files, you can use `lfx run` with Python scripts that define flows programmatically.
308+
This approach allows you to create flows directly in Python code without the visual builder.
309+
310+
For a complete example of creating an agent flow programmatically using LFX components, see the [Complete Agent Example on PyPI](https://pypi.org/project/lfx/0.1.13/#complete-agent-example).

docs/sidebars.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ module.exports = {
7171
id: "Flows/concepts-flows-import",
7272
label: "Import and export flows"
7373
},
74+
{
75+
type: "doc",
76+
id: "Flows/lfx",
77+
label: "Run flows with Langflow Executor (LFX)"
78+
},
7479
],
7580
},
7681
{

0 commit comments

Comments
 (0)