PTENES
MODULE 6.3

🧠 Multi-Agent Memory + /sessionend

One shared brain among your AI agents, working across machines, tools, and frameworks. Save a fact in one agent, retrieve it from another, and get a briefing from a third. And the ritual /sessionend that makes every session leave the whole system smarter.

6
Topics
55
Minutes
Advanced
Level
System
Type
Claude Code Autonomous agent n8n / scripts 🧠 Brain shared memory dedup → supersede → decay LLM consolidation (6h) session briefing

Illustrative diagram · agents write to the brain (rose); it processes and returns briefings (cyan) at the start of each session.

1

🧠 The problem: agents that forget

You run several agents—one for development, one autonomous agent for tasks, and automations for workflows. Each keeps its own context and forgets everything between sessions. When one discovers something important, the others never find out. That’s the problem that justifies a shared brain.

⚠️ Why key-value isn’t enough

Existing solutions are either single-machine, require a paid cloud service, or treat memory as a flat key-value bag — without understanding that a fact and one event are fundamentally different things, with different life cycles. Real memory needs types.

✓ With a shared brain

  • ✓What one agent learns becomes available to everyone.
  • ✓Works across machines, tools, and frameworks.
  • ✓The session starts with an understanding of what changed since last time.

✗ Without it

  • ✗Each agent lives in its own context bubble.
  • ✗Total amnesia at the start of every new session.
  • ✗Valuable discoveries don't propagate.
Isolation

Separate context.

Amnesia

Forget between sessions.

Silos

Discoveries get stuck.

Solution

Shared brain.

2

🧩 The 4 types of memory

Here’s the central idea: a fact and an event are different things. The system understands four types, each with its own lifecycle and mutation rule. This taxonomy is what separates a real memory system from a pile of strings.

TypeBehaviorExample
eventAppend-only, immutable. You don’t update history; you record it."Workflow failed at 3 a.m."
factUpsert by key. New fact supersedes the old one."API status: healthy"
statusIn-place update by subject. The latest one wins."migration: 70%"
decisionAppend-only with reasoning. The why matters."Postgres instead of MySQL because..."

📊 It’s not taxonomy for its own sake

Typing tells the system how each memory should behave when it changes: a fact is superseded, a status is overwritten, an event is permanent, and a decision is a reasoning record. Different data, different rules. Without this, everything becomes the same blob, and you lose the ability to version it and trust what’s active.

Event

Immutable.

Fact

Upsert by key.

Status

Last one wins.

Decision

Keep the why.

3

🔄 The Memory Lifecycle

Each memory goes through a pipeline. That’s what keeps the brain useful instead of turning into a repository that only grows. Four mechanisms work together: deduplication, supersession chains, confidence decay, and LLM consolidation.

Store ──> Dedup ──> Supersedes ──> Decay ──> Consolidation (LLM) │ │ │ │ │ saves same hash? same key? fades over groups, merges, returns marks old time without finds connections existing as inactive access and insights
1

Deduplication

Content is hashed with SHA-256 when saved. Exact duplicates are caught; consolidation still catches near-duplicates at 92% semantic similarity.

2

Supersedes chain

Recorded a fact with the same key? The old one is marked inactive, and the new one points back to it. Free version history, with no manual work.

3

Trust decay

Facts and status lose ~2%/day if no one accesses them. Search ranks by similaridade × confiança. Old knowledge sinks on its own; access resets the clock. Events and decisions don’t decay—they’re history.

4

LLM consolidation (every 6h)

A background process analyzes new memories: merges duplicates, flags contradictions, discovers connections, and extracts cross-cutting insights. It’s a librarian that organizes knowledge instead of letting it pile up.

💡 The brain improves while you sleep

Periodic consolidation is the differentiator. While ordinary systems only accumulate, this one reorganizes: the first pass after an upgrade automatically cleared hundreds of junk memories. Decay + consolidation = memory that ages like human memory, forgetting what’s irrelevant.

4

🛡️ Security and isolation

Shared memory among agents that run without supervision is only viable with a well-designed gatekeeper. The API is the gatekeeper: no agent touches the database directly. They can store and retrieve—and that's it.

✓ What an agent CAN do

  • ✓Record and search memories through validated endpoints.
  • ✓Read briefs, stats, and entities.

✗ What NOT to do

  • ✗Deleting memories or dropping tables.
  • ✗Bypass credential cleanup.
  • ✗Access the database directly or alter someone else's memory.

🔐 Credential scrubbing

All content is cleaned before storage: API keys, JWTs, SSH keys, passwords, and base64 secrets are redacted automatically. Agents share context freely without leaking credentials into long-term memory.

⚠️ The worst case is good data, not destruction

It’s by design: if an autonomous agent hallucinates or goes off script, the worst it can do is write bad data — cannot destroy good data. Add timing-safe auth and rate limiting (10 failures/min = lockout). The basics done right.

Gatekeeper

API validates everything.

Scrubbing

No credentials.

Isolation

Doesn’t touch the database.

Auth

Timing-safe + limit.

5

📊 Session briefings

This is where coordination between agents actually happens — passively. Every session starts with a question: "what's happened since I was last here?". The briefing endpoint returns updates from all the other agents, excluding your own.

