Skip to content

An autonomous AI agent that captures human decisions, extracts policy patterns using LLMs, and applies learned constraints with human-in-the-loop approval gates.

License

Notifications You must be signed in to change notification settings

andrewjsauer/decision-memory-agent

Repository files navigation

Decision Memory Agent

CI TypeScript License: MIT Node Version

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.

Features

  • 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

Quick Start

# 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 dev

Open http://localhost:3000

Demo Scenarios

Vendor Selection

Navigate to /agent?scenario=vendor_selection

The agent retrieves past vendor decisions and applies learned policies:

  • SOC2 compliance requirements
  • Budget thresholds
  • Team expertise preferences

Email Reply

Navigate to /agent?scenario=email_reply

The agent follows communication patterns:

  • Tone preferences by customer tier
  • Escalation rules
  • Response time SLAs

Architecture

┌─────────────────────────────────────────────────────────────┐
│                        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)      │  │
│  └──────────────────┘    └──────────────────────────────┘  │
└─────────────────────────────────────────────────────────────┘

Project Structure

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

Tech Stack

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

Configuration

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

Development

# 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 typecheck

API Reference

POST /api/decisions

Create 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"
}

POST /api/tasks

Start a new agent task.

{
  "taskType": "vendor_selection",
  "goal": "Select email service provider under $2000/month"
}

GET /api/tasks/[id]/stream

SSE stream for real-time task execution updates.

State Machine

The agent uses a type-safe state machine with discriminated unions:

IDLE → PLANNING → PROPOSING_ACTIONS → APPROVAL_GATE → EXECUTING_TOOL
                                           ↓
                                      LOGGING → FINALIZING → COMPLETED

License

MIT

About

An autonomous AI agent that captures human decisions, extracts policy patterns using LLMs, and applies learned constraints with human-in-the-loop approval gates.

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published