Created: 2025-11-20 Status: Draft Purpose: Defines normative requirements for the server-based Agent Memory System, including taxonomy, data model, hybrid search, ACE workflow, APIs, and constraints. Related: docs/requirements/multi_agent_orchestration.md
This document defines normative requirements for the server-based Agent Memory System. It specifies memory taxonomy, data models, hybrid search behavior, ACE workflow responsibilities, APIs, and non-functional constraints. The implementation is expected to use PostgreSQL with pgvector for semantic search, but all search requirements MUST be expressed in terms of a generic vector search capability.
Parent Document: Multi-Agent Orchestration Requirements
THE SYSTEM SHALL provide a centralized, server-based memory service that allows agents to store, retrieve, and evolve project knowledge across sessions and workflows.
THE SYSTEM SHALL support automatic capture of task outcomes into structured memories, with minimal additional burden on agents.
THE SYSTEM SHALL enable hybrid search (semantic + keyword) over stored memories, with filtering by project, files, tags, time, and type.
Memories MUST be classified into one of the following types:
error_fixdiscoverydecisionlearningwarningcodebase_knowledge
THE SYSTEM SHALL enforce memory_type via a strict enumeration, rejecting or flagging any memory that does not conform to the allowed set.
Implementation note: The following requirements assume PostgreSQL storage with pgvector and tsvector support. However, any relational store with equivalent capabilities MAY be used, provided all constraints are preserved.
Each memory MUST belong to exactly one project. Projects SHALL include at minimum:
id(UUID),name(unique per installation),description(optional),- repository metadata (e.g.,
repository_url,current_branch), settings(JSON),created_at,updated_at.
The memories entity SHALL include at least:
id(UUID),project_id(FK → projects),agent_id(string),content(text),memory_type(taxonomy enum),goal(optional text),result(optional text),feedback(optional text),tool_usage(JSON),embedding(vector; semantic search),content_tsv(full-text index),tags(string array),- audit fields:
created_at,updated_at, - deduplication fields:
similarity_hash,is_duplicate,duplicate_of.
Memories marked is_duplicate=true SHALL reference the original memory via duplicate_of, and MUST be excluded from primary search results by default.
The files entity SHALL represent codebase files and include:
id(UUID),project_id(FK),file_path(unique per project),- optional
file_type,last_content_hash, - stats:
memory_count, - timestamps (
first_seen_at,last_seen_at).
The memory_files link entity SHALL support many-to-many relationships between memories and files, including:
memory_id(FK → memories),file_id(FK → files),relation_type(e.g., read, modified, created, deleted, referenced),- optional
line_start,line_end.
The system SHALL maintain a playbook_entries entity representing project-wide guidance bullets, including:
id,project_id,content,category(e.g.,dependencies,architecture,gotchas,patterns),embedding(vector),content_tsv(tsvector),tags(string array),priority(int; higher = more important),supporting_memory_ids(array of UUIDs),created_at,created_by,updated_at,is_active(soft-delete).
All modifications to the playbook MUST be recorded in playbook_changes with:
operation∈ {add, update, delete},- old/new content and/or structured
delta, reason,related_memory_id(optional),changed_at,changed_by.
Tags SHALL be modeled as first-class entities with:
name(unique per project),description,category(e.g., language, framework, concept),usage_count.
THE SYSTEM SHALL support at least three search modes over memories:
semantic(vector similarity only),keyword(full-text only),hybrid(combination of both).
Semantic search SHALL use a vector similarity index; pgvector with HNSW is the preferred implementation. Similarity MUST be computed via cosine similarity or equivalent.
Keyword search SHALL use full-text capabilities, such as PostgreSQL’s tsvector/tsquery, and MUST support ranking (ts_rank or equivalent) and snippet generation.
Hybrid search MUST fuse semantic and keyword rankings via a stable, documented strategy (e.g., Reciprocal Rank Fusion with configurable semantic/keyword weights).
Search requests MUST support optional filters for:
memory_types,tags,file_paths,agent_ids,date_from,date_to.
The ACE (Executor, Reflector, Curator) workflow is the primary mechanism for automatic memory creation and playbook updates.
Executor SHALL:
- parse
tool_usageto extract file paths and classify relations, - classify
memory_typebased ongoalandresult, - generate embeddings for content,
- create a memory record,
- link memory to relevant files.
Reflector SHALL:
- analyze task feedback for errors and root causes,
- search playbook for related entries using semantic search,
- tag related entries with supporting memory IDs,
- extract structured insights (e.g., patterns, gotchas, best practices).
Curator SHALL:
- propose playbook updates based on insights,
- generate delta operations (add/update/delete),
- validate deltas (no duplicates, minimal quality thresholds),
- apply accepted deltas to the playbook,
- record changes in
playbook_changes.
The ACE workflow MUST be invocable via a single complete-task style API that:
- accepts
goal,result,tool_usage, andfeedback, - runs Executor → Reflector → Curator in sequence,
- returns a structured
ACEResult.
The following endpoints describe required capabilities; URL paths and exact naming MAY vary, but equivalent functionality and contracts MUST exist.
The system SHALL expose an endpoint to execute the ACE workflow on task completion (e.g., POST /complete-task), accepting:
project_id,agent_id,goal,result,tool_usage(list),feedback.
Response MUST include:
memory_id,memory_type,files_linked,- tags, insights, errors, related playbook entries,
- playbook delta and updated bullets,
change_id(playbook change record).
The system SHALL support:
POST /memoriesto create a memory manually,GET /memories/{memory_id}to retrieve full details,POST /search(or equivalent) to perform hybrid memory search.
The system SHALL allow:
- retrieving the current playbook for a project,
- filtering by category/tags,
- retrieving playbook change history with filters (operation, agent_id, date).
The system SHALL provide an endpoint to retrieve the knowledge graph for a file (linked memories, playbook entries, related files, stats).
The system SHALL support a “get context for task” endpoint that:
- accepts
project_idandtask_description, - returns top-k relevant memories, playbook entries, and recommended files.
On memory creation, THE SYSTEM SHALL check for near-duplicates via semantic similarity and mark new memories as duplicate if similarity exceeds a configurable threshold (default 0.95).
The system SHOULD provide a deduplication maintenance operation to scan and mark duplicates in bulk for a project.
- Search latency P95:
- hybrid search: < 100ms under nominal load,
- semantic-only: < 50ms,
- keyword-only: < 20ms.
- ACE
complete-taskP95: < 2s including embedding calls.
The system SHALL support:
- horizontal scaling of stateless API servers,
- optional read replicas for search-heavy workloads,
- future sharding by
project_id.
All API calls MUST be authenticated and authorized; sensitive operations (playbook changes, deduplication) MUST be audited with actor, project_id, and timestamp.
from __future__ import annotations
from datetime import datetime
from typing import Any, Dict, List, Optional, Tuple
from pydantic import BaseModel, Field
class MemoryType(str, Enum):
ERROR_FIX = "error_fix"
DISCOVERY = "discovery"
DECISION = "decision"
LEARNING = "learning"
WARNING = "warning"
CODEBASE_KNOWLEDGE = "codebase_knowledge"
class ToolUsage(BaseModel):
tool_name: str
arguments: Dict[str, Any]
result: Optional[str] = None
class CreateMemoryRequest(BaseModel):
project_id: str
agent_id: str
content: str = Field(..., min_length=10)
memory_type: MemoryType
goal: Optional[str] = None
result: Optional[str] = None
feedback: Optional[str] = None
tags: List[str] = Field(default_factory=list)
file_paths: List[str] = Field(default_factory=list)
class CompleteTaskRequest(BaseModel):
project_id: str
agent_id: str
goal: str
result: str
tool_usage: List[ToolUsage]
feedback: str- Monitoring Architecture Requirements
- Task Queue Management Requirements
- Diagnosis Agent Requirements
| Version | Date | Author | Changes |
|---|---|---|---|
| 1.0 | 2025-11-16 | AI Spec Agent | Initial requirements derived from design doc |