Download the PHP package mauricioperera/php-agent-memory without Composer
On this page you can find all versions of the php package mauricioperera/php-agent-memory. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mauricioperera/php-agent-memory
More information about mauricioperera/php-agent-memory
Files in mauricioperera/php-agent-memory
Package php-agent-memory
Short Description Agentic memory system for AI agents with dream consolidation — built on php-vector-store
License MIT
Homepage https://github.com/MauricioPerera/php-agent-memory
Informations about the package php-agent-memory
PHPAgentMemory
Agentic memory system for AI agents — built on php-vector-store. Zero external dependencies beyond php-vector-store itself.
Inspired by RepoMemory's philosophy: save, search, recall, and consolidate knowledge — but pragmatic PHP instead of Git-like versioning.
Why
AI agents lose context between sessions. PHPAgentMemory gives them persistent, searchable memory with:
- 3 entity types: memories (what happened), skills (how to do things), knowledge (facts about the world)
- Hybrid search: vector similarity + BM25 full-text, fused with RRF
- Matryoshka progressive search: 128d→384d→768d — 5.6x faster than brute force at 5K vectors
- Recall engine: pools all collections, ranks by score, formats as context
- Dream cycle: 4-phase AI consolidation — orient, analyze, consolidate, verify — the agent "sleeps" and wakes up with cleaner memory
- Neuron AI integration: 4 adapters (VectorStore, Toolkit, Retrieval, PreProcessor)
- HTTP API: REST server with Bearer auth, ready for any agent framework
- Zero dependencies: only PHP 8.1+ and php-vector-store
Quick Start
As PHP Library
As HTTP API
Architecture
The Dream Cycle
The dream is a 4-phase reflective pass over the agent's memory — like how the brain consolidates memories during sleep.
Usage
What the LLM Does During the Dream
Given these 14 memories:
Result: 14 memories → 7 memories. Same knowledge, less noise.
Programmatic Access to the Report
Or Use the Low-Level Pipeline Directly
Entity Types
Memory
What happened — scoped by agentId + userId.
| Field | Type | Description |
|---|---|---|
| content | string | The memory text |
| tags | string[] | Searchable tags (max 50, auto-lowercased) |
| category | enum | fact, decision, issue, task, correction |
| sourceSession | ?string | Optional session ID that produced this memory |
Skill
How to do things — scoped by agentId only (no userId).
| Field | Type | Description |
|---|---|---|
| content | string | The procedure/config/workflow |
| tags | string[] | Searchable tags |
| category | enum | procedure, configuration, troubleshooting, workflow |
| status | enum | active, deprecated, draft |
Knowledge
Facts about the world — scoped by agentId only.
| Field | Type | Description |
|---|---|---|
| content | string | The knowledge text |
| tags | string[] | Searchable tags |
| source | ?string | Where this knowledge came from |
Scoping Model
Entities are isolated by scope using php-vector-store collections:
The special agent ID _shared enables cross-agent shared skills and knowledge. The recall engine automatically searches both the agent's own collections and _shared.
Deduplication
Every saveOrUpdate() call:
- Flushes pending writes
- Runs hybrid search for similar existing entities
- If score >= threshold (default 0.85): updates existing entity, merges tags
- Otherwise: creates new entity
This prevents memory bloat from repeated saves of similar content.
Configuration
CloudflareLlmProvider (included)
Zero-dependency LLM provider using Cloudflare Workers AI:
Any Workers AI text generation model works. Recommended:
@cf/ibm-granite/granite-4.0-h-micro— fastest, cheapest, good JSON output@cf/meta/llama-3.1-8b-instruct— better reasoning, slower
Custom LLM Provider
Neuron AI Integration
PHPAgentMemory integrates with Neuron AI — the PHP agentic framework. Four adapters give any Neuron agent persistent memory:
Option 1: Memory Tools (agent decides when to remember)
The toolkit exposes 4 tools the LLM can call:
memory_save— Save facts, decisions, preferences, correctionsmemory_recall— Multi-collection recall (memories + skills + knowledge)memory_search— Search a specific collectionmemory_store_skill— Save reusable procedures
Option 2: VectorStore Adapter (for RAG pipelines)
Option 3: Memory Retrieval (replaces default retrieval)
Option 4: PreProcessor (automatic context injection)
Combining Everything
HTTP API Reference
| Method | Route | Body | Description |
|---|---|---|---|
| GET | /health |
— | Status check (no auth) |
| GET | /stats |
— | Storage statistics |
| POST | /memory/save |
{agentId, userId, content, tags, category, vector} |
Save/dedup memory |
| POST | /memory/search |
{agentId, userId, query, vector, limit?} |
Search memories |
| POST | /skill/save |
{agentId, content, tags, category, vector} |
Save/dedup skill |
| POST | /skill/search |
{agentId, query, vector, limit?} |
Search skills (+shared) |
| POST | /knowledge/save |
{agentId, content, tags, source, vector} |
Save/dedup knowledge |
| POST | /knowledge/search |
{agentId, query, vector, limit?} |
Search knowledge (+shared) |
| POST | /recall |
{agentId, userId, query, vector, maxItems?, weights?} |
Multi-collection recall |
| POST | /consolidate |
{agentId, userId?} |
AI consolidation (needs LLM) |
| POST | /dream |
{agentId, userId?} |
Full dream cycle (needs LLM + embedFn) |
| GET | /entity/{id} |
— | Get any entity by ID |
| DELETE | /entity/{id} |
— | Soft-delete entity |
Auth: Authorization: Bearer <token> (timing-safe comparison). /health is public.
CORS: Configurable via --cors-origin (default *).
Benchmarks
Tested with AG News dataset and Cloudflare EmbeddingGemma-300m (768d Matryoshka, Int8 quantized).
Search Performance
| Vectors | Brute 768d | Matryoshka 128→768 | 128d only | Speedup | Top-1 Accuracy |
|---|---|---|---|---|---|
| 100 | 68ms | 90ms | 15ms | 0.7x | 100% |
| 500 | 297ms | 152ms | 60ms | 1.9x | 100% |
| 1,000 | 703ms | 230ms | 128ms | 3.1x | 100% |
| 2,000 | 1,320ms | 306ms | 262ms | 4.3x | 100% |
| 5,000 | 3,333ms | 596ms | 438ms | 5.6x | 100% |
Dream Performance
| Metric | Value |
|---|---|
| Entities before dream | 18 (14 memories + 4 skills) |
| Entities after dream | 10 |
| Duplicate clusters found | 5 |
| Merged groups | 3 |
| Entries removed | 11 |
| Duration | 20s |
| LLM model | Granite 4.0 H-Micro (Cloudflare Workers AI) |
Other Metrics
| Metric | Value |
|---|---|
| Save latency | 1.0-2.0ms/entity |
| Flush to disk | 60-130ms |
| Storage per vector | 776 bytes (Int8 768d) |
| Storage at 5K vectors | 3.7 MB |
| Embedding (Cloudflare batch) | 23ms/text |
| Persistence reload | 7ms |
Embedding Providers
PHPAgentMemory is embedding-agnostic — you pass pre-computed vectors to every save() and search() call. Use any provider:
Cloudflare Workers AI (free)
OpenAI
Ollama (local)
Storage Format
Testing
Project Structure
RepoMemory Comparison
| Feature | RepoMemory (TS) | PHPAgentMemory |
|---|---|---|
| Language | TypeScript | PHP 8.1+ |
| Storage | Git-like (SHA-256 objects + commits) | php-vector-store (binary + JSON) |
| Versioning | Full commit history + tombstones | Soft-delete via metadata |
| Search | TF-IDF + neural embeddings | BM25 + vector hybrid (RRF) |
| Entity types | 5 (+ sessions, profiles) | 3 (memories, skills, knowledge) |
| Dream/Consolidation | AI pipeline | AI pipeline (4-phase dream cycle) |
| Agent integration | MCP server | Neuron AI (4 adapters) + HTTP API |
| Dependencies | 0 | 0 (beyond php-vector-store) |
PHPAgentMemory trades RepoMemory's Git-like versioning for simplicity. No commit chains, no tombstones, no audit log — just vectors, metadata, and soft-deletes. The core value (save, search, recall, dream) is preserved.
License
MIT