A production-grade chassis for stateful LangGraph agents, purpose-built for multi-agent development workflows.
A Yarn 4 monorepo containing a NestJS 11 microservice that runs a LangGraph state machine with a Three-Brain memory architecture: per-run Working Memory, session-scoped Episodic Memory (Postgres + Drizzle ORM), and long-term Semantic Memory combining a Neo4j 5 knowledge graph with pgvector dense embeddings. This project demonstrates the intersection of senior monorepo engineering and production agentic systems: it is an extraction of production patterns from a proprietary platform, sanitized for public consumption.
graph TD
Console["console<br/>(React + Vite)"]
Gateway["gateway<br/>(Express)"]
Agent["agent-service<br/>(NestJS 11 + LangGraph)"]
Memory["memory-core<br/>(unified facade)"]
PG["Postgres 16<br/>+ pgvector"]
Neo["Neo4j 5<br/>Community"]
Redis["Redis 7"]
Console -->|HTTP| Gateway
Gateway -->|proxy| Agent
Agent --> Memory
Memory --> PG
Memory --> Neo
Agent -.->|cache| Redis
graph LR
S((START)) --> ingress
ingress --> retrieve
retrieve --> plan
plan --> act
act -->|"stepCount < maxSteps<br/>& shouldContinue"| act
act -->|"loop done"| reflect
reflect --> egress
egress --> E((END))
graph TD
WM["Working Memory<br/>(LangGraph AgentState)"]
EM["Episodic Memory<br/>(Postgres + Drizzle)"]
Neo4j["Neo4j Knowledge Graph<br/>(entities + relationships)"]
PGV["pgvector Collection<br/>(dense embeddings)"]
RRF["RRF Merge + Rerank"]
WM -->|"reflect node"| EM
EM -->|"reflect node"| Neo4j
EM -->|"reflect node"| PGV
Neo4j -->|"graph expansion"| RRF
PGV -->|"cosine search"| RRF
RRF -->|"merged candidates"| WM
This repository is an extraction of production patterns from a proprietary agentic platform, sanitized for public consumption. It is not a tutorial, starter kit, or SaaS template.
It exists to demonstrate architectural thinking in two domains that rarely overlap:
- Senior monorepo engineering — Yarn 4 workspaces, Turborepo build orchestration, shared TypeScript configs, contract-first package design with Zod schemas as the source of truth.
- Production agentic systems — LangGraph state machines with crash-safe idempotent writes, hybrid symbolic + dense memory retrieval via Neo4j and pgvector, OpenTelemetry instrumentation at the graph-node level.
The agent's domain logic is intentionally trivial (a single system prompt: "You are a helpful research assistant."). The value is in the chassis — how the pieces connect, how memory is structured, how observability is wired, and how the monorepo scales.
git clone https://github.com/<owner>/agent-native-monorepo
cd agent-native-monorepo
yarn install
docker compose up -d # Postgres + pgvector, Neo4j, Redis
yarn dev # Starts all services in dev mode
# Request/response mode
curl -X POST http://localhost:3001/runs \
-H 'Content-Type: application/json' \
-d '{"sessionId": "550e8400-e29b-41d4-a716-446655440000", "messages": [{"role": "user", "content": "What is LangGraph?"}]}'
# Streaming mode (SSE)
curl -N -X POST http://localhost:3001/runs/stream \
-H 'Content-Type: application/json' \
-d '{"sessionId": "550e8400-e29b-41d4-a716-446655440000", "messages": [{"role": "user", "content": "What is LangGraph?"}]}'- Node.js 20.x or 22.x (not required for Full-Stack Docker)
- Docker and Docker Compose
- A Google AI Studio API key (set
GOOGLE_API_KEYin.env)
Copy .env.example to .env and fill in your API key:
cp .env.example .envTo run the entire stack (infra + all apps) in Docker without Node.js installed:
cp .env.example .env
# Set GOOGLE_API_KEY in .env
docker compose --profile full up --build| Service | URL |
|---|---|
| Console | http://localhost:8080 |
| Gateway | http://localhost:3001 |
| Agent Service | http://localhost:3000 |
| Neo4j Browser | http://localhost:7474 |
docker compose up (without --profile) still starts only the infrastructure services for local yarn dev development.
The memory system is divided into three tiers with distinct scopes, persistence strategies, and access patterns.
Per-run, in-process state held in the LangGraph AgentState object. Accumulates intermediate reasoning, tool outputs, and retrieved context. Destroyed at run completion — no external I/O.
Session-scoped turn history persisted in Postgres via Drizzle ORM. Records the full conversation per session_id with a configurable TTL (default 90 days). Serves as raw material for Semantic tier promotion.
This is the architectural differentiator. Long-term memory is maintained across two complementary indices, written atomically by the
reflectnode.
| Index | Technology | What It Stores | Retrieval Pattern |
|---|---|---|---|
| Knowledge Graph | Neo4j 5 | Entities (:Concept, :Fact) and relationships |
Bounded multi-hop Cypher traversal |
| Dense Embeddings | pgvector | Distilled fact embeddings (768-dim) | Cosine similarity via <=> operator |
Why both? Dense search finds semantically similar facts (paraphrase, synonym variants) but cannot follow relational chains. Graph traversal follows explicit relationships (A→B→C) but misses paraphrase variants. Together, they provide complementary recall paths that reduce false negatives. Results are merged via Reciprocal Rank Fusion (RRF).
| Node | Purpose | Key Input Fields | Key Output Fields | Side Effects |
|---|---|---|---|---|
ingress |
Validate request, seed state | Raw HTTP body | Full AgentState |
None |
retrieve |
Hybrid semantic recall | messages |
retrievedContext |
pgvector query, Neo4j traversal |
plan |
LLM planning step | messages, retrievedContext |
plan, tokenCounts |
LLM API call |
act |
Tool execution loop | plan |
toolOutputs, stepCount |
Tool invocations |
reflect |
Memory consolidation | Full state | (none — side-effect node) | Episodic write, Neo4j MERGE, pgvector upsert |
egress |
Validate output, build response | Full state | outcome |
None |
- Fork the repository and create a feature branch.
- Read
.context/conventions.mdfor code style and naming rules. - Follow the step-by-step guides in
.context/workflows.mdfor:- Adding a new graph node
- Adding a new package
- Adding a new memory adapter
- Use the specialized subagent prompts in
.agents/if working with AI coding tools. - See
AGENTS.mdfor cross-tool compatibility notes (Cursor, Kilo Code, Continue, Aider). - Run
yarn turbo typecheck && yarn turbo lintbefore submitting a PR. - Use Conventional Commits:
feat:,fix:,chore:,test:,docs:,ci:.