Skip to content

Fix/ handle different LLM encodings for listener IDs in speak_to#147

Open
gamal1osama wants to merge 5 commits intomesa:mainfrom
gamal1osama:fix/speak-to-normalize-ids
Open

Fix/ handle different LLM encodings for listener IDs in speak_to#147
gamal1osama wants to merge 5 commits intomesa:mainfrom
gamal1osama:fix/speak-to-normalize-ids

Conversation

@gamal1osama
Copy link
Contributor

@gamal1osama gamal1osama commented Mar 5, 2026

Description

The speak_to tool expects listener_agents_unique_ids to be a list[int], but LLMs often send it in different formats depending on how they serialize arguments:

  • As a stringified list: "[5, 9]" (the LLM JSON-encodes it twice by mistake)
  • As a bare integer: 5 (when there's only one recipient)
  • As None: happens occasionaly when the LLM forgets the arg

Without this fix, the code raises a TypeError (e.g. 'in <string>' requires string as left operand, not int) which gets caught by ToolManager._process_tool_call and returned to the LLM as a cryptic "Error: ..." — the message is never delivered and the LLM has no useful feedback to recover from.

This PR adds normalization logic to handle all three cases, so messages get through regaurdless of how the LLM formats the IDs.

Example scenarios that now work:

# LLM sends a stringified list (common in chain-of-thought outputs)
speak_to(agent, "[11, 12]", "hey")  # now works, was TypeError before

# LLM sends a bare int (when generating single-recipient calls)
speak_to(agent, 11, "hey")  # now works, was TypeError before

# LLM sends None
speak_to(agent, None, "hey")  # now gracefully handles it

Testing

Added 5 new tests covering every normalization branch:

Test What it covers
test_speak_to_accepts_stringified_list "[11, 12]" parsed via ast.literal_eval
test_speak_to_accepts_bare_int 11 wrapped to [11]
test_speak_to_handles_none_ids None treated as empty list
test_speak_to_handles_malformed_string_ids garbage string falls back to []
test_speak_to_handles_non_numeric_ids_in_list ["alice", "bob"]int() fails → []

The first two fail without this PR (raise TypeError), the last three cover the except/fallback branches for full patch coverage. All existing tests still pass.

@coderabbitai
Copy link

coderabbitai bot commented Mar 5, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d5bea293-b561-4843-8982-6b047e1063c7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Mar 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.17%. Comparing base (4ea91ed) to head (43c2e95).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #147      +/-   ##
==========================================
+ Coverage   90.08%   90.17%   +0.09%     
==========================================
  Files          19       19              
  Lines        1503     1517      +14     
==========================================
+ Hits         1354     1368      +14     
  Misses        149      149              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant