| 81 | self.save_cache(self.tool, tool_args, tool_result) |
| 82 | return tool_result |
| 83 | def save_cache(self, tool: Callable, tool_args: Dict, tool_result: Union[str, Dict]): |
| 84 | tool_name = tool.__name__ |
| 85 | |
| 86 | tool_cache_file = f"{self.cache_path}/tools/{tool_name}.json" |
| 87 | os.makedirs(os.path.dirname(tool_cache_file), exist_ok=True) |
| 88 | tool_cache_dict = { |
| 89 | "name": tool_name, |
| 90 | "args": tool_args, |
| 91 | "result": tool_result |
| 92 | } |
| 93 | with open(tool_cache_file, "w", encoding="utf-8") as f: |
| 94 | json.dump(tool_cache_dict, f, ensure_ascii=False, indent=4) |
| 95 | def check_cache(self, tool_name: str): |
| 96 | tool_name = tool_name |
| 97 | cache_file = f"{self.cache_path}/tools/{tool_name}.json" |