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/blocks): add ConcatenateListsBlock (#11567)

Mewael Tsegay Desta2169b433c98a
diff --git a/autogpt_platform/backend/backend/blocks/data_manipulation.py b/autogpt_platform/backend/backend/blocks/data_manipulation.py
index 5864a517ed..1014236b8c 100644
--- a/autogpt_platform/backend/backend/blocks/data_manipulation.py
+++ b/autogpt_platform/backend/backend/blocks/data_manipulation.py
@@ -680,3 +680,58 @@ class ListIsEmptyBlock(Block):
async def run(self, input_data: Input, **kwargs) -> BlockOutput:
yield "is_empty", len(input_data.list) == 0
+
+
+class ConcatenateListsBlock(Block):
+ class Input(BlockSchemaInput):
+ lists: List[List[Any]] = SchemaField(
+ description="A list of lists to concatenate together. All lists will be combined in order into a single list.",
+ placeholder="e.g., [[1, 2], [3, 4], [5, 6]]",
+ )
+
+ class Output(BlockSchemaOutput):
+ concatenated_list: List[Any] = SchemaField(
+ description="The concatenated list containing all elements from all input lists in order."
+ )
+ error: str = SchemaField(
+ description="Error message if concatenation failed due to invalid input types."
+ )
+
+ def __init__(self):
+ super().__init__(
+ id="3cf9298b-5817-4141-9d80-7c2cc5199c8e",
+ description="Concatenates multiple lists into a single list. All elements from all input lists are combined in order.",
+ categories={BlockCategory.BASIC},
+ input_schema=ConcatenateListsBlock.Input,
+ output_schema=ConcatenateListsBlock.Output,
+ test_input=[
+ {"lists": [[1, 2, 3], [4, 5, 6]]},
+ {"lists": [["a", "b"], ["c"], ["d", "e", "f"]]},
+ {"lists": [[1, 2], []]},
+ {"lists": []},
+ ],
+ test_output=[
+ ("concatenated_list", [1, 2, 3, 4, 5, 6]),
+ ("concatenated_list", ["a", "b", "c", "d", "e", "f"]),
+ ("concatenated_list", [1, 2]),
+ ("concatenated_list", []),
+ ],
+ )
+
+ async def run(self, input_data: Input, **kwargs) -> BlockOutput:
+ concatenated = []
+ for idx, lst in enumerate(input_data.lists):
+ if lst is None:
+ # Skip None values to avoid errors
+ continue
+ if not isinstance(lst, list):
+ # Type validation: each item must be a list
+ # Strings are iterable and would cause extend() to iterate character-by-character
+ # Non-iterable types would raise TypeError
+ yield "error", (
+ f"Invalid input at index {idx}: expected a list, got {type(lst).__name__}. "
+ f"All items in 'lists' must be lists (e.g., [[1, 2], [3, 4]])."
+ )
+ return
+ concatenated.extend(lst)
+ yield "concatenated_list", concatenated
diff --git a/docs/CLAUDE.md b/docs/CLAUDE.md
new file mode 100644
index 0000000000..67cb1fc4f3
--- /dev/null
+++ b/docs/CLAUDE.md
@@ -0,0 +1,44 @@
+# Documentation Guidelines
+
+## Block Documentation Manual Sections
+
+When updating manual sections (`<!-- MANUAL: ... -->`) in block documentation files (e.g., `docs/integrations/basic.md`), follow these formats:
+
+### How It Works Section
+
+Provide a technical explanation of how the block functions:
+- Describe the processing logic in 1-2 paragraphs
+- Mention any validation, error handling, or edge cases
+- Use code examples with backticks when helpful (e.g., `[[1, 2], [3, 4]]` becomes `[1, 2, 3, 4]`)
+
+Example:
+```markdown
+<!-- MANUAL: how_it_works -->
+The block iterates through each list in the input and extends a result list with all elements from each one. It processes lists in order, so `[[1, 2], [3, 4]]` becomes `[1, 2, 3, 4]`.
+
+The block includes validation to ensure each item is actually a list. If a non-list value is encountered, the block outputs an error message instead of proceeding.
+<!-- END MANUAL -->
+```
+
+### Use Case Section
+
+Provide 3 practical use cases in this format:
+- **Bold Heading**: Short one-sentence description
+
+Example:
+```markdown
+<!-- MANUAL: use_case -->
+**Paginated API Merging**: Combine results from multiple API pages into a single list for batch processing or display.
+
+**Parallel Task Aggregation**: Merge outputs from parallel workflow branches that each produce a list of results.
+
+**Multi-Source Data Collection**: Combine data collected from different sources (like multiple RSS feeds or API endpoints) into one unified list.
+<!-- END MANUAL -->
+```
+
+### Style Guidelines
+
+- Keep descriptions concise and action-oriented
+- Focus on practical, real-world scenarios
+- Use consistent terminology with other blocks
+- Avoid overly technical jargon unless necessary
diff --git a/docs/integrations/README.md b/docs/integrations/README.md
index f954ac530f..e444757a49 100644
--- a/docs/integrations/README.md
+++ b/docs/integrations/README.md
@@ -31,6 +31,7 @@ Below is a comprehensive list of all available blocks, categorized by their prim
| [Agent Time Input](basic.md#agent-time-input) | Block for time input |
| [Agent Toggle Input](basic.md#agent-toggle-input) | Block for boolean toggle input |
| [Block Installation](basic.md#block-installation) | Given a code string, this block allows the verification and installation of a block code into the system |
+| [Concatenate Lists](basic.md#concatenate-lists) | Concatenates multiple lists into a single list |
| [Dictionary Is Empty](basic.md#dictionary-is-empty) | Checks if a dictionary is empty |
| [File Store](basic.md#file-store) | Stores the input file in the temporary directory |
| [Find In Dictionary](basic.md#find-in-dictionary) | A block that looks up a value in a dictionary, list, or object by key or index and returns the corresponding value |
diff --git a/docs/integrations/basic.md b/docs/integrations/basic.md
index 367299ffa7..f92d19002f 100644
--- a/docs/integrations/basic.md
+++ b/docs/integrations/basic.md
@@ -634,6 +634,42 @@ This enables extensibility by allowing custom blocks to be added without modifyi
---
+## Concatenate Lists
+
+### What it is
+Concatenates multiple lists into a single list. All elements from all input lists are combined in order.
+
+### How it works
+<!-- MANUAL: how_it_works -->
+The block iterates through each list in the input and extends a result list with all elements from each one. It processes lists in order, so `[[1, 2], [3, 4]]` becomes `[1, 2, 3, 4]`.
+
+The block includes validation to ensure each item is actually a list. If a non-list value (like a string or number) is encountered, the block outputs an error message instead of proceeding. None values are skipped automatically.
+<!-- END MANUAL -->
+
+### Inputs
+
+| Input | Description | Type | Required |
+|-------|-------------|------|----------|
+| lists | A list of lists to concatenate together. All lists will be combined in order into a single list. | List[List[Any]] | Yes |
+
+### Outputs
+
+| Output | Description | Type |
+|--------|-------------|------|
+| error | Error message if concatenation failed due to invalid input types. | str |
+| concatenated_list | The concatenated list containing all elements from all input lists in order. | List[Any] |
+
+### Possible use case
+<!-- MANUAL: use_case -->
+**Paginated API Merging**: Combine results from multiple API pages into a single list for batch processing or display.
+
+**Parallel Task Aggregation**: Merge outputs from parallel workflow branches that each produce a list of results.
+
+**Multi-Source Data Collection**: Combine data collected from different sources (like multiple RSS feeds or API endpoints) into one unified list.
+<!-- END MANUAL -->
+
+---
+
## Dictionary Is Empty
### What it is