Skip to main content
Version: 1.9.x

Build components with Langflow Assistant

Langflow Assistant is an in-app virtual assistant pane within the Playground.

It can answer questions about the application and help you get more out of Langflow.

Langflow Assistant understands the structure of the Langflow graph, so it can create components from natural language prompts.

Behind the scenes, Langflow Assistant runs a built-in Langflow flow on your Langflow server each time you send a message. This flow is distinct from the flow that is open in the canvas, and has its own language model. The language model in Langflow Assistant only has the currently opened flow in your workspace for context. To give Langflow Assistant context for a different flow, switch to that flow in your workspace, and open Langflow Assistant.

Prerequisites

Create a custom component with Langflow Assistant

In this example, you'll prompt Langflow Assistant to create a custom component that validates and normalizes a list of URLs.

You'll then iterate on the code based on the results in the Playground.

  1. In the Playground, click the Langflow icon. The Langflow Assistant pane opens.

  2. Optionally, ask What can you help me with? for a list of Langflow Assistant's capabilities.

  3. Prompt Langflow Assistant to generate a custom component. For example:


    _10
    Create a custom component URLTitleExtractor with:
    _10
    input: text
    _10
    output: list of {url, title, status}
    _10
    timeout handling + per-URL error handling
    _10
    clean docstring and typed methods.”

  4. Langflow Assistant generates component code from your prompt. Because generation is model-driven, your code may differ from the example below.

    Python component code

    _124
    import html
    _124
    import re
    _124
    from typing import Any
    _124
    from urllib.error import HTTPError, URLError
    _124
    from urllib.request import Request, urlopen
    _124
    _124
    from lfx.custom import Component
    _124
    from lfx.io import FloatInput, MessageTextInput, Output
    _124
    from lfx.schema import DataFrame
    _124
    _124
    _124
    class URLTitleExtractor(Component):
    _124
    """Extract URLs from text, fetch each page, and return URL/title/status rows."""
    _124
    _124
    display_name = "URLTitleExtractor"
    _124
    description = "Extracts URLs from input text and fetches page titles with per-URL status handling."
    _124
    icon = "Link"
    _124
    _124
    inputs = [
    _124
    MessageTextInput(
    _124
    name="text",
    _124
    display_name="Text",
    _124
    info="Text that may contain one or more URLs.",
    _124
    required=True,
    _124
    ),
    _124
    FloatInput(
    _124
    name="timeout",
    _124
    display_name="Timeout",
    _124
    value=5.0,
    _124
    info="HTTP request timeout in seconds for each URL.",
    _124
    range_spec={"min": 0.1, "max": 60.0, "step": 0.1, "step_type": "float"},
    _124
    ),
    _124
    ]
    _124
    _124
    outputs = [
    _124
    Output(
    _124
    name="dataframe",
    _124
    display_name="DataFrame",
    _124
    method="build_dataframe",
    _124
    ),
    _124
    ]
    _124
    _124
    URL_PATTERN = re.compile(r"https?://[^\s<>\]\"'`{}|\\^]+", re.IGNORECASE)
    _124
    TITLE_PATTERN = re.compile(r"<title\b[^>]*>(.*?)</title>", re.IGNORECASE | re.DOTALL)
    _124
    _124
    def build_dataframe(self) -> DataFrame:
    _124
    """Build a DataFrame containing URL, extracted title, and request status."""
    _124
    urls = self._extract_urls(self.text)
    _124
    rows = [self._process_url(url, self.timeout) for url in urls]
    _124
    return DataFrame(rows)
    _124
    _124
    def _extract_urls(self, text: str) -> list[str]:
    _124
    """Extract unique URLs from text using a conservative regex."""
    _124
    if not text:
    _124
    return []
    _124
    _124
    matches = self.URL_PATTERN.findall(text)
    _124
    cleaned_urls: list[str] = []
    _124
    seen: set[str] = set()
    _124
    _124
    for url in matches:
    _124
    cleaned = url.rstrip(".,);:!?]}")
    _124
    if cleaned and cleaned not in seen:
    _124
    seen.add(cleaned)
    _124
    cleaned_urls.append(cleaned)
    _124
    _124
    return cleaned_urls
    _124
    _124
    def _process_url(self, url: str, timeout: float) -> dict[str, Any]:
    _124
    """Fetch a URL and return a row with url, title, and status."""
    _124
    request = Request(
    _124
    url,
    _124
    headers={
    _124
    "User-Agent": "Mozilla/5.0 (compatible; Langflow URLTitleExtractor/1.0)"
    _124
    },
    _124
    )
    _124
    _124
    try:
    _124
    with urlopen(request, timeout=float(timeout)) as response:
    _124
    status_code = getattr(response, "status", 200)
    _124
    content_bytes = response.read()
    _124
    content_type = response.headers.get_content_charset() or "utf-8"
    _124
    html_text = content_bytes.decode(content_type, errors="replace")
    _124
    title = self._extract_title(html_text)
    _124
    return {"url": url, "title": title, "status": str(status_code)}
    _124
    _124
    except HTTPError as exc:
    _124
    title = ""
    _124
    try:
    _124
    body = exc.read()
    _124
    charset = exc.headers.get_content_charset() if exc.headers else None
    _124
    if body:
    _124
    html_text = body.decode(charset or "utf-8", errors="replace")
    _124
    title = self._extract_title(html_text)
    _124
    except Exception:
    _124
    title = ""
    _124
    return {"url": url, "title": title, "status": str(exc.code)}
    _124
    _124
    except TimeoutError:
    _124
    return {"url": url, "title": "", "status": "timeout"}
    _124
    _124
    except URLError as exc:
    _124
    reason = getattr(exc, "reason", None)
    _124
    if isinstance(reason, TimeoutError):
    _124
    status = "timeout"
    _124
    else:
    _124
    status = "request_error"
    _124
    return {"url": url, "title": "", "status": status}
    _124
    _124
    except Exception:
    _124
    return {"url": url, "title": "", "status": "request_error"}
    _124
    _124
    def _extract_title(self, html_text: str) -> str:
    _124
    """Extract and normalize the HTML title from a document string."""
    _124
    if not html_text:
    _124
    return ""
    _124
    _124
    match = self.TITLE_PATTERN.search(html_text)
    _124
    if not match:
    _124
    return ""
    _124
    _124
    title = html.unescape(match.group(1))
    _124
    title = re.sub(r"\s+", " ", title).strip()
    _124
    return title

    To inspect the code, click View Code. To add the component to the canvas, click Add to Canvas.

  5. Connect the component to Chat Input and Chat Output components. At this point your flow has three connected components:

    • Chat Input sends the text that contains URLs into the URLTitleExtractor so the flow runs when you chat in the Playground or send a prompt from an app.
    • URLTitleExtractor reads that text, finds URLs, fetches each page, and outputs a Table with url, title, and status columns.
    • Chat Output receives URLTitleExtractor's result and displays the Table back to the user or calling application.

    A custom URL Title Extractor component connected to a chat input and chat output

  6. Open the Playground, and tell Langflow to check a list of URLs. For example:


    _10
    Check these links: https://langflow.org
    _10
    https://github.com/langflow-ai/langflow
    _10
    https://python.org
    _10
    https://this-domain-should-not-resolve-12345.invalid

  7. Run the flow. The output will be similar to the following, with a Table with one row per URL, including page titles and status codes.

    urltitlestatus
    https://langflow.orgLangflow | Low-code AI builder for agentic and RAG applications200
    https://github.com/langflow-ai/langflowGitHub - langflow-ai/langflow: Langflow is a powerful tool for building and deploying AI-powered agents and workflows. - GitHub200
    https://python.orgWelcome to Python.org200
    https://this-domain-should-not-resolve-12345.invalid
  8. To iterate further, tell Langflow Assistant what you want. For example, prompt it to Update URLTitleExtractor to add max_urls (default 5) and skip duplicates..

    Langflow Assistant generates an updated URLTitleExtractor component (again, the exact code may differ from a previous run).

  9. Replace the old component with the new component. Set max_urls to 3. In the Playground, enter a list that includes a duplicate URL and the invalid URL from before:


    _10
    Check these links: https://langflow.org
    _10
    https://github.com/langflow-ai/langflow
    _10
    https://python.org
    _10
    https://langflow.org
    _10
    https://this-domain-should-not-resolve-12345.invalid

  10. Run the flow. The output will be similar to the following, with the duplicate https://langflow.org removed and only 3 valid URLs displayed.

    urltitlestatus
    https://langflow.orgLangflow | Low-code AI builder for agentic and RAG applications200
    https://github.com/langflow-ai/langflowGitHub - langflow-ai/langflow: Langflow is a powerful tool for building and deploying AI-powered agents and workflows. - GitHub200
    https://python.orgWelcome to Python.org200
Search