|
12 | 12 | from haystack.core.pipeline.pipeline import Pipeline |
13 | 13 | from haystack.core.pipeline.utils import _deepcopy_with_exceptions |
14 | 14 | from haystack.core.serialization import component_to_dict |
15 | | -from haystack.dataclasses import ChatMessage |
| 15 | +from haystack.dataclasses import ChatMessage, ChatRole |
16 | 16 | from haystack.dataclasses.streaming_chunk import StreamingCallbackT, select_streaming_callback |
17 | 17 | from haystack.tools import Tool, Toolset, deserialize_tools_or_toolset_inplace, serialize_tools_or_toolset |
18 | 18 | from haystack.utils.callable_serialization import deserialize_callable, serialize_callable |
@@ -69,7 +69,7 @@ def __init__( |
69 | 69 | max_agent_steps: int = 100, |
70 | 70 | raise_on_tool_invocation_failure: bool = False, |
71 | 71 | streaming_callback: Optional[StreamingCallbackT] = None, |
72 | | - ): |
| 72 | + ) -> None: |
73 | 73 | """ |
74 | 74 | Initialize the agent component. |
75 | 75 |
|
@@ -237,13 +237,20 @@ def run( |
237 | 237 | - "messages": List of all messages exchanged during the agent's run. |
238 | 238 | - "last_message": The last message exchanged during the agent's run. |
239 | 239 | - Any additional keys defined in the `state_schema`. |
| 240 | + :raises RuntimeError: If the Agent component wasn't warmed up before calling `run()`. |
240 | 241 | """ |
241 | 242 | if not self._is_warmed_up and hasattr(self.chat_generator, "warm_up"): |
242 | 243 | raise RuntimeError("The component Agent wasn't warmed up. Run 'warm_up()' before calling 'run()'.") |
243 | 244 |
|
244 | 245 | if self.system_prompt is not None: |
245 | 246 | messages = [ChatMessage.from_system(self.system_prompt)] + messages |
246 | 247 |
|
| 248 | + if all(m.is_from(ChatRole.SYSTEM) for m in messages): |
| 249 | + logger.warning( |
| 250 | + "All messages provided to the Agent component are system messages. This is not recommended as the " |
| 251 | + "Agent will not perform any actions specific to user input. Consider adding user messages to the input." |
| 252 | + ) |
| 253 | + |
247 | 254 | state = State(schema=self.state_schema, data=kwargs) |
248 | 255 | state.set("messages", messages) |
249 | 256 | component_visits = dict.fromkeys(["chat_generator", "tool_invoker"], 0) |
@@ -332,13 +339,20 @@ async def run_async( |
332 | 339 | - "messages": List of all messages exchanged during the agent's run. |
333 | 340 | - "last_message": The last message exchanged during the agent's run. |
334 | 341 | - Any additional keys defined in the `state_schema`. |
| 342 | + :raises RuntimeError: If the Agent component wasn't warmed up before calling `run_async()`. |
335 | 343 | """ |
336 | 344 | if not self._is_warmed_up and hasattr(self.chat_generator, "warm_up"): |
337 | 345 | raise RuntimeError("The component Agent wasn't warmed up. Run 'warm_up()' before calling 'run_async()'.") |
338 | 346 |
|
339 | 347 | if self.system_prompt is not None: |
340 | 348 | messages = [ChatMessage.from_system(self.system_prompt)] + messages |
341 | 349 |
|
| 350 | + if all(m.is_from(ChatRole.SYSTEM) for m in messages): |
| 351 | + logger.warning( |
| 352 | + "All messages provided to the Agent component are system messages. This is not recommended as the " |
| 353 | + "Agent will not perform any actions specific to user input. Consider adding user messages to the input." |
| 354 | + ) |
| 355 | + |
342 | 356 | state = State(schema=self.state_schema, data=kwargs) |
343 | 357 | state.set("messages", messages) |
344 | 358 | component_visits = dict.fromkeys(["chat_generator", "tool_invoker"], 0) |
|
0 commit comments