Langflow Beta 和 Legacy 功能说明
一、Show Beta 和 Show Legacy 功能分析
1. 核心定义位置
在 langflow/template/frontend_node/base.py 中定义:
class FrontendNode:
beta: bool = False
"""Whether the frontend node is in beta."""
# 前端节点是否处于 beta(测试)状态
legacy: bool = False
"""Whether the frontend node is legacy."""
# 前端节点是否为 legacy(遗留/废弃)状态
2. 功能用途对比
| 属性 | 用途 | 前端表现 |
|---|---|---|
| beta | 标记组件为实验性功能 | 显示 "Beta" 标签,警告用户该功能可能不稳定或有 bug |
| legacy | 标记组件为遗留/废弃功能 | 显示 "Legacy" 标签,提示用户这是旧版本组件,建议迁移到新版本 |
3. 具体作用
Beta (beta=True)
- 组件处于测试阶段
- 功能可能不完整或有已知问题
- 向用户提示:使用需谨慎,可能随时变化
- 例如:新开发的 AI 模型集成、实验性的数据处理节点
Legacy (legacy=True)
- 组件已被标记为废弃
- 通常存在更好的替代方案
- 向用户提示:建议迁移到新组件
- 例如:旧版本的 API 连接器、已被重构的数据转换节点
4. 使用场景示例
# 定义一个 Beta 组件
class NewExperimentalComponent(FrontendNode):
beta = True # 标记为实验性功能
legacy = False
# 定义一个 Legacy 组件
class OldDeprecatedComponent(FrontendNode):
beta = False
legacy = True # 标记为已废弃
5. 与 Feature Flags 的区别
在 feature_flags.py 中定义的是全局功能开关:
class FeatureFlags(BaseSettings):
mvp_components: bool = False # 控制是否显示 MVP 组件
而 beta/legacy 是单个组件级别的状态标记,控制组件在前端的展示和分类。
6. 总结
这两个属性帮助 Langflow 用户:
- 识别功能成熟度 - 区分稳定版、测试版、废弃版
- 降低使用风险 - Beta 功能有明确警告
- 引导迁移 - Legacy 组件提示用户升级
- 组织组件库 - 按状态筛选和分类组件
二、PythonCodeStructuredTool 迁移指南
1. 废弃声明
在 langflow/components/tools/python_code_structured_tool.py:40-41 中:
legacy: bool = True
replacement = ["processing.PythonREPLComponent"]
2. 迁移路径
| 属性 | 旧组件 | 新组件 |
|---|---|---|
| 名称 | PythonCodeStructuredTool | Python Interpreter |
| 路径 | tools/PythonCodeStructuredTool | processing/PythonREPLComponent |
| 图标 | Python | square-terminal |
| 用途 | 创建结构化工具 | 执行 Python 代码 |
3. 新组件功能
class PythonREPLComponent(Component):
display_name = "Python Interpreter"
description = "Run Python code with optional imports. Use print() to see the output."
输入参数:
| 参数 | 说明 |
|---|---|
| Global Imports | 全局导入模块(如 math,numpy,pandas) |
| Python Code | 要执行的 Python 代码 |
输出:
| 输出 | 类型 | 说明 |
|---|---|---|
| Results | Data | 执行结果 |
4. 迁移原因
PythonCodeStructuredTool 基于 LangChain 的 StructuredTool,需要定义 dataclass 结构,使用复杂。
而 PythonREPLComponent 更简单直接:
# 旧方式 - 需要定义复杂的 dataclass
def my_function(args: SomeSchema):
pass
# 新方式 - 直接写代码
print('Hello, World!')
result = some_calculation()
5. 迁移步骤
- 删除
PythonCodeStructuredTool节点 - 添加
Python Interpreter节点(在 Processing 分类下) - 配置 全局导入(如
math,pandas,numpy) - 编写 Python 代码(无需复杂结构定义)
- 使用
print()输出结果
6. 代码示例对比
旧组件 (PythonCodeStructuredTool):
# 需要定义 dataclass 结构
from dataclasses import dataclass
@dataclass
class ToolArgs:
x: int
y: int
def calculate(args: ToolArgs) -> str:
return str(args.x + args.y)
新组件 (Python Interpreter):
# 直接编写代码
x = 5
y = 3
result = x + y
print(result)
相关文件
langflow/template/frontend_node/base.py- FrontendNode 基类定义langflow/components/tools/python_code_structured_tool.py- 旧组件(已废弃)langflow/components/processing/python_repl_core.py- 新组件(替代方案)langflow/services/settings/feature_flags.py- 全局功能开关