Langflow Tutorial: Build an AI Agent With RAG [Step-by-Step Guide] | CodeConductor
Ai Agents
Langflow Tutorial: Build an AI Agent With RAG [Step-by-Step Guide]
Learn how to build an AI agent in Langflow with tools, RAG document search, API access, and web app integration. This tutorial covers setup, LLM configuration, Chroma DB retrieval, testing, debugging, production deployment, and how CodeConductor helps turn agent workflows into complete AI applications.
1Install and run Langflow using Python or Docker containers.
2Configure an LLM, prompts, tools, and memory inside a flow.
3Build a RAG knowledge base from uploaded documents and vector storage.
4Test, debug, and expose the agent via API for web apps.
How much time are you spending writing orchestration code, connecting models, configuring retrieval, and building APIs before your AI agent can answer its first useful question?
Langflow addresses this complexity through a visual, Python-based framework for connecting language models, prompts, tools, memory, and vector databases into executable AI workflows.
Its growing developer adoption is reflected in roughly 152,000 GitHub stars and 9,700 forks as of July 2026 (Source).
Recent engineering improvements have also reduced Langflow’s memory consumption by approximately 89%, making larger and longer-running workflows more practical (Source).
In this Langflow tutorial, you will build an AI agent that can call tools and retrieve information from uploaded documents. You will learn how to install Langflow, configure an LLM, create a RAG knowledge base, test and debug the flow, expose it through an API, connect it to a web application, and prepare it for production deployment.
What is Langflow and How Does it Build AI Agents?
Langflow is an open-source framework for building AI applications through visual workflows called flows. Each flow represents the path a request follows from the initial input to the final response.
A flow is made up of three core elements:
Components perform individual tasks, such as receiving a message, calling a language model, searching stored data, or running a tool.
Connections move information between components.
Execution order determines which components must run before others can begin.
For example, a basic conversational flow may send a user’s message from a Chat Input component to a language model, then pass the generated response to a Chat Output component. A more advanced agent may decide whether it needs to call a tool, search a knowledge base, or respond directly.
When the flow runs, Langflow checks the relationships between its components and executes them in the required sequence. The output produced by one component becomes the input for the next connected step.
Although the workflow is created visually, Langflow’s components are Python-based. Developers can adjust component settings, build custom components, or add application-specific logic when the standard options are insufficient. This allows teams to begin with visual configuration without being restricted to fixed templates.
A flow can be tested as a complete conversation or evaluated one component at a time, helping developers identify configuration, data-transfer, and model-response issues before integration.
Now that the flow structure is clear, the next step is to prepare the software, credentials, and local environment required to run Langflow.
Langflow Prerequisites: What Do You Need to Get Started?
Before installing Langflow, prepare the basic tools and credentials required for the tutorial.
You will need:
Python 3.10 or later for a local installation
Docker or Podman for a container-based setup
A model provider API key, such as OpenAI, Anthropic, Google, or another supported service
A modern web browser to access the Langflow interface
A sample document for testing the RAG knowledge base
Node.js, if you plan to connect the agent to a React or Next.js application
Store API keys in environment variables instead of adding them directly to your code. Also confirm that your model account has access to the model you want to use.
Once these requirements are met, you can install Langflow with Python or run it inside a Docker container.
How to Install Langflow With Python or Docker
Langflow can be installed with Python or run in a Docker container.
Install Langflow With Python
Langflow supports Python 3.10 through 3.12 (3.13 is experimental and may require workarounds). Create a virtual environment before installing it.
Automatic login is enabled by default in many Docker setups; for production, disable it by setting “LANGFLOW_AUTO_LOGIN=false”.
Configure an LLM Provider API Key
After opening Langflow:
Go to Settings
Open Global Variables
Select Add New
Enter a name such as OPENAI_API_KEY
Choose Credential as the variable type
Paste the key and save it
For request-time values, Langflow also supports passing variables through X-LANGFLOW-GLOBAL-VAR-* headers, so not every value needs to be created manually in Global Variables
For a local installation, recognized provider keys can also be loaded from a .env file:
OPENAI_API_KEY=your_api_key
Start Langflow with the file:
uv run langflow run --env-file .env
This lets components reference the credential without hardcoding the key in each flow. The model credential is now ready, so you can create the first agent workflow.
How to Build Your First AI Agent in Langflow
Create the core agent workflow by connecting the input, agent, output, and tool components.
Create a New Langflow Agent Flow
From the Langflow dashboard:
Select New Flow.
Choose Blank Flow.
Name the flow, such as Research Agent.
Add the Agent component to the workspace.
The Agent component processes user requests through the selected language model and generates the final response.
Connect Chat Input, Agent, and Chat Output
Add the following components:
Chat Input
Chat Output
Connect them in this order:
Chat Input → Agent → Chat Output
Connect the Chat Input output to the Agent input, then connect the Agent response to Chat Output. Chat Input receives the user’s message, while Chat Output displays the completed response in the Playground.
Select a Tool-Calling Language Model
Select the Agent component and choose a language model from the available provider list.
Use a model that supports tool calling. If the required model does not appear, enable its provider and model in Langflow’s model settings or connect a separate language-model component to the Agent.
Write Instructions for the AI Agent
Enter the following text in the Agent Instructions field:
You are a helpful research assistant.
Answer questions clearly and concisely.
Use a connected tool when it is required.
Do not invent tool results or document information.
If the required information is unavailable, explain that clearly.
These instructions define the agent’s role, response behaviour, and tool-use boundaries. Start with simple rules and refine them after testing the flow.
Connect a Tool to the Agent
Tools allow the agent to perform actions that the language model cannot complete reliably on its own.
Connect the Toolset output to the Agent’s Tools input.
Chat Input → Agent → Chat Output
↑
Calculator Too
When the user asks a calculation-based question, the agent can select the calculator, pass the required expression, and use the result in its response.
The flow can now handle general questions and calculations. The next step is to connect a RAG knowledge base so the agent can retrieve information from private documents.
How to Add RAG and Document Search to a Langflow Agent
RAG allows the agent to search uploaded documents before answering. Add the document-processing components to the existing flow, index the content once, and expose the vector search to the Agent as a tool.
Upload and Split the Source Documents
Add these components:
Read File
Split Text
Chroma DB
Upload a PDF or text document through Read File, then connect:
Read File → Split Text → Chroma DB
Connect the Loaded Files output to Split Text and the Chunks output to Chroma DB’s Ingest Data input.
Split Text divides the document into smaller passages that can be indexed and retrieved independently. Its chunk size and overlap can be adjusted later if the search results lack context.
Get insights in your inbox!!
Weekly tips on building smarter apps. Join 8,200+ founders and builders.
No spam. Unsubscribe anytime. We respect your privacy.
Generate Embeddings for Document Chunks
Add an Embedding Model component and select an embedding model from your configured provider.
Connect it to the Chroma DB Embedding input:
Embedding Model → Chroma DB
The embedding model converts each document chunk into a vector used for semantic search. As a best practice, use the same embedding model for both indexing and retrieval, since mixing models within one collection can reduce search quality.
Store the Embeddings in Chroma DB
In the Chroma DB component:
Enter a collection name, such as research-agent-documents.
Add a persistence directory if the indexed data should remain available after a restart.
Run the Chroma DB component.
Langflow will process the connected document, create embeddings, and write the records to the selected Chroma collection. Inspect the component output to confirm that the data was added successfully.
The indexing path should now look like this:
Read File → Split Text → Chroma DB
↑
Embedding Model
Connect Chroma Search to the Langflow Agent
Use the same Chroma DB component as the document-search tool:
Connect its tool output to the Agent’s Tools input.
Add a clear description, such as:
Search the uploaded document collection for information relevant to the user’s question.
Langflow agents can use connected components as tools, and their descriptions help the model decide when each tool is appropriate.
The Agent now has access to both tools:
Calculator Tool ─┐
├→ Agent → Chat Output
Chroma Search ───┘
↑
Chat Input
Some bundles provide dedicated “Retriever” or “Vector Store Tool” components as alternatives, depending on version. When a question relates to the uploaded documents, the Agent can search Chroma for relevant passages and use the retrieved content to prepare its response.
The RAG connection is now complete. The next step is to test whether the Agent selects the correct tool, retrieves useful passages, and accurately handles missing information.
How to Test and Debug Your Langflow AI Agent
Test the agent in Langflow before connecting it to an external application.
Test the AI Agent in Langflow Playground
Open the flow and select Playground. Run prompts that test each path:
What is 18% of 4,750?
According to the uploaded document, what is the refund period?
Who founded the company?
Confirm that the agent:
Answers general questions directly
Uses the Calculator for calculations
Searches Chroma for document-based questions
States when the requested information is unavailable
Verify Tool Usage and RAG Accuracy
For each response, check whether the correct tool was called.
For RAG questions, verify that:
Chroma returned a relevant passage
The answer matches the source document
No unsupported details were added
If the wrong tool is selected, improve its name or description in Edit Tool Actions.
If retrieval quality is poor, check:
The document was indexed successfully
The same embedding model is used for indexing and retrieval
The correct Chroma collection is selected
The chunk size provides enough context
Test one change at a time using the same prompts.
Review Execution Traces, Errors, and Token Usage
Open Traces after running the flow. Review:
Component inputs and outputs
Tool and retriever activity
Execution time
Error details
Model metadata
Token usage, when provided by the model provider
Start with the first failed or unusually slow component. This helps identify whether the issue comes from credentials, the model, retrieval, or tool configuration. Once the agent returns consistent responses and uses the correct tools, you can expose it through the Langflow API.
How to Run a Langflow Agent Through the REST API
Once the agent works correctly inside Langflow, the next step is to make it accessible outside the visual workspace. Langflow provides a REST API that lets external applications send messages to the flow and receive its responses.
Replace FLOW_ID with the ID shown in the API panel.
Send a Request to the Langflow API
Use cURL to test the flow:
curl --request POST \
--url "http://localhost:7860/api/v1/run/$FLOW_ID" \
--header "Content-Type: application/json" \
--header "x-api-key: $LANGFLOW_API_KEY" \
--data '{
"input_value": "What is the refund period?",
"input_type": "chat",
"output_type": "chat",
"session_id": "tutorial-user-1"
}'
The input_value contains the user message, while session_id groups related requests into the same conversation.
Process the Agent Response
The endpoint returns a JSON response containing the flow output and execution details. In a typical chat flow, the generated message can be extracted in Python like this:
import os
import requests
response = requests.post(
f"http://localhost:7860/api/v1/run/{os.environ['FLOW_ID']}",
headers={
"Content-Type": "application/json",
"x-api-key": os.environ["LANGFLOW_API_KEY"],
},
json={
"input_value": "What is the refund period?",
"input_type": "chat",
"output_type": "chat",
"session_id": "tutorial-user-1",
},
timeout=60,
)
response.raise_for_status()
result = response.json()
message = result["outputs"][0]["outputs"][0]["results"]["message"]["text"]
print(message)
The exact response path may vary depending on the flow’s output component; developers should inspect the JSON structure for their specific flow. Keep the Langflow API key on the server rather than placing it in browser-side code. The next section connects this endpoint to a web interface through a backend route.
How to Connect a Langflow Agent to a Web Application
Connect the Langflow endpoint to a basic chat interface through a server-side route.
Build the Chat Interface
Create a chat interface with an input field, send button, response area, and request status.
Send User Messages to Langflow
The backend should forward each message to the Langflow flow:
Display the returned message in the chat area. Show a loading state while the request is running and a clear error message if it fails.
Maintain Conversation Sessions
Reuse the same session_id throughout one conversation and generate a new value when the user starts another chat. Anonymous session IDs can be stored in the browser, while authenticated sessions should be managed on the server.
The web interface is now connected to the agent. The next section covers the security, storage, monitoring, and infrastructure needed for production deployment.
How to Deploy a Langflow AI Agent to Production
Production deployment requires persistent storage, secure access, monitoring, and failure recovery.
Choose a Deployment Method
Docker Compose: Suitable for a single-server deployment with persistent services.
Kubernetes: Suitable for multiple replicas, higher availability, and independent scaling.
Backend-only container: Runs Langflow as an API without exposing the visual editor.
For Kubernetes deployments, Langflow recommends using an external PostgreSQL database and network-level access controls (Source).
Secure API Keys and Environment Variables
Store model credentials, database passwords, Langflow API keys, and encryption secrets in environment variables or a Secrets Manager. Do not include them in source code or container images.
Use separate credentials for development and production environments.
Add Authentication and Rate Limiting
For shared or publicly accessible deployments:
Disable automatic login.
Enable authentication and secure administrator credentials.
Serve the application through HTTPS.
Limit editor and database access to authorized users or networks.
Apply rate limits through the backend, reverse proxy, or API gateway.
The Langflow editor should not be directly exposed to public users unless access is properly restricted.
Configure Monitoring and Persistent Storage
Langflow may use SQLite for local setups, but PostgreSQL is typically a better fit for production deployments.
Store uploaded files, vector data, and application state on persistent volumes or external services. Monitor:
Flow errors and failures
Response time and server health
Model, tool, and token usage
Database and storage capacity
Use Redis when running multiple workers because the default in-memory queue is limited to a single worker.
After deployment, verify the API, authentication, storage, and monitoring configuration. The next section covers common Langflow errors and how to resolve them.
Common Langflow Errors, Causes, and Fixes
Most Langflow issues come from setup, credentials, component connections, or retrieval configuration. Use the table below to identify the likely cause quickly.
Error
Main fix
Langflow does not start
Confirm the Python version and reinstall Langflow in a clean virtual environment.
Model provider authentication fails
Check the model credential, provider permissions, and available credits.
Agent does not use a tool
Enable Tool Mode and give the tool a clear name and description.
RAG returns irrelevant answers
Verify document indexing, the Chroma collection, embedding model, and chunk settings.
Langflow API returns 401 or 403
Add a valid Langflow API key to the request header and verify access permissions.
Playground returns no response
Confirm that Chat Input, Agent, and Chat Output are connected correctly.
Flow fails after an update
Review component or dependency changes and test the flow with the new version.
Use Traces and server logs to locate the first failed component and review its error details.
Conclusion: From Langflow Prototype to Production AI Application
Langflow provides a practical way to build AI agents by connecting models, tools, document retrieval, and APIs within a visual workflow. In this tutorial, you created an agent, added calculator and RAG capabilities, tested its behavior, connected it to a web interface, and prepared it for production use.
Langflow is a strong option when your main goal is to design and control the agent workflow. However, a complete AI product may also require a frontend, authentication, backend logic, user management, deployment pipelines, and monitoring.
CodeConductor helps teams build application layers alongside AI agents in one development environment. Explore CodeConductor when you need to move beyond an isolated agent flow and create a complete, production-ready AI application.
FAQs
Does Langflow require Python knowledge?
No Python knowledge is required for standard visual workflows. Python becomes useful when creating custom components, adding unsupported integrations, or modifying component behaviour.
Can Langflow build multi-agent workflows?
Yes. One Agent component can be connected to another as a tool, allowing specialized agents to collaborate within the same workflow.
Can Langflow connect to a React or Next.js application?
Yes. React and Next.js applications can send requests to a Langflow flow through its REST API. Keep the Langflow API key in a server-side route rather than exposing it in the browser.
Can Langflow be used in production?
Yes. Langflow provides container, backend-only runtime, and Kubernetes deployment options. Production environments still require authentication, persistent storage, monitoring, and appropriate network controls.
What is the difference between Langflow and LangChain?
Langflow provides a visual environment and runtime for assembling and deploying AI workflows. LangChain is a code-first framework that developers use to compose models, tools, prompts, and agent behaviour directly in Python or JavaScript.
Key Takeaways
4 essential insights
Use Langflow visual flows to connect LLMs, tools, memory, and vector databases.
Debug workflows by testing full conversations or individual components before integration.
Prepare prerequisites: Python 3.10+, API keys in env vars, sample documents.
Install via Python virtual environment or Docker, then start the Langflow server.
Written by
Paul Dhaliwal
Founder & Chief Executive Officer
Paul Dhaliwal is a tech innovator and Founder of CodeConductor, an open-source no/low-code platform. With 10+ years of experience in AI and scalable development, Paul focuses on crafting intelligent solutions that drive real-world value. A firm believer in the mantra "Eat, Sleep, Code, Repeat," he balances his passion for software with a love for travel and family.
⚡
Build your app
No coding. No designers. Just describe what you want and watch AI build it.