Save the contract for a tool
(self, tool_names: Optional[List[str]] = None)
| 1013 | return restored_config |
| 1014 | |
| 1015 | async def save_contract(self, tool_names: Optional[List[str]] = None): |
| 1016 | """Save the contract for a tool""" |
| 1017 | contract = [] |
| 1018 | if tool_names is not None: |
| 1019 | for index, tool_name in enumerate(tool_names): |
| 1020 | tool_info = await self.get_info(tool_name) |
| 1021 | text = tool_info.text |
| 1022 | contract.append(f"{index + 1:04d}\n{text}\n") |
| 1023 | else: |
| 1024 | for index, tool_name in enumerate(self._tool_configs.keys()): |
| 1025 | tool_info = await self.get_info(tool_name) |
| 1026 | text = tool_info.text |
| 1027 | contract.append(f"{index + 1:04d}\n{text}\n") |
| 1028 | contract_text = "---\n".join(contract) |
| 1029 | with open(self.contract_path, "w", encoding="utf-8") as f: |
| 1030 | f.write(contract_text) |
| 1031 | logger.info(f"| 📝 Saved {len(contract)} tools contract to {self.contract_path}") |
| 1032 | |
| 1033 | async def load_contract(self) -> str: |
| 1034 | """Load the contract for a tool""" |