Skip to main content
The Davenporter
Essays Builds Now About
Theme
Palette

All builds

Freight Floor Multiplayer forklift game cosm / topocosm Go / Python SmartRouter Python Electric Sheep Python / SQL
  1. Home
  2. Builds
  3. Electric Sheep
Python / SQL

Electric Sheep: long-term memory for AI agents

Agents forget everything when a session ends. Electric Sheep reviews past sessions offline, finds what keeps proving true, and saves it as a lasting memory the next session can use.

Illustration of Electric Sheep AI dream cycle memory consolidation pipeline promoting episodic agent session logs into crystallized Google Cloud Spanner developer beliefs.
Electric Sheep turns raw session logs into verified, lasting memories stored in Cloud Spanner.
What it does

Electric Sheep in plain terms

Electric Sheep gives coding agents memory that lasts across sessions. Between sessions it runs a 'dream cycle': it groups similar events from past sessions and promotes a pattern to a lasting belief only after it has held up across several of them. Beliefs live in Cloud Spanner and agents read them through an MCP server.

How it works

Three things to know

  • Three levels of memory: the current session, the workspace, and global beliefs that apply everywhere.
  • A pattern has to show up in several sessions before it becomes a belief.
  • Agents reach it through MCP tools, so any MCP-capable agent can use it.

Sample result: 0.97 belief confidence in a sample run.

Learn more

Essays and source

Read the essay: WIBTM: Give an agent access to memories created with AI dreams → Related: 'Dark data' is your new most valuable data for AI → GitHub: Electric Sheep ↗
View a code sample (dream_consolidation.py) Python / SQL
File: dream_consolidation.py
from dataclasses import dataclass


@dataclass(frozen=True)
class EpisodicObservation:
    session_id: str
    rule_candidate: str
    success_rate: float


@dataclass(frozen=True)
class CrystallizedBelief:
    belief_id: str
    statement: str
    confidence: float
    supporting_sessions: int
    scope: str = "global"


def consolidate_dream_cycle(
    observations: list[EpisodicObservation],
    min_sessions: int = 3,
    min_confidence: float = 0.90,
) -> list[CrystallizedBelief]:
    """Promote recurring episodic observations into crystallized Spanner beliefs."""
    grouped: dict[str, list[EpisodicObservation]] = {}
    for obs in observations:
        grouped.setdefault(obs.rule_candidate.strip(), []).append(obs)

    promoted: list[CrystallizedBelief] = []
    for idx, (statement, items) in enumerate(sorted(grouped.items()), start=1):
        unique_sessions = {i.session_id for i in items}
        if len(unique_sessions) < min_sessions:
            continue
        avg_score = sum(i.success_rate for i in items) / len(items)
        confidence = round(min(0.99, avg_score * (1.0 + 0.02 * len(unique_sessions))), 2)
        if confidence >= min_confidence:
            promoted.append(
                CrystallizedBelief(
                    belief_id=f"BELIEF-{idx:03d}",
                    statement=statement,
                    confidence=confidence,
                    supporting_sessions=len(unique_sessions),
                )
            )
    return promoted
Run it: $ uv run python -m electric_sheep.dream --scope workspace --min-confidence 0.90
DREAM CONSOLIDATION COMPLETE · Scanned 18 session trajectories
PROMOTED BELIEF #042: 'Always run uv run pytest -v and maintain <3s unit test execution' (confidence=0.97)
SPANNER COMMIT: projects/davenport-boutique/instances/electric-sheep/databases/memory
About · Subscribe on Substack · RSS · Privacy ·
Ask

Social card and structured data

The share image, feeds and Schema.org JSON-LD that search engines and AI tools read for this page.

Social card

Title card for Electric Sheep
Card URL: /og/builds.svg

Machine feeds

/llms.txt /llms-full.txt /sitemap.xml /api/agent/spec

Structured data

