33# SPDX-License-Identifier: Apache-2.0
44
55import inspect
6- from typing import Any , Dict , List , Optional , Union
6+ from typing import Any , Optional , Union
77
88from haystack import logging , tracing
99from haystack .components .generators .chat .types import ChatGenerator
@@ -71,14 +71,14 @@ def __init__(
7171 self ,
7272 * ,
7373 chat_generator : ChatGenerator ,
74- tools : Optional [Union [List [Tool ], Toolset ]] = None ,
74+ tools : Optional [Union [list [Tool ], Toolset ]] = None ,
7575 system_prompt : Optional [str ] = None ,
76- exit_conditions : Optional [List [str ]] = None ,
77- state_schema : Optional [Dict [str , Any ]] = None ,
76+ exit_conditions : Optional [list [str ]] = None ,
77+ state_schema : Optional [dict [str , Any ]] = None ,
7878 max_agent_steps : int = 100 ,
7979 streaming_callback : Optional [StreamingCallbackT ] = None ,
8080 raise_on_tool_invocation_failure : bool = False ,
81- tool_invoker_kwargs : Optional [Dict [str , Any ]] = None ,
81+ tool_invoker_kwargs : Optional [dict [str , Any ]] = None ,
8282 ) -> None :
8383 """
8484 Initialize the agent component.
@@ -126,7 +126,7 @@ def __init__(
126126 # Initialize state schema
127127 resolved_state_schema = _deepcopy_with_exceptions (self ._state_schema )
128128 if resolved_state_schema .get ("messages" ) is None :
129- resolved_state_schema ["messages" ] = {"type" : List [ChatMessage ], "handler" : merge_lists }
129+ resolved_state_schema ["messages" ] = {"type" : list [ChatMessage ], "handler" : merge_lists }
130130 self .state_schema = resolved_state_schema
131131
132132 self .chat_generator = chat_generator
@@ -172,7 +172,7 @@ def warm_up(self) -> None:
172172 self .chat_generator .warm_up ()
173173 self ._is_warmed_up = True
174174
175- def to_dict (self ) -> Dict [str , Any ]:
175+ def to_dict (self ) -> dict [str , Any ]:
176176 """
177177 Serialize the component to a dictionary.
178178
@@ -198,7 +198,7 @@ def to_dict(self) -> Dict[str, Any]:
198198 )
199199
200200 @classmethod
201- def from_dict (cls , data : Dict [str , Any ]) -> "Agent" :
201+ def from_dict (cls , data : dict [str , Any ]) -> "Agent" :
202202 """
203203 Deserialize the agent from a dictionary.
204204
@@ -219,9 +219,9 @@ def from_dict(cls, data: Dict[str, Any]) -> "Agent":
219219
220220 return default_from_dict (cls , data )
221221
222- def _prepare_generator_inputs (self , streaming_callback : Optional [StreamingCallbackT ] = None ) -> Dict [str , Any ]:
222+ def _prepare_generator_inputs (self , streaming_callback : Optional [StreamingCallbackT ] = None ) -> dict [str , Any ]:
223223 """Prepare inputs for the chat generator."""
224- generator_inputs : Dict [str , Any ] = {"tools" : self .tools }
224+ generator_inputs : dict [str , Any ] = {"tools" : self .tools }
225225 if streaming_callback is not None :
226226 generator_inputs ["streaming_callback" ] = streaming_callback
227227 return generator_inputs
@@ -240,13 +240,13 @@ def _create_agent_span(self) -> Any:
240240
241241 def run ( # noqa: PLR0915
242242 self ,
243- messages : List [ChatMessage ],
243+ messages : list [ChatMessage ],
244244 streaming_callback : Optional [StreamingCallbackT ] = None ,
245245 * ,
246246 break_point : Optional [AgentBreakpoint ] = None ,
247247 snapshot : Optional [AgentSnapshot ] = None ,
248248 ** kwargs : Any ,
249- ) -> Dict [str , Any ]:
249+ ) -> dict [str , Any ]:
250250 """
251251 Process messages and execute tools until an exit condition is met.
252252
@@ -431,13 +431,13 @@ def run( # noqa: PLR0915
431431
432432 async def run_async ( # noqa: PLR0915
433433 self ,
434- messages : List [ChatMessage ],
434+ messages : list [ChatMessage ],
435435 streaming_callback : Optional [StreamingCallbackT ] = None ,
436436 * ,
437437 break_point : Optional [AgentBreakpoint ] = None ,
438438 snapshot : Optional [AgentSnapshot ] = None ,
439439 ** kwargs : Any ,
440- ) -> Dict [str , Any ]:
440+ ) -> dict [str , Any ]:
441441 """
442442 Asynchronously process messages and execute tools until the exit condition is met.
443443
@@ -626,7 +626,7 @@ async def run_async( # noqa: PLR0915
626626 result .update ({"last_message" : all_messages [- 1 ]})
627627 return result
628628
629- def _check_exit_conditions (self , llm_messages : List [ChatMessage ], tool_messages : List [ChatMessage ]) -> bool :
629+ def _check_exit_conditions (self , llm_messages : list [ChatMessage ], tool_messages : list [ChatMessage ]) -> bool :
630630 """
631631 Check if any of the LLM messages' tool calls match an exit condition and if there are no errors.
632632
0 commit comments