Skip to content

Fix: Smolagents LiteLLMModel ChatMessage compatibility#3

Open
vinayak-shanawad wants to merge 1 commit intonicknochnack:mainfrom
vinayak-shanawad:fix-smolagents-compatibility
Open

Fix: Smolagents LiteLLMModel ChatMessage compatibility#3
vinayak-shanawad wants to merge 1 commit intonicknochnack:mainfrom
vinayak-shanawad:fix-smolagents-compatibility

Conversation

@vinayak-shanawad
Copy link

@vinayak-shanawad vinayak-shanawad commented Jul 21, 2025

Problem

The fastacp.py script was encountering AttributeError: 'dict' object has no attribute 'role' when interacting with smolagents.models.LiteLLMModel`.

Root Cause

This was due to a mismatch in the expected message format. LiteLLMModel expects smolagents.models.ChatMessage objects with their content structured as a list of dictionaries (even for pure text, e.g., [{"type": "text", "text": "our_message"}]), while the script was sometimes passing plain dictionaries or ChatMessage objects with string content.

Solution

This PR implements minimal changes to ensure all messages passed to LiteLLMModel are smolagents.models.ChatMessage instances, and their content attribute consistently follows the list[dict] format. Specifically:

  • Imported ChatMessage as SmolAgentsChatMessage and MessageRole from smolagents.models.
  • Modified MultiStepAgent.input_messages to explicitly store SmolAgentsChatMessage.
  • Updated MultiStepAgent.write_memory_to_messages to act as a guardian, converting messages to the correct SmolAgentsChatMessage object type and formatting content as list[dict] before passing to the model
  • Ensured all message creations in run and message appends in step use SmolAgentsChatMessage with content=[{"type": "text", "text": "..."}]
  • Adjusted parsing logic in step function to correctly extract text from the list[dict] model_message.content.

Link to issue: #2

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