Skip to content

feat: add serve command to CLI #8862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 62 commits into
base: main
Choose a base branch
from
Draft

Conversation

ogabrielluiz
Copy link
Contributor

@ogabrielluiz ogabrielluiz commented Jul 3, 2025

This pull request introduces several updates to the Langflow project, including enhancements to the CLI, new functionality for executing Langflow graphs, and backend improvements. The most significant changes are the addition of the execute command for running Langflow graphs from the CLI, the introduction of MCP server support, and improvements to the backend for better type safety and functionality.

CLI Enhancements:

  • Added a new execute command to the CLI, allowing users to run Langflow graphs directly from Python scripts or JSON files. This includes support for input values, diagnostic output, and multiple output formats such as JSON and plain text. (src/backend/base/langflow/__main__.py, docs/docs/Configuration/configuration-cli.md, [1] [2]
  • Introduced a script_loader module with utilities for loading and validating Python scripts containing Langflow graph variables. This includes functionality for extracting structured results and handling errors gracefully. (src/backend/base/langflow/cli/script_loader.py, src/backend/base/langflow/cli/script_loader.pyR1-R237)

Backend Improvements:

MCP Server Support:

  • Added an MCP server implementation for Langflow CLI, enabling the use of Langflow's MCP infrastructure for serverless and containerized environments. This includes support for SSE transport and integration with FastAPI. (src/backend/base/langflow/cli/mcp_server.py, src/backend/base/langflow/cli/mcp_server.pyR1-R53)

CI Workflow Update:

  • Added a new test-frontend-unit job to the CI workflow to run frontend unit tests separately, improving test coverage and modularity. (.github/workflows/ci.yml, .github/workflows/ci.ymlR175-R180)

ogabrielluiz and others added 30 commits July 1, 2025 09:03
This commit introduces a new module for loading and validating Python scripts containing Langflow graph variables. It includes functions for dynamically importing scripts, validating graph instances, and extracting messages from results, enhancing the CLI's functionality.
… graph variables

This commit introduces a new CLI command that allows users to analyze a Python script for a 'graph' variable, validate its type, and execute it to retrieve results. The command includes error handling for file existence, type checks, and provides informative output about the graph variable found in the script.
…cript outputs

This commit introduces two new functions, `extract_text_from_result` and `extract_structured_result`, to enhance the processing of results from Langflow CLI scripts. These functions extract text content and structured data, respectively, while implementing error handling for improved robustness.
…mproved output formatting

This commit updates the CLI command to execute Langflow graph scripts, adding options for verbose output and customizable result formats (json, text, message, or result). It improves error handling and captures logs during execution, providing a more informative user experience. The command now returns results in the specified format, enhancing usability in various environments.
…ully

This commit modifies the `end_tracers` method in the TracingService class to return early instead of raising an error when no trace context is found. This change improves the robustness of the tracing functionality by preventing unnecessary exceptions in scenarios where tracing is not active.
This commit updates the TracingService class to log warnings instead of raising RuntimeErrors when the trace context is not found in various methods. This change enhances the robustness of the service by allowing it to handle missing contexts gracefully, preventing unnecessary exceptions and improving overall stability.
…h execution

This commit enhances the existing CLI command to allow execution of Langflow graphs defined in JSON files, in addition to Python scripts. It improves error handling for file type validation and provides informative output during the analysis and execution process. The command now accommodates both .py and .json file formats, enhancing usability and flexibility for users.
This commit refactors the verbose output handling in the Langflow CLI command by introducing a dedicated `verbose_print` function. This change centralizes the logic for printing diagnostic messages, enhancing code readability and maintainability. Additionally, it ensures that all relevant error messages and execution details are consistently printed to stderr when verbose mode is enabled, improving the user experience during script analysis and execution.
This commit introduces a suite of tests for the Langflow CLI call command, enhancing coverage for various scenarios including valid and invalid Python scripts, JSON flows, and error handling for nonexistent or unsupported file types. New fixtures are added to create temporary scripts for testing, ensuring robust validation of output formats and error messages. The tests improve the reliability of the CLI command and provide a foundation for future enhancements.
This commit introduces detailed documentation for the new `langflow call` command, which allows users to execute Langflow graphs directly from the command line using Python scripts or JSON flow files. The documentation includes usage examples, argument descriptions, and available output formats, enhancing user understanding and accessibility of the CLI functionality.
…` to `execute`

This commit updates the documentation for the Langflow CLI, changing references from the `langflow call` command to the new `langflow execute` command. The documentation now accurately describes the command's functionality, usage examples, and available options, ensuring clarity for users. Additionally, the command's arguments and output formats have been revised to align with the new naming convention.
…for execution

This commit modifies the basic_prompting script to utilize the GPT-4.1-nano model for improved performance. Additionally, it introduces a new test fixture for executing the basic prompting graph, ensuring that the functionality works as expected. A test case is added to validate the execution of the graph, enhancing overall test coverage and reliability.
This commit introduces a new configuration option, `load_from_db`, to the OpenAIModelComponent. This enhancement allows the component to load the API key directly from the database, improving flexibility in managing sensitive credentials. The change aims to streamline the setup process for users while maintaining security best practices.
…pdate_params_with_load_from_db_fields

This commit introduces a new function, `load_from_env_vars`, which allows parameters to be populated from environment variables when the database is unavailable. Additionally, it updates the `update_params_with_load_from_db_fields` function to utilize this new functionality, enhancing the robustness of parameter loading in scenarios where database access is not possible. The changes improve flexibility and error handling for missing environment variables.
This commit introduces comprehensive validation for JSON responses in the CLI tests related to the execute command. It replaces previous JSON parsing logic with a dedicated validation function, `validate_execute_command_json_response`, ensuring that responses adhere to expected structures and types. Additionally, new test cases are added to validate both successful and error responses, improving test coverage and robustness in handling various output scenarios.
* test: add pyleak for task and event loop block detections

* test: add pyleak for task and event loop block detections

* ci: add env variables for verbose logging

* chore: dummy sleep to shwocase error

* chore: dummy sleep to showcase error

* chore: remove dummy sleep
…meter render logic (#8493)

* fix: enhance dropdown component with refresh button and clean up parameter render logic

- Added a refresh button to the dropdown component, improving user interaction.
- Refactored parameter render component to remove unnecessary wrapping around the render function.
- Updated package-lock.json to remove extraneous dependencies.

* [autofix.ci] apply automated fixes

* refactor(OutputComponent): replace DropdownMenu with Popover and Command components

- Updated OutputComponent to use Popover and Command components for improved UI interaction.
- Refactored dropdown logic to enhance accessibility and user experience.
- Added a reference for the button to manage focus visibility.

* refactor: update Memory Chatbot configuration and remove unused RefreshParameterComponent

- Changed display names and output methods in Memory Chatbot JSON configuration for clarity and consistency.
- Introduced a new output method for retrieving messages as text.
- Removed the RefreshParameterComponent and its references from the parameter render component to streamline the codebase.

* refactor: update dropdown component layout for improved styling

- Changed the layout classes in the dropdown component to enhance responsiveness and visual consistency.
- Adjusted flex properties to ensure proper alignment and spacing based on the presence of filtered metadata.

* refactor: streamline dropdown component structure and enhance button functionality

- Removed redundant rendering functions for refresh and custom option dialogs, integrating them directly into the dropdown's main structure.
- Improved layout and styling for better responsiveness and visual consistency.
- Adjusted class names for better alignment and spacing, particularly in relation to filtered metadata.
- Ensured the refresh button is consistently displayed based on dialog input conditions.

* refactor: enhance dropdown component styling for better readability

- Updated text size in dropdown options for improved visibility.
- Increased padding in command items for better touch targets and visual consistency.

* refactor: adjust dropdown component styling for improved usability

- Reduced padding in the search input for a more compact design.
- Updated text size in the search input for better readability.
- Enhanced layout of filtered metadata display for clearer visibility.

* refactor: enhance dropdown component rendering and styling

- Added console log for filtered metadata to assist in debugging.
- Adjusted class names in dropdown options for better responsiveness based on filtered metadata length.

* feat: add data-testid attributes for refresh buttons and simplify memoization in ParameterRenderComponent

- Added data-testid attributes to refresh buttons in Dropdown component for improved testability.
- Removed unnecessary useMemo in ParameterRenderComponent to streamline rendering logic.
- Introduced a new test for the refresh dropdown list functionality to ensure proper behavior.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
✨ (frontend): add CustomTermsLinks component to GeneralPage to display custom terms links in the settings page.
🐛 (code-tabs.tsx): fix button positioning by adjusting right margin to 4px instead of 2px
Changed run flow to not group outputs
…8815)

* chore: add jest-junit dependency for improved test reporting

- Updated package.json and package-lock.json to include jest-junit version 16.0.0, enhancing test reporting capabilities in the project.

* chore: enhance Jest configuration for improved test coverage and CI reporting

- Added coverage collection settings, including coverage thresholds and report formats.
- Configured CI-specific options for Jest, including the use of jest-junit for test reporting and adjusted worker settings for better performance in CI environments.

* chore: update frontend test command for CI mode to ensure proper environment variable usage

- Modified the test command in the Makefile to set CI=true for accurate test execution in CI environments.

* chore: enhance frontend CI workflow with test reporting and coverage uploads

- Replaced the frontend dependency installation step with a command to run unit tests in CI mode.
- Added steps to publish test results using junit report and to comment on pull requests with coverage summaries.
- Implemented artifact upload for coverage reports to improve visibility and tracking of test coverage over time.

* chore: add frontend dependency installation step to CI workflow

- Introduced a step to install frontend dependencies using npm ci in the GitHub Actions workflow.
- This enhancement ensures that all necessary packages are available before running frontend unit tests, improving the reliability of the CI process.

* chore: update junit report action version in CI workflow

- Upgraded the junit report action from v5 to v5.5.1 in the GitHub Actions workflow to leverage the latest features and improvements for test result reporting.

* chore: add Jest unit test workflow for frontend

- Introduced a new GitHub Actions workflow to run Jest unit tests for the frontend.
- The workflow includes steps for checking out the repository, setting up the Node.js environment, running tests, publishing test results, adding coverage comments on pull requests, and uploading coverage reports.
- This enhancement improves the CI process by ensuring comprehensive testing and reporting for frontend components.

* chore: integrate Jest unit tests into CI workflow

- Added a new job to the CI workflow to run frontend unit tests using Jest.
- Updated the changes filter to include Jest test files, ensuring they are recognized during the CI process.
- This enhancement improves the testing coverage and reliability of the frontend components.
@github-actions github-actions bot added the enhancement New feature or request label Jul 4, 2025
Copy link
Contributor

github-actions bot commented Jul 4, 2025

Build successful! ✅
Deploying docs draft.
Deploy successful! View draft

@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 4, 2025
Copy link
Contributor

github-actions bot commented Jul 4, 2025

Build successful! ✅
Deploying docs draft.
Deploy successful! View draft

- Introduced comprehensive unit tests for the MCP server functionality, including model validation and server creation.
- Added tests for the serve components, covering FastAPI app creation, endpoint functionality, and error handling.
- Enhanced test coverage for Pydantic models related to flow input, output, and metadata.
- Implemented integration tests to ensure seamless interaction between components.
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 4, 2025
Copy link
Contributor

github-actions bot commented Jul 4, 2025

Build successful! ✅
Deploying docs draft.
Deploy successful! View draft

- Updated the help descriptions for the execute and serve commands to provide clearer guidance on their functionality and intended use in containers and serverless environments.
- Simplified the docstring for the execute command while retaining essential information about its purpose and input parameters.
- Enhanced the exception handling in the execute_graph_with_capture function to capture and include stderr output in raised exceptions for better debugging.
- Updated the function's docstring to reflect the new behavior of re-raising exceptions with additional context.
…uration

- Condensed the docstring for the serve_command function to focus on key functionalities, including support for single files, folders, and GitHub repositories.
- Added an environment variable to disable pretty logs for the serve command, ensuring cleaner API responses.
- Improved error handling in the run_flow function to return detailed error messages and full tracebacks in API responses instead of raising HTTP exceptions.
- Added debug logging to capture flow execution results and logs, providing better insights during execution.
- Ensured that error logs include context when flow execution fails, enhancing debuggability.
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 4, 2025
Copy link
Contributor

github-actions bot commented Jul 4, 2025

Build successful! ✅
Deploying docs draft.
Deploy successful! View draft

@ogabrielluiz ogabrielluiz changed the title feat: add deploy command to CLI feat: add serve command to CLI Jul 4, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 4, 2025
…rve_command

- Implemented a new function to extract module-level docstrings from Python files, enhancing the serve_command functionality.
- Updated serve_command to process both JSON and Python files, providing detailed logging for each flow preparation.
- Improved error handling and logging for loading Python flows, ensuring better visibility into potential issues.
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 4, 2025
Copy link
Contributor

github-actions bot commented Jul 4, 2025

Build successful! ✅
Deploying docs draft.
Deploy successful! View draft

@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 4, 2025
Copy link
Contributor

github-actions bot commented Jul 4, 2025

Build successful! ✅
Deploying docs draft.
Deploy successful! View draft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants