How to Give Your AI Agent a Real Memory with Garry Tan's GBrain

Akram Chauhan
Akram Chauhan
9 min read575 views
How to Give Your AI Agent a Real Memory with Garry Tan's GBrain

Let's be honest. For all their brilliance, most AI agents have the memory of a goldfish.

You can have an amazing, in-depth conversation, solve a complex problem, map out a whole strategy... and the next time you open the chat, it's a blank slate. The agent has no idea who you are or what you talked about. It's like meeting a new intern every single morning.

It’s a huge problem. How can we build truly useful, long-term assistants if they can't remember anything?

Well, Garry Tan, the President and CEO of Y Combinator, got tired of this problem and decided to build a fix for his own AI agents. He calls it GBrain, and it's an open-source project you can use right now to give your agent a persistent, self-organizing brain.

Think of it as a personal knowledge base that not only stores information but automatically connects the dots. It ingests your notes, meetings, emails, and tweets, and then builds a knowledge graph on top of it all—without needing an expensive LLM call every five seconds. This is the real deal, powering his actual agents with a brain that holds over 146,000 pages of information.

The best part? We're going to build a mini-version of this brain right now. In about 20 minutes, you'll have a working GBrain instance on your machine, complete with a knowledge graph and the ability to hook it into an agent like Claude.

Ready? Let's get started.

What You're Actually Building Today

By the end of this walkthrough, you’ll have a few cool things set up:

  • A local "brain" database: It uses something called PGLite, which is basically a full-featured Postgres database that runs locally without any server setup. Super simple.
  • A small collection of notes: We'll create a few markdown files about people and companies to act as our brain's first memories.
  • A powerful search tool: You'll be able to search your notes using a smart hybrid of keyword and vector search.
  • An auto-generated knowledge graph: This is the magic part. GBrain will automatically figure out that "Alice Chen" is the founder of "Acme AI" just from your notes.
  • A connection to Claude: We'll set it up so an AI agent can directly read from and write to your new brain.

First, a Few Things You’ll Need

Don't worry, the list is short.

  • macOS or Linux: If you're on Windows, you can use WSL2.
  • A code editor: VS Code, Sublime, whatever you like.
  • Bun: This is the JavaScript runtime GBrain is built on. We'll install it in the first step, so no sweat if you don't have it.
  • An embedding API key (optional but recommended): To get the full power of hybrid search, you'll want a key from ZeroEntropy (the default), OpenAI, or Voyage. You can still do the whole tutorial without one, you just won't be able to run the vector search part.
  • An Anthropic API key (also optional): This helps the search feature get even smarter, but it's not required.

Got all that? Awesome. Let's dive in.

Step 1: Install Bun and GBrain

First things first, we need to install Bun. It’s a super-fast JavaScript toolkit, and it’s what makes GBrain tick.

Pop open your terminal and run this command:

curl -fsSL https://bun.sh/install | bash
exec $SHELL # this reloads your shell so the 'bun' command is available
bun --version

Once that's done, installing GBrain is a one-liner. This command installs it globally on your system.

bun install -g github:garrytan/gbrain
gbrain --version # should show something like gbrain 0.38.2.0

And that's it! The software is installed.

Step 2: Create a Home for Your Brain

Now, we need to initialize your brain. This command creates the local PGLite database file right in your home directory.

We're going to add the --no-embedding flag for now. This just means we'll set up the API key for vector search a little later. It lets you follow along even if you don't have a key handy yet.

gbrain init --pglite --no-embedding

You'll see a bunch of text fly by as it sets up the database schema. It should end with something like this:

Setting up local brain with PGLite (no server needed)...
...
Brain ready at /home/you/.gbrain/brain.pglite
0 pages. Engine: PGLite (local Postgres).

You now officially have an empty brain. You can check its status anytime with:

gbrain stats

Step 3: Give Your Brain Its First Memories

Your brain's knowledge lives in a simple folder of markdown (.md) files. This is your "brain repo." The structure is simple: a main section at the top with the current, most accurate info, and a timeline of events or notes at the bottom.

Here's the one "gotcha" you need to remember: when you link between notes (using [[wikilinks]]), you have to use the full path, like [[people/alice-chen]], not just [[alice-chen]]. I learned this the hard way—the short version just fails silently.

Let's create a folder and a few files to play with.

mkdir -p ~/my-brain/people ~/my-brain/companies ~/my-brain/concepts
cd ~/my-brain

Now, create a file for a person named Alice Chen.

cat > people/alice-chen.md <<'EOF'
---
type: person

tags: [founder, ai-infra]
---
Founder and CEO of [[companies/acme-ai]]. Previously staff engineer at Google Brain. Focus area: inference optimization for small language models.
---
- 2024-03-12: Met at AI Engineer Summit. Discussed sparse MoE routing.
- 2024-09-04: Announced $12M seed led by Sequoia.
- 2025-01-18: Shipped open-source inference router on GitHub.
EOF

Next, a file for her company, Acme AI. Notice how we link back to her.

cat > companies/acme-ai.md <<'EOF'
---
type: company

tags: [startup, inference]
---
YC W24 inference-optimization startup. Founded by [[people/alice-chen]]. Building latency-aware routing for sub-7B models.
---
- 2024-09-04: $12M seed, led by Sequoia.
- 2025-01-18: Open-sourced their inference router.
EOF

And finally, a file for a concept.

cat > concepts/inference-optimization.md <<'EOF'
---
type: concept

tags: [ml-systems]
---
Techniques to reduce latency and cost when serving language models: quantization, speculative decoding, KV-cache reuse, and request batching.
EOF

That's it. We have our source material.

Step 4: Import the Notes into GBrain

Time to load these memories into the database. The import command is smart; if you run it again, it won't create duplicates.

