Skip to content

Commit f43956e

Browse files
committed
Fix ChatAgent.step crash when input_message is None or empty
1 parent 0f91a19 commit f43956e

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

camel/agents/chat_agent.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,6 +2855,20 @@ def step(
28552855

28562856
stream = self.model_backend.model_config_dict.get("stream", False)
28572857

2858+
if input_message is None or (
2859+
isinstance(input_message, str) and not input_message.strip()
2860+
):
2861+
return ChatAgentResponse(
2862+
msgs=[
2863+
BaseMessage.make_assistant_message(
2864+
role_name="assistant",
2865+
content="Please provide a valid input."
2866+
)
2867+
],
2868+
terminated=False,
2869+
info={"error": "empty_input"}
2870+
)
2871+
28582872
if stream:
28592873
# Return wrapped generator that has ChatAgentResponse interface
28602874
generator = self._stream(input_message, response_format)

0 commit comments

Comments
 (0)