{
  "@context": "https://schema.org",
  "@graph": [
    {
      "@type": "Person",
      "@id": "https://davenporter.com/#jason-davenport",
      "name": "Jason Davenport",
      "alternateName": "@davenportjw",
      "jobTitle": "AI & Distributed Systems Architect",
      "description": "Exploring agent-first source control (cosm), trajectory-to-lineage observability, Spanner-backed agent memory consolidation (Electric Sheep), hybrid local/cloud LLM routing, and real-time multiplayer browser simulations on Google Cloud Run.",
      "url": "https://davenporter.com",
      "sameAs": [
        "https://davenporter.substack.com",
        "https://www.linkedin.com/in/davenportjw",
        "https://github.com/davenportjw",
        "https://x.com/davenportjw",
        "https://medium.com/@davenportjw"
      ]
    },
    {
      "@type": "WebSite",
      "@id": "https://davenporter.com/#website",
      "url": "https://davenporter.com",
      "name": "The Davenporter",
      "description": "Learnings about software, technology, agentic systems, and occasionally home renovation.",
      "publisher": {
        "@id": "https://davenporter.com/#jason-davenport"
      },
      "inLanguage": "en-US"
    },
    {
      "@type": "ImageObject",
      "@id": "https://davenporter.com/builds/electric-sheep#primaryimage",
      "url": "https://davenporter.com/og/builds.png",
      "contentUrl": "https://davenporter.com/og/builds.png",
      "width": 1200,
      "height": 630,
      "caption": "Title card for Electric Sheep",
      "representativeOfPage": true,
      "creator": {
        "@id": "https://davenporter.com/#jason-davenport"
      },
      "license": "https://creativecommons.org/licenses/by/4.0/",
      "acquireLicensePage": "https://davenporter.com/writings"
    },
    {
      "@type": "WebPage",
      "@id": "https://davenporter.com/builds/electric-sheep#webpage",
      "url": "https://davenporter.com/builds/electric-sheep",
      "name": "Electric Sheep | Builds | The Davenporter",
      "description": "Electric Sheep gives coding agents memory that lasts across sessions. Between sessions it runs a 'dream cycle': it groups similar events from past sessions and promotes a pattern to a lasting belief only after it has held up across several of them. Beliefs live in Cloud Spanner and agents read them through an MCP server.",
      "isPartOf": {
        "@id": "https://davenporter.com/#website"
      },
      "about": {
        "@id": "https://davenporter.com/#jason-davenport"
      },
      "primaryImageOfPage": {
        "@id": "https://davenporter.com/builds/electric-sheep#primaryimage"
      },
      "inLanguage": "en-US"
    },
    {
      "@type": "FAQPage",
      "@id": "https://davenporter.com/builds/electric-sheep#faq",
      "mainEntity": [
        {
          "@type": "Question",
          "name": "What is Electric Sheep?",
          "acceptedAnswer": {
            "@type": "Answer",
            "text": "Electric Sheep gives coding agents memory that lasts across sessions. Between sessions it runs a 'dream cycle': it groups similar events from past sessions and promotes a pattern to a lasting belief only after it has held up across several of them. Beliefs live in Cloud Spanner and agents read them through an MCP server."
          }
        }
      ]
    },
    {
      "@type": "SoftwareSourceCode",
      "@id": "https://davenporter.com/builds#electric-sheep",
      "name": "Electric Sheep",
      "description": "Electric Sheep gives coding agents memory that lasts across sessions. Between sessions it runs a 'dream cycle': it groups similar events from past sessions and promotes a pattern to a lasting belief only after it has held up across several of them. Beliefs live in Cloud Spanner and agents read them through an MCP server.",
      "codeRepository": "https://github.com/davenportjw/agentic-memory",
      "programmingLanguage": "Python / SQL",
      "author": {
        "@id": "https://davenporter.com/#jason-davenport"
      }
    },
    {
      "@type": "BreadcrumbList",
      "@id": "https://davenporter.com/builds/electric-sheep#breadcrumb",
      "itemListElement": [
        {
          "@type": "ListItem",
          "position": 1,
          "name": "Home",
          "item": "https://davenporter.com/"
        },
        {
          "@type": "ListItem",
          "position": 2,
          "name": "Builds",
          "item": "https://davenporter.com/builds"
        },
        {
          "@type": "ListItem",
          "position": 3,
          "name": "Electric Sheep",
          "item": "https://davenporter.com/builds/electric-sheep"
        }
      ]
    }
  ]
}

Ask The Davenporter

Ask anything about the essays and builds on this site.