Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(swarm): prevent KeyError when converting assistant messages without tool calls - #2850

Open
saitejabandaru-in wants to merge 1 commit into
vibrantlabsai:mainfrom
saitejabandaru-in:fix/swarm-converter-keyerror-and-vertexai-import
Open

fix(swarm): prevent KeyError when converting assistant messages without tool calls#2850
saitejabandaru-in wants to merge 1 commit into
vibrantlabsai:mainfrom
saitejabandaru-in:fix/swarm-converter-keyerror-and-vertexai-import

Conversation

@saitejabandaru-in

Copy link
Copy Markdown

Resolves #2813.

Description

OpenAI Swarm assistant messages that do not make tool calls typically contain only role and content keys. When converted using convert_to_ragas_messages(), it was accessing message["tool_calls"] directly, raising a KeyError.

Also, importing ChatVertexAI and VertexAI directly from langchain_community raises ModuleNotFoundError on modern langchain environments because those modules were sunset or relocated.

Changes

  • Updated handle_assistant_message() in swarm.py to use .get("tool_calls") instead of direct index access.
  • Added safe try-except fallback imports for ChatVertexAI and VertexAI in ragas/llms/base.py to fallback to langchain-google-vertexai if available.
  • Added a new unit test suite in tests/unit/integrations/test_swarm.py validating Swarm message conversion with and without tool calls.

…ut tool calls and fallback VertexAI imports
@github-actions

Copy link
Copy Markdown

✅ No documentation update needed — Internal bug fixes only (KeyError guard in swarm converter, VertexAI import fallback) with no user-facing API or usage changes; existing docstrings are unaffected.

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.

Swarm converter raises KeyError for assistant messages without tool_calls

1 participant