About Portfolio Cases Services Blog Contact 🎙 Talk to AI
EN DE RU
🎙 Talk to AI
August 30, 2026 · 3 min read

How to Avoid Losing Control Over AI Agents: New Local-First Memory Layer for Private Multi-Agent Systems

I’m Denis Shokhirev, Agentic AI Systems Architect based in Freiburg, Germany, and founder of DennisCraft AI Studio. My stack: Claude, Supabase, n8n, Doppler, and self-hosted Postgres. In production—especially for DACH B2B logistics and fintech—I’ve repeatedly seen multi-agent systems lose context, repeat the same failing actions, and drift out of compliance. It’s never in the demo, always in the first month of real traffic. Why Standard Agent Memory Patterns Fail in Private, Regulated Systems

Denis Shokhirev
Denis Shokhirev
Agentic AI Systems Architect
Telegram LinkedIn

I’m Denis Shokhirev, Agentic AI Systems Architect based in Freiburg, Germany, and founder of DennisCraft AI Studio. My stack: Claude, Supabase, n8n, Doppler, and self-hosted Postgres. In production—especially for DACH B2B logistics and fintech—I’ve repeatedly seen multi-agent systems lose context, repeat the same failing actions, and drift out of compliance. It’s never in the demo, always in the first month of real traffic.

Why Standard Agent Memory Patterns Fail in Private, Regulated Systems

Most LLM agent frameworks either use cloud vector DBs/APIs for memory or rely on short in-context chains without persistent state. This doesn’t cut it in production for three reasons:

  • Lack of traceability: Impossible to reconstruct why an agent made a given decision post-factum.
  • Data exposure: Cloud-based memory layers can violate GDPR/DSGVO and internal audit requirements.
  • Unstable agent behavior: Without persistent local memory, agents forget failed actions and repeat mistakes.

On three separate deployments this year, I caught the same bug: Claude-powered agents running via n8n would get stuck in retry loops, hammering the same external API because their “memory” of previous attempts got lost between orchestrator runs. The cost and compliance risk was real.

Local-First Memory Layer: A Stable Pattern for Multi-Agent Production

The fix: implement a local, auditable memory layer using self-hosted Postgres or Supabase. This layer:

  • Persists every intermediate step of agent reasoning.
  • Links events across agents (e.g., who triggered what, which data was used, what action was taken).
  • Provides full auditability for debugging and compliance review.
  • Keeps all data inside the client perimeter—no external leaks, GDPR/DSGVO aligned.

Data Model: What to Track

TableDescriptionKey Fields
agent_sessionsReasoning sessions per agentsession_id, agent_id, started_at, status
agent_stepsEach step/action in agent reasoningstep_id, session_id, input, output, timestamp
agent_eventsExternal events (API calls, errors)event_id, step_id, event_type, payload

Example: Minimal Postgres Schema


CREATE TABLE agent_sessions (
  session_id UUID PRIMARY KEY,
  agent_id TEXT NOT NULL,
  started_at TIMESTAMP NOT NULL,
  status TEXT
);

CREATE TABLE agent_steps (
  step_id UUID PRIMARY KEY,
  session_id UUID REFERENCES agent_sessions(session_id),
  input JSONB,
  output JSONB,
  timestamp TIMESTAMP NOT NULL
);

CREATE TABLE agent_events (
  event_id UUID PRIMARY KEY,
  step_id UUID REFERENCES agent_steps(step_id),
  event_type TEXT,
  payload JSONB
);

Integrating with n8n and Supabase: Production-Grade Pipeline

My go-to pipeline using n8n and Supabase looks like this:

  1. n8n starts a process (e.g., incoming API call or business event).
  2. Before launching the agent, create a new entry in agent_sessions.
  3. Each agent reasoning step is a row in agent_steps (input, output, timestamp).
  4. External events (API calls, errors) are logged in agent_events.
  5. The entire chain is available for live audit (I expose it at live.gerdennisai.com).

This pattern immediately surfaces agent “looping,” repeated API calls, or lost context. For compliance, it provides a transparent audit trail showing which agent used what data and when.

n8n node: log agent reasoning step


{
  "operation": "insert",
  "table": "agent_steps",
  "data": {
    "step_id": $uuid(),
    "session_id": {{$json["session_id"]}},
    "input": {{$json["input"]}},
    "output": {{$json["output"]}},
    "timestamp": {{$now}}
  }
}

What Changes in Real-World Operation?

  • Agents don’t “loop” endlessly: You can set a max step limit per session and automatically flag suspicious behavior.
  • Reasoning errors are visible immediately: If an agent repeats the same action with different inputs, you’ll see it in the log—no more silent failures.
  • GDPR/DSGVO compliance: No step of agent reasoning leaves the client perimeter, not even temporary logs.
  • Easy to explain decisions: For fintech or logistics, this is critical—auditors get a full trace of agent actions.

The downside: storage use goes up if you have many agents and long reasoning chains. In my experience (4 B2B projects, 2024–2025), storage increased less than 15% over baseline Postgres usage.

FAQ

Can I build this memory layer without Supabase?

Yes, self-hosted Postgres is enough. Supabase just speeds up schema and API scaffolding.

How do I detect reasoning anomalies?

Aggregate agent_steps: if step count per session exceeds a threshold, flag it. Also track for repeated outputs or failed actions.

Does this slow down agent execution?

In my deployments, writing a step log to Postgres takes 15–30 ms (DennisCraft, 2024). For B2B tasks, this is negligible.

How do I purge agent memory for GDPR?

Set a TTL on agent_sessions and clean up related data via cron or n8n workflow.

Can agents share memory?

Link sessions via a mapping table, but make sure to enforce data isolation for private contexts.

Where do your agents most often lose context in production—at the LLM call, external API step, or orchestration logic? I’d genuinely like to know.
I run a free 30-min stack audit for DACH founders building AI in regulated markets. DM me on LinkedIn or write to @ger_dennis_ai.

Continue reading
Anthropic launches MHS: Claude can now control real-world hardware (robots, microscopes, lasers) — what this changes for business and security
How to Give AI Agents Real Working Memory: 90% Token Savings Without Quality Loss (graymatter, mcp-memory-service)
AI agents now install, execute, and test your code — not just suggest it. How to use open-source Goose to actually speed up delivery
Why 90% of AI Agent Frameworks Fail in Production: How to Pick One That Actually Works
All articles →
Ready to build?

Turn your process into an AI system

Fixed price. Production quality. DACH B2B focus.

Start a project → ← All articles