Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions haystack/components/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,12 @@ def _initialize_fresh_execution(
system_prompt = system_prompt or self.system_prompt
messages = messages or []

if not isinstance(messages, list):
raise TypeError(
f"Agent component expects list[ChatMessage] for 'messages', got {type(messages).__name__}. "
"Check that the 'messages' input is correctly wired in the pipeline."
)

if user_prompt is not None:
if self._user_chat_prompt_builder is None:
raise ValueError(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Agent component now raises a clear TypeError when the `messages` input is not a list
(e.g. a string wired from an upstream component), instead of failing with the opaque
"can only concatenate list (not 'str') to list" error.
6 changes: 6 additions & 0 deletions test/components/agents/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,12 @@ def test_run_no_messages(self, monkeypatch):
result = agent.run([])
assert result["messages"] == []

def test_run_messages_string_raises_type_error(self):
chat_generator = MockChatGeneratorWithoutRunAsync()
agent = Agent(chat_generator=chat_generator, tools=[], system_prompt="You are helpful.")
with pytest.raises(TypeError, match="Agent component expects list\\[ChatMessage\\] for 'messages', got str"):
agent.run("this is a string not a list")

def test_run_only_system_prompt(self, caplog):
chat_generator = MockChatGeneratorWithoutRunAsync()
agent = Agent(chat_generator=chat_generator, tools=[], system_prompt="This is a system prompt.")
Expand Down
Loading