Coverage for src / agent_contracts / store / base.py: 0%

16 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-09 00:42 +0900

1"""StateStore - Abstract base class for state storage. 

2 

3Provides an interface for persistent state storage. 

4Implement this for your storage backend (Redis, PostgreSQL, etc.). 

5""" 

6from __future__ import annotations 

7 

8from abc import ABC, abstractmethod 

9from typing import Any 

10 

11 

12class StateStore(ABC): 

13 """Abstract base class for state storage. 

14  

15 Implement this for your storage backend. 

16  

17 Example: 

18 class RedisStateStore(StateStore): 

19 async def save(self, key: str, value: dict) -> None: 

20 await self.redis.set(key, json.dumps(value)) 

21  

22 async def load(self, key: str) -> dict | None: 

23 data = await self.redis.get(key) 

24 return json.loads(data) if data else None 

25 """ 

26 

27 @abstractmethod 

28 async def save(self, key: str, value: dict[str, Any]) -> None: 

29 """Save value for key. 

30  

31 Args: 

32 key: Storage key 

33 value: Value to store 

34 """ 

35 ... 

36 

37 @abstractmethod 

38 async def load(self, key: str) -> dict[str, Any] | None: 

39 """Load value for key. 

40  

41 Args: 

42 key: Storage key 

43  

44 Returns: 

45 Stored value or None if not found 

46 """ 

47 ... 

48 

49 @abstractmethod 

50 async def delete(self, key: str) -> bool: 

51 """Delete value for key. 

52  

53 Args: 

54 key: Storage key 

55  

56 Returns: 

57 True if deleted, False if not found 

58 """ 

59 ... 

60 

61 @abstractmethod 

62 async def exists(self, key: str) -> bool: 

63 """Check if key exists. 

64  

65 Args: 

66 key: Storage key 

67  

68 Returns: 

69 True if exists 

70 """ 

71 ... 

72 

73 async def list_by_prefix(self, prefix: str) -> list[str]: 

74 """List keys matching prefix. 

75  

76 Optional method - override if your backend supports it. 

77  

78 Args: 

79 prefix: Key prefix 

80  

81 Returns: 

82 List of matching keys 

83 """ 

84 return [] 

85 

86 async def close(self) -> None: 

87 """Cleanup resources. 

88  

89 Optional method - override if your backend needs cleanup. 

90 """ 

91 pass