Just like before, we'll use --no-embed to skip the vectorizing step for now.

gbrain import ~/my-brain/ --no-embed

The output will confirm that it found and imported your three new files.

[gbrain phase] import.collect_files start dir=/home/you/my-brain/ strategy=markdown
[gbrain phase] import.collect_files done 2ms files=3
Found 3 markdown files
[import.files] 3/3 (100%) imported=3 skipped=0 errors=0
Import complete (0.3s): 3 pages imported
0 pages skipped (0 unchanged, 0 errors)
3 chunks created

You can see a list of all pages in your brain with gbrain list.

Step 5: Watch the Knowledge Graph Wire Itself

This is where things get really cool. We're going to tell GBrain to analyze the links between our notes and build the knowledge graph.

And here's the kicker: this process uses zero LLM calls. It's all done with clever, high-speed pattern matching.

gbrain extract links --source db

You should see it create two new links.

[extract.links_db] 3/3 (100%) done
Links: created 2 from 3 pages (db source)
Done: 2 links, 0 timeline entries from 3 pages

So what just happened? Based on the text, GBrain inferred two typed relationships:

  1. alice-chen --works_at--> acme-ai (because of "Founder and CEO of...")
  2. acme-ai --founded--> alice-chen (because of "Founded by...")

This is what separates GBrain from a simple vector database. You can now ask structured questions. Try this:

gbrain graph-query people/alice-chen --depth 1

It will show you exactly what it knows about Alice:

[depth 0] people/alice-chen
--works_at-> companies/acme-ai (depth 1)

Pretty neat, right? This structural understanding is why GBrain performs so much better on benchmarks. Answering "Who works at Acme AI?" is now a simple lookup, not a fuzzy similarity search.

Step 6: Let's Run a Search

GBrain gives you two ways to search. The first, gbrain search, is a simple but fast keyword search. It works without any API keys.

gbrain search "inference"

You'll get back results for both Alice's page and the Acme AI page, since they both mention the word.

But the real power comes from gbrain query, which uses the full hybrid search pipeline. To use it, we finally need to connect our embedding API key.

First, set your API key as an environment variable (replace sk-... with your actual key).

# Set ONE of these, depending on your provider
export OPENAI_API_KEY=sk-...
# export ZEROENTROPY_API_KEY=...
# export VOYAGE_API_KEY=...

Next, tell GBrain which model to use. Let's use OpenAI's text-embedding-3-large.

gbrain config set embedding_model openai:text-embedding-3-large

Now, run the embed command to go back and create vector embeddings for all the notes we've already imported.

gbrain embed --all

With that one-time setup done, you can now run a full hybrid query. This type of search understands the meaning behind your words, not just the keywords.

gbrain query "who works on small-model inference?"

This will give you much more relevant results by combining vector search, keyword search, and a smart reranker to put the best stuff at the top.

Step 7: Connect Your Brain to Claude

A personal knowledge base is great, but it's even better when your AI agent can use it directly. GBrain makes this incredibly easy using something called the Model Context Protocol (MCP). Think of it as a standard way for models to talk to external tools.

If you use the Claude Code desktop app, wiring this up is a single command:

claude mcp add gbrain -- gbrain serve

That's it. You can verify it's connected by running claude mcp list. Now, you can open Claude and say something like, "search the brain for inference optimization," and it will use your local GBrain instance to find the answer.

If you use other tools like Cursor or Windsurf, you just need to add a small JSON snippet to their settings. The command is the same: gbrain serve.

{
  "mcpServers": {
    "gbrain": {
      "command": "gbrain",
      "args": ["serve"]
    }
  }
}

This opens up 74 different tools for your agent, from get_page and put_page to search, query, and add_link. Your agent now has a persistent memory it can read from and write to.

Step 8: Put Your Brain on Autopilot

GBrain even comes with a built-in "autopilot" to keep itself healthy and up-to-date. You can run a one-time checkup and remediation with the doctor command:

gbrain doctor --remediate --yes --target-score 90 --max-usd 5

This will analyze the health of your brain, figure out what needs to be done (like embedding new notes or extracting new links), and run the jobs for you, all while staying under a budget you set.

Or, you can set it up to run automatically in the background like a cron job:

gbrain autopilot --install

This will have it check in every five minutes. If the brain is healthy, it sleeps. If it's not, it kicks off a cycle to sync, extract, embed, and consolidate new information.

So, What Did We Just Do?

Let's zoom out for a second. We took a simple folder of markdown files—our source of truth that we can edit anytime—and layered a powerful retrieval system on top of it.

That system, GBrain, created a database (PGLite), indexed our notes for both keyword and vector search, and—most importantly—built a typed knowledge graph by understanding the relationships within our text.

An AI agent can now tap into this brain to get information, and we can keep adding to it over time. Every new note, every captured thought, makes the agent smarter and more context-aware.

This is a huge step beyond the amnesiac agents we're used to. It's the foundation for a truly personal AI that learns and grows with you. The longer you run it, the more valuable it becomes. Your agent finally has a memory.

Tags

AI Agentic AI AI Engineering AI System Design Open Source AI Software Development AI Memory AI agents AI agent development Building AI Agents Coding Tutorial Garry Tan GBrain Y Combinator Persistent AI Memory AI Knowledge Graph Long

Stay Updated

Get the latest articles and insights delivered straight to your inbox.

We respect your privacy. Unsubscribe at any time.

Aicosoft

AI & Technology News, Insights & Innovation

AICOSOFT delivers cutting-edge AI news, technology breakthroughs, and innovation insights. Stay informed about artificial intelligence, machine learning, robotics, and the latest tech trends shaping tomorrow.

Connect With Us

© 2026 Aicosoft. All rights reserved.