in _handle_event(handlers, event_name, ignore_condition_name, *args, **kwargs)        135 try:        136     if ignore_condition_name is None or not getattr(        137         handler, ignore_condition_name        138     ):    --> 139         getattr(handler, event_name)(*args, **kwargs)        140 except NotImplementedError as e:        141     if event_name == "on_chat_model_start":    File ~/langchain/langchain/callbacks/human.py:48, in HumanApprovalCallbackHandler.on_tool_start(self, serialized, input_str, run_id, parent_run_id, **kwargs)         38 def on_tool_start(         39     self,         40     serialized: Dict[str, Any],       (...)         45     **kwargs: Any,         46 ) -> Any:         47     if self._should_check(serialized) and not self._approve(input_str):    ---> 48         raise HumanRejectedException(         49             f"Inputs {input_str} to tool {serialized} were rejected."         50         )    HumanRejectedException: Inputs ls /private to tool {'name': 'terminal', 'description': 'Run shell commands on this MacOS machine.'} were rejected.Configuring Human Approval‚ÄãLet's suppose we have an agent that takes in multiple tools, and we want it to only trigger human approval requests on certain tools and certain inputs. We can configure out callback handler to do just this.from langchain.agents import load_toolsfrom langchain.agents import initialize_agentfrom langchain.agents import AgentTypefrom langchain.llms import OpenAIdef _should_check(serialized_obj: dict) -> bool:    # Only require approval on ShellTool.    return serialized_obj.get("name") == "terminal"def _approve(_input: str) -> bool:    if _input == "echo 'Hello World'":        return True    msg = (        "Do you approve of the following input? "        "Anything except 'Y'/'Yes' (case-insensitive) will be treated as a no."    )    msg += "\n\n" + _input + "\n"    resp = input(msg)    return resp.lower() in ("yes", "y")callbacks =
This walkthrough demonstrates how to add human validation to any Tool. We'll do this using the HumanApprovalCallbackhandler.
This walkthrough demonstrates how to add human validation to any Tool. We'll do this using the HumanApprovalCallbackhandler. ->: in _handle_event(handlers, event_name, ignore_condition_name, *args, **kwargs)        135 try:        136     if ignore_condition_name is None or not getattr(        137         handler, ignore_condition_name        138     ):    --> 139         getattr(handler, event_name)(*args, **kwargs)        140 except NotImplementedError as e:        141     if event_name == "on_chat_model_start":    File ~/langchain/langchain/callbacks/human.py:48, in HumanApprovalCallbackHandler.on_tool_start(self, serialized, input_str, run_id, parent_run_id, **kwargs)         38 def on_tool_start(         39     self,         40     serialized: Dict[str, Any],       (...)         45     **kwargs: Any,         46 ) -> Any:         47     if self._should_check(serialized) and not self._approve(input_str):    ---> 48         raise HumanRejectedException(         49             f"Inputs {input_str} to tool {serialized} were rejected."         50         )    HumanRejectedException: Inputs ls /private to tool {'name': 'terminal', 'description': 'Run shell commands on this MacOS machine.'} were rejected.Configuring Human Approval‚ÄãLet's suppose we have an agent that takes in multiple tools, and we want it to only trigger human approval requests on certain tools and certain inputs. We can configure out callback handler to do just this.from langchain.agents import load_toolsfrom langchain.agents import initialize_agentfrom langchain.agents import AgentTypefrom langchain.llms import OpenAIdef _should_check(serialized_obj: dict) -> bool:    # Only require approval on ShellTool.    return serialized_obj.get("name") == "terminal"def _approve(_input: str) -> bool:    if _input == "echo 'Hello World'":        return True    msg = (        "Do you approve of the following input? "        "Anything except 'Y'/'Yes' (case-insensitive) will be treated as a no."    )    msg += "\n\n" + _input + "\n"    resp = input(msg)    return resp.lower() in ("yes", "y")callbacks =