# FlowDrop Memory

Scoped, pluggable memory storage for FlowDrop workflows and AI agents.

PHP classes in this module are `@api` or `@internal`. See the [BC Policy](../../docs/reference/api/bc-policy.md) for details.

## Overview

Provides a key-value memory system with configurable backends and automatic scope resolution. Nodes can read and write named values scoped to a workflow, pipeline, execution, session, or globally — without wiring explicit IDs.

## Services

### MemoryManager

**Service ID:** `flowdrop_memory.manager`

```php
$manager = \Drupal::service('flowdrop_memory.manager');

$manager->set($scope, $scopeId, $key, $value, $ttl);
$value  = $manager->get($scope, $scopeId, $key, $default);
$exists = $manager->has($scope, $scopeId, $key);
$manager->delete($scope, $scopeId, $key);
$manager->clear($scope, $scopeId);
```

The active backend is resolved per-scope from configuration. Scope IDs are auto-derived from the execution context in the `memory_read` and `memory_write` node processors.

### MemoryBackendPluginManager

**Service ID:** `flowdrop_memory.backend_plugin_manager`

Discovers and instantiates `MemoryBackend` plugins. Use the `#[MemoryBackend]` attribute to register a custom backend.

## Built-in Backends

| Plugin ID | Class | Storage | TTL | Notes |
|-----------|-------|---------|-----|-------|
| `static` | `StaticMemoryBackend` | PHP process memory | No | Lost between requests |
| `cached` | `CachedMemoryBackend` | Drupal cache bins | Yes | Configurable bin |
| `entity` | `EntityMemoryBackend` | Database (`MemoryRecord`) | Yes | Durable, queryable |

## Built-in Node Processors

| Plugin ID | Description |
|-----------|-------------|
| `memory_read` | Read from scoped memory; scope ID auto-derived from execution context |
| `memory_write` | Write to scoped memory; scope ID auto-derived from execution context |
| `memory_read_raw` | Read with explicit scope ID (no execution context required) |
| `memory_write_raw` | Write with explicit scope ID (no execution context required) |

## Configuration

**Admin:** `/admin/flowdrop/memory/settings`

Requires `administer flowdrop` permission.
