An AI agent system that captures human decisions and replays them as policies for future actions. Features semantic retrieval, human-in-the-loop approval gates, and full execution tracing.
Portfolio Project: This is a demonstration codebase showcasing AI agent architecture patterns. See Known Limitations for details on what's production-ready vs. demo implementation.
- Decision Capture - Record decisions with context, rationale, and outcomes
- Semantic Retrieval - Vector similarity search finds relevant past decisions
- Policy Extraction - Automatically extract constraints and preferences from decisions
- Approval Gates - Human-in-the-loop checkpoints for high-impact actions
- Execution Tracing - Full audit trail of all agent actions
- Real-time Streaming - SSE-based live updates during task execution
# Clone and setup
git clone https://github.com/andrewsauer/decision-memory-agent.git
cd decision-memory-agent
# One-command setup
./scripts/setup.sh
# Start development server
pnpm devNavigate to /agent?scenario=vendor_selection
The agent retrieves past vendor decisions and applies learned policies:
- SOC2 compliance requirements
- Budget thresholds
- Team expertise preferences
Navigate to /agent?scenario=email_reply
The agent follows communication patterns:
- Tone preferences by customer tier
- Escalation rules
- Response time SLAs
┌─────────────────────────────────────────────────────────────┐
│ Frontend │
│ ┌──────────────────┐ ┌──────────────────────────────┐ │
│ │ Decision Capture │ │ Agent Execution Page │ │
│ │ Page │ │ ┌────────────────────────┐ │ │
│ │ │ │ │ Policy Matrix Display │ │ │
│ │ • Task Type │ │ │ Execution Stream │ │ │
│ │ • Context Form │ │ │ Approval Gate Modal │ │ │
│ │ • Rationale │ │ │ Trace Viewer │ │ │
│ └──────────────────┘ │ └────────────────────────┘ │ │
└─────────────────────────────────────────────────────────────┘
│
│ SSE Stream
▼
┌─────────────────────────────────────────────────────────────┐
│ API Layer │
│ /api/decisions /api/tasks /api/tasks/[id]/stream │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Agent Orchestrator │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────────┐ │
│ │State Machine │ │Approval Gate │ │ Policy Extractor │ │
│ │ (FSM) │ │ Checker │ │ (LLM) │ │
│ └──────────────┘ └──────────────┘ └──────────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Data Layer │
│ ┌──────────────────┐ ┌──────────────────────────────┐ │
│ │ PostgreSQL │ │ Vector Search │ │
│ │ + pgvector │◄───│ (Embeddings + Cosine) │ │
│ └──────────────────┘ └──────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
decision-memory-agent/
├── apps/
│ └── web/ # Next.js 14 application
│ ├── src/
│ │ ├── app/
│ │ │ ├── decisions/ # Decision capture page
│ │ │ ├── agent/ # Agent execution page
│ │ │ └── api/ # API routes
│ │ └── components/ # UI components
│
├── packages/
│ ├── core/ # Shared domain logic
│ │ ├── src/
│ │ │ ├── schemas/ # Zod schemas
│ │ │ ├── db/ # Drizzle + migrations
│ │ │ └── retrieval/ # Vector search
│ │
│ └── agent/ # Agent orchestration
│ ├── src/
│ │ ├── orchestrator/ # State machine
│ │ ├── extraction/ # Policy extraction
│ │ ├── tools/ # Tool registry
│ │ └── tracing/ # Execution traces
│
├── scripts/
│ └── setup.sh # One-command setup
│
└── docker-compose.yml # PostgreSQL + pgvector
| Layer | Technology |
|---|---|
| Frontend | Next.js 14, React, shadcn/ui, Tailwind CSS |
| Backend | Next.js API Routes, SSE |
| Database | PostgreSQL + pgvector |
| ORM | Drizzle |
| Validation | Zod |
| LLM | Claude API (Anthropic) |
| Embeddings | OpenAI text-embedding-3-small |
| Monorepo | pnpm + Turborepo |
Create a .env file in the root directory:
# Database
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/decision_memory
# OpenAI (for embeddings)
OPENAI_API_KEY=your-openai-key
# Anthropic (for policy extraction)
ANTHROPIC_API_KEY=your-anthropic-key# Install dependencies
pnpm install
# Start database
docker compose up -d postgres
# Run migrations
pnpm db:migrate
# Seed demo data
pnpm db:seed
# Start development
pnpm dev
# Build for production
pnpm build
# Run tests
pnpm test
# Type check
pnpm typecheckCreate a new decision record.
{
"taskType": "vendor_selection",
"title": "Selected AWS for cloud hosting",
"context": "Evaluating cloud providers...",
"rationale": "Chose AWS due to team expertise...",
"outcome": "Deployment completed successfully"
}Start a new agent task.
{
"taskType": "vendor_selection",
"goal": "Select email service provider under $2000/month"
}SSE stream for real-time task execution updates.
The agent uses a type-safe state machine with discriminated unions:
IDLE → PLANNING → PROPOSING_ACTIONS → APPROVAL_GATE → EXECUTING_TOOL
↓
LOGGING → FINALIZING → COMPLETED
MIT