Illustrative recreation of a briefing call (not a real screenshot):

GET /briefing?since=2026-06-13T00:00:00Z&agent=claude-code → events: 1 · "n8n: workflow daily-report failed (Thursday 11 p.m.)" → facts: 2 · "acme client ranking rose to #3" → status: 1 · "db-migration: completed" → decisions:1 · "chose Qdrant for vectors — filterable search"

In practice: the dev agent opens a session on Friday morning and already knows that a workflow failed on Thursday night and another agent discovered something about a client’s ranking—without checking logs or remembering to look. The system surfaces it.

✓ Good briefing practices

  • ✓Call in beginning for each session.
  • ✓Exclude your own entries (they’re already known).
  • ✓Sort by importance, then recency.

✗ Antipatterns

  • ✗Rely on human memory to “go check the logs.”
  • ✗Bring everything without filtering by importance—it becomes noise.
  • ✗Include its own entries and clutter the brief.

💡 Practical tip

Treat the briefing as the agent’s mandatory “good morning.” Put the call at the start of your session-opening flow—this makes coordination between agents a system habit, not something that depends on you remembering. It’s the natural counterpart to /sessionend: one opens, the other closes.

"Since when?"

Timestamp.

From others

Exclude itself.

Categorized

By type.

Passive

Effortless coordination.

6

🔥 The /sessionend Ritual

O /sessionend is a skill that closes the loop of compound intelligence. At the end of each session, it turns what happened into institutional memory. The point isn’t just to summarize — it’s to evaluate honestly and save the result in a structured way.

1

Gather — collect the artifacts

Runs git log, diff, status and reviews the conversation history: what was requested, which tools were used, what worked, and what needed a retry.

2

Reflect — reflect honestly

What went well, what went poorly, and how it could have been better. "Everything went well" is not valid reflection — if something was suboptimal, name it. That’s the rule that adds the most value.

3

Store — save in memory

Saves a structured summary (what was done · what went well · what went poorly · how to improve · relevant to other agents) under a dated topic.

4

Update — update local memory

Only save what's genuinely new: preferences, project facts, information about the user. Update the index. Don't save again what has already been captured.

♾️ Why this composes

The end of a session feeds the consolidation, which feeds the briefing of the next session. Each session makes all future sessions smarter—not just for that agent, but for everyone. It's the same self-improvement loop as 6.1 (Workflow Spotter) and 6.2 (Taproot), now at the system memory level.

Prompt · start the session
"O que aconteceu desde a última vez que estive aqui?
Traga o briefing de todos os outros agentes desde ontem,
ordenado por importância. Exclua minhas próprias entradas."
Prompt · end the session
/sessionend

# (ou, sem a skill instalada:)
"Encerre a sessão: reúna git log/diff, reflita com honestidade
(o que foi bem, o que foi mal — 'tudo certo' NÃO vale), guarde
um resumo estruturado e atualize a memória local só com o novo."

📤 Output example

Illustrative recreation of the final summary that /sessionend prints for the user (not a real screenshot):

Session ended. Stored in memory: session-reflection/curso-trilha6/2026-06-15 Done: Built Track 6 (3 modules) in the INEMA format. Went well: SVGs rendered on the first try; consistent light mode. Could improve: validate the line count before wrapping up. Memory: yes — updated project_curso.md with the rose pattern.

🏋️ Hands-on exercises

1

Classify 5 memories

Choose 5 pieces of information from your recent work and classify each as event, fact, status, or decision. Explain why the type matters in each case.

2

Design your brief

List your agents/tools and write the briefing question each one would ask at startup. Define the sorting criteria (importance × recency).

3

Create a runnable /sessionend SKILL.md

Write a shutdown skill that adapts to any memory backend. Skeleton:

--- name: sessionend description: "End-of-session ritual. Use when the user types /sessionend or says they're finished/going to wrap up. Gather what happened, reflect honestly, and save a structured summary." --- # Session End ## 1. Gather git log --oneline --since="8 hours ago"; git diff --stat; git status Review the conversation: what was requested, tools, retries. ## 2. Reflect (honestly — “everything’s fine” is forbidden) - What went well? · What went poorly? · How can we improve? ## 3. Store (structured summary) topic: session-reflection/{projeto}/{AAAA-MM-DD} sections: done · went well · went poorly · improve · cross-agent ## 4. Update local memory (only what’s new) ## 5. Brief user output (no wall of text)

Save in ~/.claude/skills/sessionend/SKILL.md and test by typing "/sessionend" at the end of a work session. Works with any memory backend (or locally only).

📌 Module summary

✓
The problem — isolated agents forget between sessions; plain key-value storage isn't enough.
✓
4 types — event, fact, status, decision; each with its own mutation rule.
✓
Lifecycle — dedup, supersede, decay, and LLM consolidation keep the brain useful.
✓
Security — API gatekeeper, credential scrubbing, agent isolation.
✓
Briefing + /sessionend — close the loop: each session makes all future ones smarter.

You’ve reached the end

This is the final lesson of the course. From the anatomy of SKILL.md (T1) to multi-agent memory, you've covered the full path of Claude Skills in Practice.