feat(memory): add working memory implementation (Issue #89)

Implements session-scoped ephemeral memory with:

Storage Backends:
- InMemoryStorage: Thread-safe fallback with TTL support and capacity limits
- RedisStorage: Primary storage with connection pooling and JSON serialization
- Auto-fallback from Redis to in-memory when unavailable

WorkingMemory Class:
- Key-value storage with TTL and reserved key protection
- Task state tracking with progress updates
- Scratchpad for reasoning steps with timestamps
- Checkpoint/snapshot support for recovery
- Factory methods for auto-configured storage

Tests:
- 55 unit tests covering all functionality
- Tests for basic ops, TTL, capacity, concurrency
- Tests for task state, scratchpad, checkpoints

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-05 01:51:03 +01:00
parent c9d8c0835c
commit 4974233169
7 changed files with 1673 additions and 4 deletions

View File

@@ -94,6 +94,22 @@ class MemoryStorageError(MemoryError):
self.backend = backend
class MemoryConnectionError(MemoryError):
"""Raised when memory storage connection fails."""
def __init__(
self,
message: str = "Memory connection failed",
*,
backend: str | None = None,
host: str | None = None,
**kwargs: Any,
) -> None:
super().__init__(message, **kwargs)
self.backend = backend
self.host = host
class MemorySerializationError(MemoryError):
"""Raised when memory serialization/deserialization fails."""