Project Context & Memory System
The Project Context system (project_context.go) provides a 4-tier memory hierarchy for AntFarm swarm workers, enabling persistent context across long-running multi-agent projects.
🧠 Four-Tier Memory Architecture
| Tier | Name | Storage | TTL | Purpose |
|---|---|---|---|---|
| 0 | Short-Term | In-memory (map[string]string) |
Per-session | Active facts, current work state |
| 1 | Project | workspaces/{user}/{project}/memory.md |
Persistent | Project-specific knowledge |
| 2 | User | workspaces/{user}/.global_memory/ |
Persistent | User-wide context |
| 3 | System | vault.txt (RAG) |
Persistent | Global knowledge base |
📁 Key Components
project_context.go
ProjectContextManager: Core struct managing all 4 tiersNewProjectContextManager(): Constructor for project-scoped contextSetShortTerm()/GetShortTerm(): In-memory cache operationsLoadProjectMemory(): Load frommemory.mdfileBuildMemoryContext(): Aggregate all tiers into context for agent
TierProject — Project Memory
// File: workspaces/{user}/{project}/memory.md
Stores:
- Key discoveries made during the project
- Important file locations and patterns
- Test results and verification status
- Design decisions and rationale
TierUser — User Global Context
// Directory: workspaces/{user}/.global_memory/
Per-user context that persists across all projects: -coding preferences
- Default tool sets
- Common patterns
TierSystem — Global Vault (RAG)
// File: vault.txt (loaded by rag.go)
Global knowledge base using Retrieval Augmented Generation:
- API patterns
- Codebase conventions
- Agent personas
🔧 Usage in AntFarm
Workers automatically receive a ProjectContextManager on spawn:
// From antfarm.go
session, err := NewProjectWorkerSession(
workerType, // "worker", "scout", "soldier", etc.
workspaceID, // "project-abc"
parentID, // Queen session ID
skillID, // Optional skill context
)
// The session's ContextMgr provides 4-tier memory
context := session.ContextMgr.BuildMemoryContext()
🎯 Context Injection
Each tier is injected into the agent's system prompt at different priorities:
- Short-Term (highest priority) — Active facts, current task state
- Project — Project-specific knowledge and discoveries
- User — User preferences and patterns
- System (lowest priority) — Global conventions
📋 Key Functions
| Function | Purpose |
|---|---|
NewProjectContextManager(user, project) |
Create context manager for project |
SetShortTerm(key, value) |
Store in active memory |
GetShortTerm(key) |
Retrieve from active memory |
LoadProjectMemory() |
Load project memory file |
BuildMemoryContext() |
Aggregate all 4 tiers |
ClearShortTerm() |
Clear active memory between tasks |
📂 Related Documentation
- AntFarm Swarm — For multi-agent project execution
- Tools, Skills & Memory — Tool system overview
- Assistant Core — Session management