Coverage for haystack/hooks/human_in_the_loop/dataclasses.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-21 13:53 +0000

1# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai> 

2# 

3# SPDX-License-Identifier: Apache-2.0 

4 

5from dataclasses import asdict, dataclass 

6from typing import Any 

7 

8 

9@dataclass 

10class ConfirmationUIResult: 

11 """ 

12 Result of the confirmation UI interaction. 

13 

14 :param action: 

15 The action taken by the user such as "confirm", "reject", or "modify". 

16 This action type is not enforced to allow for custom actions to be implemented. 

17 :param feedback: 

18 Optional feedback message from the user. For example, if the user rejects the tool execution, 

19 they might provide a reason for the rejection. 

20 :param new_tool_params: 

21 Optional set of new parameters for the tool. For example, if the user chooses to modify the tool parameters, 

22 they can provide a new set of parameters here. 

23 """ 

24 

25 action: str # "confirm", "reject", "modify" 

26 feedback: str | None = None 

27 new_tool_params: dict[str, Any] | None = None 

28 

29 

30@dataclass 

31class ToolExecutionDecision: 

32 """ 

33 Decision made regarding tool execution. 

34 

35 :param tool_name: 

36 The name of the tool to be executed. 

37 :param execute: 

38 A boolean indicating whether to execute the tool with the provided parameters. 

39 :param tool_call_id: 

40 Optional unique identifier for the tool call. This can be used to track and correlate the decision with a 

41 specific tool invocation. 

42 :param feedback: 

43 Optional feedback message. 

44 For example, if the tool execution is rejected, this can contain the reason. Or if the tool parameters were 

45 modified, this can contain the modification details. 

46 :param final_tool_params: 

47 Optional final parameters for the tool if execution is confirmed or modified. 

48 """ 

49 

50 tool_name: str 

51 execute: bool 

52 tool_call_id: str | None = None 

53 feedback: str | None = None 

54 final_tool_params: dict[str, Any] | None = None 

55 

56 def to_dict(self) -> dict[str, Any]: 

57 """ 

58 Convert the ToolExecutionDecision to a dictionary representation. 

59 

60 :return: A dictionary containing the tool execution decision details. 

61 """ 

62 return asdict(self) 

63 

64 @classmethod 

65 def from_dict(cls, data: dict[str, Any]) -> "ToolExecutionDecision": 

66 """ 

67 Populate the ToolExecutionDecision from a dictionary representation. 

68 

69 :param data: A dictionary containing the tool execution decision details. 

70 :return: An instance of ToolExecutionDecision. 

71 """ 

72 return cls(**data)