Metadata-Version: 2.4
Name: agentswarm-redis-store
Version: 0.1.0
Summary: Redis implementation of the Store interface for ai-agentswarm.
Author-email: Lucas Roverelli <lucas.roverelli@gmail.com>
License: MIT License
        
        Copyright (c) 2025 Luca Roverelli
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Project-URL: Homepage, https://github.com/ai-agentswarm/agentswarm-redis-store
Project-URL: Bug Tracker, https://github.com/ai-agentswarm/agentswarm-redis-store/issues
Keywords: ai,agents,redis,store,persistence
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: redis>=5.0.0
Requires-Dist: pydantic>=2.0.0
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: fakeredis; extra == "dev"
Requires-Dist: twine; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: black; extra == "dev"
Requires-Dist: isort; extra == "dev"
Dynamic: license-file

# agentswarm-redis-store

Redis implementation of the `Store` interface for [ai-agentswarm](https://github.com/ai-agentswarm/agentswarm).

## Security Configuration

This project focuses on secure Redis connections. It supports:
- **SSL/TLS**: For encrypted communication.
- **ACL/Passwords**: For authenticated access.
- **Safe Serialization**: Uses JSON by default for structured data.

## Installation

```bash
pip install agentswarm-redis-store
```

### Local Development

If you are working on the source code:

```bash
# Clone the repository
cd agentswarm-redis-store

# Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate

# Install in editable mode
pip install -e .
```

## Security Focus

The `RedisStore` is designed with security as a primary concern:
- **SSL/TLS**: Mandatory for production environments to prevent eavesdropping.
- **Authentication**: Supports both legacy `password` and modern Redis 6+ `username`/`password` ACLs.
- **Secure Reconstruction**: `to_dict()` returns a minimal configuration that triggers reconstruction from environment variables on the remote side, ensuring sensitive credentials are never serialized or transmitted.
- **Client Injection**: Allows passing a pre-configured `redis.Redis` client for advanced use cases (e.g., custom pooling, sentinel).

## Configuration Environment Variables

When using `RedisStore.from_env()` or remote reconstruction, the following environment variables are supported:

| Variable | Description | Default |
|----------|-------------|---------|
| `REDIS_HOST` | Redis server hostname | `localhost` |
| `REDIS_PORT` | Redis server port | `6379` |
| `REDIS_DB`   | Redis database number | `0` |
| `REDIS_USERNAME` | Username for ACL authentication | `None` |
| `REDIS_PASSWORD` | Password for authentication | `None` |
| `REDIS_SSL` | Enable SSL/TLS connection (`true`/`false`) | `false` |

## Usage

### Environmental Configuration (Recommended)
Set `REDIS_HOST`, `REDIS_PASSWORD`, etc., in your environment and use:
```python
from agentswarm.redis.store import RedisStore
store = RedisStore.from_env()
```

### Direct Client Injection
```python
import redis
from agentswarm.redis.store import RedisStore

client = redis.Redis(host="localhost", db=0)
store = RedisStore(redis_client=client)
```

### Remote Reconstruction
```python
store = RedisStore.from_env()
config = store.to_dict() # Returns {"recreate_from_env": True}

# On a remote machine (with its own REDIS_HOST env var)
remote_store = RedisStore.recreate(config)
```

## Integration with Agentswarm

You can use the `RedisStore` as the backend for the `agentswarm.Context`:

```python
from agentswarm.redis.store import RedisStore
from agentswarm.datamodels.context import Context

# 1. Initialize the store (e.g., from environment)
store = RedisStore.from_env()

# 2. Inject into the Context
context = Context(
    trace_id="my-unique-trace",
    messages=[],
    store=store,
    tracing=my_tracing_instance
)

# 3. Use as usual
context.store.set("key", "value")
```
