Skip to content

Fix handling of text_message_outputs output structure in parallel translation example #1115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mshsheikh
Copy link
Contributor

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:

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:
  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.

…nslation example

**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.
@seratch seratch added documentation Improvements or additions to documentation needs-more-info Waiting for a reply/more info from the author labels Jul 14, 2025
@seratch
Copy link
Member

seratch commented Jul 14, 2025

Thanks for reporting this. I don't think this is the fundamental solution as the helper method is supposed to return a single string: https://github.com/openai/openai-agents-python/blob/v0.1.0/src/agents/items.py#L277-L284 could you help us identify the cause of the unexpected behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation needs-more-info Waiting for a reply/more info from the author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants