Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

feat(backend): Add ReverseListOrderBlock for reversing list element order (#10352)

Swiftye28eec6ff9bb
diff --git a/autogpt_platform/backend/backend/blocks/basic.py b/autogpt_platform/backend/backend/blocks/basic.py
index 1ac6abfc8c..ef251489c7 100644
--- a/autogpt_platform/backend/backend/blocks/basic.py
+++ b/autogpt_platform/backend/backend/blocks/basic.py
@@ -188,3 +188,31 @@ class UniversalTypeConverterBlock(Block):
yield "value", converted_value
except Exception as e:
yield "error", f"Failed to convert value: {str(e)}"
+
+
+class ReverseListOrderBlock(Block):
+ """
+ A block which takes in a list and returns it in the opposite order.
+ """
+
+ class Input(BlockSchema):
+ input_list: list[Any] = SchemaField(description="The list to reverse")
+
+ class Output(BlockSchema):
+ reversed_list: list[Any] = SchemaField(description="The list in reversed order")
+
+ def __init__(self):
+ super().__init__(
+ id="422cb708-3109-4277-bfe3-bc2ae5812777",
+ description="Reverses the order of elements in a list",
+ categories={BlockCategory.BASIC},
+ input_schema=ReverseListOrderBlock.Input,
+ output_schema=ReverseListOrderBlock.Output,
+ test_input={"input_list": [1, 2, 3, 4, 5]},
+ test_output=[("reversed_list", [5, 4, 3, 2, 1])],
+ )
+
+ async def run(self, input_data: Input, **kwargs) -> BlockOutput:
+ reversed_list = list(input_data.input_list)
+ reversed_list.reverse()
+ yield "reversed_list", reversed_list