From dc9d7985ae1ece214cff32fb3425ea8be807fa45 Mon Sep 17 00:00:00 2001 From: MUHAMMAD SALMAN HUSSAIN <160324527+mshsheikh@users.noreply.github.com> Date: Tue, 15 Jul 2025 03:58:25 +0500 Subject: [PATCH] Fix handling of text_message_outputs output structure in parallel translation example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Problem**: The code assumed `ItemHelpers.text_message_outputs()` returned a single string per result (e.g., `"Hola mundo"`), but it actually returns a **list of strings** (e.g., `["Hola", "Mundo"]`). This caused a `TypeError` when joining outputs. **Example of Failure**: ```python outputs = [ ["Hola", "Mundo"], # From text_message_outputs ["Buenos días"], ["Cómo estás"], ] translations = "\n\n".join(outputs) # ❌ TypeError: can't join list to str ``` **Changes**: - Wrap `text_message_outputs(...)` with `" ".join(...)` to safely flatten each agent’s output into a single string: ```python outputs = [ " ".join(ItemHelpers.text_message_outputs(res_1.new_items)), " ".join(ItemHelpers.text_message_outputs(res_2.new_items)), " ".join(ItemHelpers.text_message_outputs(res_3.new_items)), ] ``` **Benefits**: - Prevents `TypeError` by ensuring all outputs are strings. - Maintains consistent formatting for the final joined output. - Makes the example robust and easier to understand for users. This change ensures the parallel translation workflow works reliably, even when agent outputs vary in structure. --- examples/agent_patterns/parallelization.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/agent_patterns/parallelization.py b/examples/agent_patterns/parallelization.py index fe2a8ecd0..b5210d6a3 100644 --- a/examples/agent_patterns/parallelization.py +++ b/examples/agent_patterns/parallelization.py @@ -39,9 +39,9 @@ async def main(): ) outputs = [ - ItemHelpers.text_message_outputs(res_1.new_items), - ItemHelpers.text_message_outputs(res_2.new_items), - ItemHelpers.text_message_outputs(res_3.new_items), + " ".join(ItemHelpers.text_message_outputs(res_1.new_items)), + " ".join(ItemHelpers.text_message_outputs(res_2.new_items)), + " ".join(ItemHelpers.text_message_outputs(res_3.new_items)), ] translations = "\n\n".join(outputs)