Langflow is a powerful tool for building and deploying AI-powered agents and workflows. http://www.langflow.org
Find a file
Gabriel Luiz Freitas Almeida 270f609fe7
refactor: enhance tool creation logic and add FeatureFlags (#3662)
* Add `required_inputs` field to `Output` model in `base.py`

* Refactor ComponentTool to ComponentToolkit and enhance tool creation logic

- Replaced `ComponentTool` with `ComponentToolkit` to better encapsulate component-related tools.
- Introduced `build_description` and `_build_output_function` helper functions for dynamic tool creation.
- Updated tool initialization to handle multiple outputs and required inputs using `StructuredTool`.
- Improved schema creation for tool arguments based on component inputs.

* Refactor `to_tool` method to `to_toolkit` to use `ComponentToolkit` instead of `ComponentTool`

* Refactor `ComponentTool` to `ComponentToolkit` in unit tests

- Updated import statements to reflect the new `ComponentToolkit` class.
- Modified test logic to use `ComponentToolkit` for retrieving tools.
- Adjusted assertions to match the new structure and output format.
- Ensured compatibility with `Message` schema for output validation.

* Refactor `test_component_to_tool` to validate `ComponentToolkit` and tool properties

* Refactor `build_description` to include input types in the output format

* Add method to set required inputs for outputs based on method analysis

- Introduced `_set_output_required_inputs` method to determine and set required inputs for each output by analyzing the method's source code.
- Added necessary imports (`ast` and `dedent`) to support the new functionality.

* Update test to assert full tool description in test_component_to_tool.py

* Add unit tests for verifying required inputs of various components

- Added tests to ensure that required inputs for outputs are present in the inputs of `ChatInput`, `ChatOutput`, `SequentialTaskComponent`, `ToolCallingAgentComponent`, and `OpenAIModelComponent`.
- Included helper functions to check if required inputs are in inputs and to assert that all outputs have different required inputs.

* Add RequiredInputsVisitor to identify required inputs in AST nodes

- Introduced RequiredInputsVisitor class to traverse AST nodes and collect required inputs.
- The visitor checks for 'self' attributes matching the provided inputs and adds them to the required_inputs set.

* Refactor required inputs extraction using `RequiredInputsVisitor`

* Add feature flags configuration for toolkit output in settings

* Add toolkit output handling based on feature flag in custom component utils

* Add method to append 'component_as_tool' output in custom component

* Add unit test for toolkit output feature flag in custom component

* Add utility functions for lazy loading and instantiating input types in langflow

- Introduced `get_InputTypesMap` for lazy loading of `InputTypesMap`.
- Added `instantiate_input` function to create instances of input types dynamically.
- Included type checking and error handling for invalid input types.

* Refactor input instantiation logic and update imports

- Removed `instantiate_input` function from `inputs.py` and moved it to `utils.py`.
- Updated imports in `base.py` to reflect the new location of `instantiate_input`.
- Added missing import for `Callable` in `base.py`.

* Refactor import statement to use `instantiate_input` from `langflow.inputs.utils` in test_inputs.py

* Add TOOL_OUTPUT_NAME constant to tools module

* Add type checking and TOOL_OUTPUT_NAME filter in ComponentToolkit

- Introduced `TYPE_CHECKING` for type hints to avoid circular imports.
- Added `TOOL_OUTPUT_NAME` constant to filter specific outputs in `ComponentToolkit`.
- Updated type annotations to use forward references.

* Refactor component toolkit import to avoid circular dependency and use constant for tool output name

* Refactor `ComponentToolkit` class to remove inheritance from `BaseToolkit` and add an initializer for `component`

* Add unit test for ComponentToolkit in test_component_to_tool

- Added `test_component_to_tool_has_no_component_as_tool` to verify that `ComponentToolkit` correctly initializes with a `ChatInput` component and returns the expected tools.

* Refactor toolkit output handling to `custom_component` module

* fix: mypy errors union-attr and arg-type

* Add 'OTHER' field type to schema in langflow/io/schema.py

* Add tool name formatting to ComponentToolkit to ensure valid characters

* Refactor toolkit output handling and add type hint for `to_toolkit` method

* Add `is_interface_component` attribute to vertex types and update import order

* Add tests for ToolCallingAgentComponent and ChatOutput with API key handling

- Updated `test_component_tool` to reflect new description format.
- Added `test_component_tool_with_api_key` to test `ToolCallingAgentComponent` with `ChatOutput` and OpenAI API key.
- Enabled `add_toolkit_output` feature flag for testing.

* Refactor `_find_matching_output_method` to accept `input_name` parameter for more precise input-output matching

* Replace ValueError with warning in build_description function

* use chat_output component directly in set

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes (attempt 3/3)

* Refactor: Reorder method calls in `__init__` for logical consistency

Moved `set_class_code` method call to ensure output types and required inputs are set before class code initialization.

* Update _format_tool_name to allow '.' in tool names

* Refactor `_format_tool_name` to remove non-alphanumeric characters

* Update test assertions for component tool name and output mapping

* Handle case where 'required_inputs' is empty in 'component_tool.py'

* Refactor import statements for better readability in `base.py`

* [autofix.ci] apply automated fixes

* Add noqa comment to suppress import warning and re-add Any import in base.py

---------

Co-authored-by: italojohnny <italojohnnydosanjos@gmail.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-10-01 20:58:51 +00:00
.devcontainer Update Python base image to version 3.10 in devcontainer.json 2024-04-17 11:21:05 -03:00
.github build(deps):(deps): bump peter-evans/create-pull-request from 6 to 7 (#3976) 2024-10-01 18:31:30 +00:00
.vscode feat: import Graph without position information (#3203) 2024-08-07 07:04:48 -07:00
deploy fix: fix docker compose and add instructions (#2654) 2024-07-12 09:27:13 -07:00
docker chore: update docker images to use uv (#3916) 2024-09-30 22:49:25 +00:00
docker_example feat: add pull_policy to Docker compose example (#3693) 2024-09-06 10:41:47 -07:00
docs fix: enhancements for the AssemblyAI component (#3934) 2024-10-01 14:28:18 +00:00
scripts chore: uv to replace poetry (#3900) 2024-09-25 13:40:30 -07:00
src refactor: enhance tool creation logic and add FeatureFlags (#3662) 2024-10-01 20:58:51 +00:00
.env.example fixing ThreadingInMemoryCache usage (#2604) 2024-07-10 04:52:37 -07:00
.eslintrc.json 🔧 (.pre-commit-config.yaml): Add eslint@9.1.1 as a dependency and enable autofix for pretty-format-json hook 2024-05-02 19:27:40 -03:00
.gitattributes Merge cz/mergeAll to two_edges 2024-06-10 11:31:02 -03:00
.gitignore fix: security file upload (#3923) 2024-09-30 19:14:03 +00:00
.pre-commit-config.yaml feat: Add pre-commit hook for ruff (#3960) 2024-10-01 12:50:19 +02:00
CODE_OF_CONDUCT.md run codespell 2024-06-04 09:26:13 -03:00
CONTRIBUTING.md docs: Update CONTRIBUTING.md to mention uv (#3965) 2024-09-30 12:23:35 -07:00
eslint.config.js 🔧 (.pre-commit-config.yaml): Add eslint@9.1.1 as a dependency and enable autofix for pretty-format-json hook 2024-05-02 19:27:40 -03:00
LICENSE Update organization name and URLs in configuration files 2024-04-18 11:58:19 -03:00
Makefile chore: update docker images to use uv (#3916) 2024-09-30 22:49:25 +00:00
poetry.lock chore: drop duckdb usage and migrations (#3730) 2024-09-26 11:48:35 +00:00
pyproject.toml fix: enhancements for the AssemblyAI component (#3934) 2024-10-01 14:28:18 +00:00
README.ES.md docs: Added Spanish README (#3451) 2024-08-20 11:41:13 -07:00
README.ja.md docs: Added Spanish README (#3451) 2024-08-20 11:41:13 -07:00
README.KR.md docs: Added Spanish README (#3451) 2024-08-20 11:41:13 -07:00
README.md docs: update integrations image (#3508) 2024-08-22 16:57:34 +00:00
README.PT.md docs: Added Spanish README (#3451) 2024-08-20 11:41:13 -07:00
README.zh_CN.md docs: Added Spanish README (#3451) 2024-08-20 11:41:13 -07:00
render.yaml docs: fix render deployment and docs (#3309) 2024-08-14 03:45:56 -07:00
uv.lock fix: enhancements for the AssemblyAI component (#3934) 2024-10-01 14:28:18 +00:00

Langflow

Langflow is a low-code app builder for RAG and multi-agent AI applications. Its Python-based and agnostic to any model, API, or database.

Docs - Free Cloud Service - Self Managed

README in English README in Portuguese README in Spanish README in Simplified Chinese README in Japanese README in KOREAN

Core features

  1. Python-based and agnostic to models, APIs, data sources, or databases.
  2. Visual IDE for drag-and-drop building and testing of workflows.
  3. Playground to immediately test and iterate workflows with step-by-step control.
  4. Multi-agent orchestration and conversation management and retrieval.
  5. Free cloud service to get started in minutes with no setup.
  6. Publish as an API or export as a Python application.
  7. Observability with LangSmith, LangFuse, or LangWatch integration.
  8. Enterprise-grade security and scalability with free DataStax Langflow cloud service.
  9. Customize workflows or create flows entirely just using Python.
  10. Ecosystem integrations as reusable components for any model, API or database.

Integrations

📦 Quickstart

  • Install with pip (Python 3.10 or greater):
pip install langflow

Getting Started

Stay up-to-date

Star Langflow on GitHub to be instantly notified of new releases.

Star Langflow

👋 Contribute

We welcome contributions from developers of all levels. If you'd like to contribute, please check our contributing guidelines and help make Langflow more accessible.


Star History Chart

❤️ Contributors

langflow contributors