From e28eec6ff9bb2fce05dc7a3123453ab72081ffd3 Mon Sep 17 00:00:00 2001 From: Swifty Date: Mon, 21 Jul 2025 11:48:30 +0200 Subject: [PATCH] feat(backend): Add ReverseListOrderBlock for reversing list element order (#10352) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Changes 🏗️ This PR adds a new utility block to the basic blocks collection. This block provides a simple way to reverse the order of elements in any list. **New Features:** - Added class in - Block accepts any list as input and returns the same list with elements in reversed order - Preserves the original list (creates a copy before reversing) - Works with lists containing any type of elements **Technical Details:** - Block ID: - Category: - Input: - The list to reverse (accepts ) - Output: - The list with elements in reversed order - Includes test input/output for validation ### Checklist 📋 #### For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [x] I have tested my changes according to the test plan: - [x] Created an agent with the ReverseListOrderBlock - [x] Tested with various list types (numbers, strings, mixed types) - [x] Verified the block preserves the original list - [x] Confirmed the block correctly reverses the order of elements - [x] Tested with empty lists and single-element lists - [x] Verified the block integrates properly with other blocks in a workflow #### For configuration changes: - [x] is updated or already compatible with my changes - [x] is updated or already compatible with my changes - [x] I have included a list of my configuration changes in the PR description (under **Changes**) **Note:** No configuration changes required - this is a pure code addition that uses the existing block framework. Co-authored-by: Abhimanyu Yadav <122007096+Abhi1992002@users.noreply.github.com> --- .../backend/backend/blocks/basic.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) 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