Files
compose-anything/src/langflow/README.md
2025-11-01 22:16:39 +08:00

6.2 KiB

Langflow

Langflow is a low-code visual framework for building AI applications. It's Python-based and agnostic to any model, API, or database, making it easy to build RAG applications, multi-agent systems, and custom AI workflows.

Features

  • Visual Flow Builder: Drag-and-drop interface for building AI applications
  • Multi-Model Support: Works with OpenAI, Anthropic, Google, HuggingFace, and more
  • RAG Components: Built-in support for vector databases and retrieval
  • Custom Components: Create your own Python components
  • Agent Support: Build multi-agent systems with memory and tools
  • Real-Time Monitoring: Track executions and debug flows
  • API Integration: REST API for programmatic access

Quick Start

  1. Copy .env.example to .env:

    cp .env.example .env
    
  2. (Optional) Edit .env to customize settings:

    • Generate a secure LANGFLOW_SECRET_KEY for production
    • Set LANGFLOW_AUTO_LOGIN=false to require authentication
    • Configure superuser credentials
    • Add API keys for LLM providers
  3. Start Langflow:

    docker compose up -d
    
  4. Wait for services to be ready

  5. Access Langflow UI at http://localhost:7860

  6. Start building your AI application!

Default Configuration

Service Port Description
Langflow 7860 Web UI and API
PostgreSQL 5432 Database (internal)

Default Credentials (if authentication enabled):

  • Username: langflow
  • Password: langflow

Environment Variables

Key environment variables (see .env.example for full list):

Variable Description Default
LANGFLOW_VERSION Langflow image version latest
LANGFLOW_PORT_OVERRIDE Host port for UI 7860
POSTGRES_PASSWORD Database password langflow
LANGFLOW_AUTO_LOGIN Auto-login (disable for auth) true
LANGFLOW_SUPERUSER Superuser username langflow
LANGFLOW_SUPERUSER_PASSWORD Superuser password langflow
LANGFLOW_SECRET_KEY Secret key for sessions (empty)
LANGFLOW_COMPONENTS_PATH Custom components directory (empty)
LANGFLOW_LOAD_FLOWS_PATH Auto-load flows directory (empty)
TZ Timezone UTC

Resource Requirements

Minimum:

  • CPU: 1 core
  • RAM: 1GB
  • Disk: 5GB

Recommended:

  • CPU: 2+ cores
  • RAM: 2GB+
  • Disk: 20GB+

Volumes

  • postgres_data: PostgreSQL database data
  • langflow_data: Langflow configuration, flows, and logs

Using Langflow

Building Your First Flow

  1. Access the UI at http://localhost:7860
  2. Click "New Flow" or use a template
  3. Drag components from the sidebar to the canvas
  4. Connect components by dragging between ports
  5. Configure component parameters
  6. Click "Run" to test your flow
  7. Use the API or integrate with your application

Adding API Keys

You can add API keys for LLM providers in two ways:

  1. Click your profile icon → Settings
  2. Go to "Global Variables"
  3. Add your API keys (e.g., OPENAI_API_KEY)
  4. Reference them in components using {OPENAI_API_KEY}

Option 2: Environment Variables

Add to your .env file:

OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GOOGLE_API_KEY=...

Langflow will automatically create global variables from these.

Using the API

Get your API token from the UI:

  1. Click your profile icon → Settings
  2. Go to "API Keys"
  3. Create a new API key

Example: Run a flow

curl -X POST http://localhost:7860/api/v1/run/YOUR_FLOW_ID \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"input_value": "Hello"}'

Custom Components

  1. Create a directory for your components
  2. Set LANGFLOW_COMPONENTS_PATH in .env
  3. Create Python files with your component classes
  4. Restart Langflow to load them

Example component structure:

from langflow import CustomComponent

class MyComponent(CustomComponent):
    display_name = "My Component"
    description = "Does something cool"
    
    def build(self):
        # Your component logic
        return result

Security Considerations

  1. Secret Key: Generate a strong LANGFLOW_SECRET_KEY for production:

    python -c "from secrets import token_urlsafe; print(token_urlsafe(32))"
    
  2. Authentication: Set LANGFLOW_AUTO_LOGIN=false to require login

  3. Database Password: Use a strong PostgreSQL password

  4. API Keys: Store sensitive keys as global variables, not in flows

  5. SSL/TLS: Use reverse proxy with HTTPS in production

  6. Network Access: Restrict access with firewall rules

Upgrading

To upgrade Langflow:

  1. Update LANGFLOW_VERSION in .env (or use latest)

  2. Pull and restart:

    docker compose pull
    docker compose up -d
    
  3. Check logs:

    docker compose logs -f langflow
    

Troubleshooting

Service won't start:

  • Check logs: docker compose logs langflow
  • Verify database: docker compose ps postgres
  • Ensure sufficient resources allocated

Cannot access UI:

  • Check port 7860 is not in use: netstat -an | findstr 7860
  • Verify firewall settings
  • Check container health: docker compose ps

API key not working:

  • Verify the key is set in Global Variables
  • Check the variable name matches in your components
  • Ensure LANGFLOW_STORE_ENVIRONMENT_VARIABLES=true

Flow execution errors:

  • Check component configurations
  • Review logs in the UI under each component
  • Verify API keys have sufficient credits/permissions

References

License

Langflow is licensed under MIT. See LICENSE for more information.