<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[recxcoder]]></title><description><![CDATA[recxcoder]]></description><link>https://recxcoder.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 28 Oct 2026 00:54:05 GMT</lastBuildDate><atom:link href="https://recxcoder.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[I gave my AI agent a memory — here's what changed]]></title><description><![CDATA[How I extended Genesis Agent with a FalkorDB knowledge graph and built something that actually learns across sessions. I've been building Genesis Agent…]]></description><link>https://recxcoder.hashnode.dev/i-gave-my-ai-agent-a-memory-here-s-what-changed</link><guid isPermaLink="true">https://recxcoder.hashnode.dev/i-gave-my-ai-agent-a-memory-here-s-what-changed</guid><category><![CDATA[AI]]></category><category><![CDATA[Python]]></category><category><![CDATA[graph database]]></category><category><![CDATA[agents]]></category><category><![CDATA[falkordb]]></category><dc:creator><![CDATA[Shivam Vishwakarma]]></dc:creator><pubDate>Sun, 18 Oct 2026 15:16:06 GMT</pubDate><content:encoded><![CDATA[<h1>I gave my AI agent a memory — here's what changed</h1>
<blockquote>
<p>How I extended Genesis Agent with a FalkorDB knowledge graph and built something that actually learns across sessions.</p>
</blockquote>
<hr />
<p>I've been building Genesis Agent from scratch in pure Python — no LangChain, no frameworks, just the fundamentals one layer at a time.</p>
<p>Part 1 was the basic LLM loop. Part 2 added web search. Part 3 added URL browsing and article reading. Part 4 added LLM-as-Judge verification.</p>
<p>Every version had the same problem: <strong>the agent forgot everything the moment you closed the terminal.</strong></p>
<p>Ask it about FalkorDB today — it searches the web, reads 3 pages, extracts facts, gives you a great answer. Ask it the same question tomorrow — it does the exact same work again. Re-fetches the same URLs. Re-extracts the same facts. Re-verifies the same claims. Complete amnesia.</p>
<p>For this hackathon — Graph Hacks: Context for AI Agents by WeMakeDevs × FalkorDB — I fixed that.</p>
<hr />
<h2>The wrong solution I almost built</h2>
<p>My first instinct was a vector database. Store embeddings of everything the agent reads, do similarity search before fetching new URLs.</p>
<p>It would have worked. But it would have missed the point.</p>
<p>A vector DB finds <em>similar</em> content. A graph finds <em>connected</em> content. Those are fundamentally different things.</p>
<p>When the agent reads that "FalkorDB uses Cypher" and "Neo4j uses Cypher" — a vector DB sees two similar sentences. A graph sees two nodes that share a relationship edge pointing to the same concept. The second time you ask something related, the graph doesn't just find similar text — it <em>traverses connections</em>.</p>
<p>That's not a subtle difference. That's the whole point of graph memory for agents.</p>
<hr />
<h2>What I built: Genesis Agent + FalkorDB</h2>
<p>The idea is simple. Every time the agent does something, it writes to a graph:</p>
<ul>
<li>Searched for a query → <code>Query</code> node</li>
<li>Visited a URL → <code>WebPage</code> node, linked to the query</li>
<li>Extracted a fact → <code>Fact</code> node, linked to the page</li>
<li>Verified the fact → <code>Verdict</code> node, linked to the fact</li>
</ul>
<pre><code>(Session) -[:CONTAINED]-&gt; (Query)
(Query)   -[:FOUND]-&gt;      (WebPage)
(WebPage) -[:MENTIONS]-&gt;   (Fact)
(Fact)    -[:VERIFIED_BY]-&gt; (Verdict)
</code></pre>
<p>Every research session builds up a persistent knowledge graph. The next session inherits it.</p>
<p>Before every single LLM call, a <strong>Context Builder</strong> reads the graph and injects what the agent already knows into the system prompt:</p>
<pre><code>## What you have already searched for:
- what is FalkorDB
- FalkorDB vs Neo4j

## Verified facts you already know:
- [0.94] FalkorDB is a graph database built on Redis (source: falkordb.com)
- [0.91] FalkorDB uses the Cypher query language (source: falkordb.com)

## Related facts from prior research:
- [0.89] Cypher is a declarative graph query language (source: neo4j.com)
</code></pre>
<p>The LLM sees this before making any decision. It knows what it already knows. It doesn't repeat itself.</p>
<hr />
<h2>The multi-hop query that makes it real</h2>
<p>This is the part that actually impressed me when I saw it work.</p>
<pre><code class="language-cypher">MATCH (s:Session)-[:CONTAINED]-&gt;(q:Query)
      -[:FOUND]-&gt;(w:WebPage)
      -[:MENTIONS]-&gt;(f:Fact)
WHERE toLower($topic) CONTAINS toLower(q.text)
  AND f.verified = true
RETURN f.text, f.confidence
ORDER BY f.confidence DESC
LIMIT 5
</code></pre>
<p>One query. Four hops. Traverses the entire research history in milliseconds and returns only the verified, high-confidence facts relevant to the current topic.</p>
<p>No embeddings. No vector similarity. Pure graph traversal.</p>
<hr />
<h2>The demo that sold me on this approach</h2>
<p>Run 1 — fresh session:</p>
<pre><code>Enter session ID (or press Enter for new): [Enter]
Enter prompt: What is FalkorDB?

🆕 New session: sess_a1b2c3
🔍 Search needed — gathering context...
🌐 Browsing top 3 URLs...
   📌 [0.94] FalkorDB is a graph database built on Redis...
   📌 [0.91] FalkorDB uses Cypher query language...
   📌 [0.88] FalkorDB supports multi-graph architecture...
✅ GOAL COMPLETED
🆔 Session: sess_a1b2c3
</code></pre>
<p>Run 2 — same session, related question:</p>
<pre><code>Enter session ID: sess_a1b2c3
Enter prompt: How does FalkorDB compare to Neo4j?

♻️  Resuming session: sess_a1b2c3
🧠 Found relevant facts in graph memory — skipping redundant search
✅ GOAL COMPLETED
Result: 1 iteration, completed: True
</code></pre>
<p>Second run. One iteration. No web requests. Answered from memory.</p>
<p>The agent didn't just remember — it <em>used</em> what it remembered to skip work it didn't need to do.</p>
<hr />
<h2>The key file: <code>context_builder.py</code></h2>
<p>The whole memory system comes down to 30 lines:</p>
<pre><code class="language-python">def build_context(session_id: str, current_query: str) -&gt; str:
    
    prior_queries  = get_prior_queries(session_id)
    known_facts    = get_known_facts(session_id, limit=8)
    related_facts  = multihop_related_facts(session_id, current_query)

    if not prior_queries and not known_facts:
        return "No prior knowledge found. Start fresh research."

    parts = []

    if prior_queries:
        lines = "\n".join(f"- {q}" for q in prior_queries)
        parts.append(f"## What you have already searched for:\n{lines}")

    if known_facts:
        lines = "\n".join(f"- {f}" for f in known_facts)
        parts.append(f"## Verified facts you already know:\n{lines}")

    if related_facts:
        lines = "\n".join(f"- {f}" for f in related_facts)
        parts.append(f"## Related facts from prior research on '{current_query}':\n{lines}")

    return "\n\n".join(parts)
</code></pre>
<p>This runs before every LLM call. The LLM never makes a decision without seeing what the agent already knows. That's it. That's the whole memory system.</p>
<hr />
<h2>What was hard</h2>
<p><strong>1. Getting Cypher direction right</strong></p>
<p>I had this query:</p>
<pre><code class="language-cypher">WHERE toLower(q.text) CONTAINS toLower($topic)
</code></pre>
<p>It always returned zero results. The bug: prior queries are short ("FalkorDB"), current topics are long ("What makes FalkorDB fast?"). The short string needs to be contained in the long string — not the other way around.</p>
<pre><code class="language-cypher">WHERE toLower($topic) CONTAINS toLower(q.text)  -- correct
</code></pre>
<p>One word swap. Took me an embarrassingly long time to catch.</p>
<p><strong>2. Fallback confidence scores polluting the graph</strong></p>
<p>When the LLM-as-Judge API call fails — rate limit, timeout, malformed JSON — I was defaulting to <code>confidence = 0.5</code>. That's "uncertain", which means those facts were being included in context injections.</p>
<p>The fix: fail to <code>0.0</code>. A fact that couldn't be verified has zero confidence, <code>verified = false</code>, and gets filtered out by <code>WHERE f.verified = true</code>. Failures stay out of the graph context.</p>
<p><strong>3. The model name mystery</strong></p>
<p>Groq's free tier in India (<code>ap-south-1</code>) doesn't have <code>llama-3.3-70b-versatile</code>. I discovered this mid-build when the API kept returning <code>model_not_found</code>.</p>
<p>The fix was listing available models programmatically:</p>
<pre><code class="language-python">models = client.models.list()
for m in models.data:
    print(m.id)
</code></pre>
<p><code>openai/gpt-oss-120b</code> is available and works great. Better than expected for structured JSON outputs.</p>
<hr />
<h2>RAG vs Graph — the honest comparison</h2>
<p>I keep seeing people reach for vector DBs by default. Here's when a graph is genuinely better:</p>
<table>
<thead>
<tr>
<th></th>
<th>RAG (vector)</th>
<th>Graph memory</th>
</tr>
</thead>
<tbody><tr>
<td>Finds</td>
<td>Similar content</td>
<td>Connected content</td>
</tr>
<tr>
<td>Tracks</td>
<td>Nothing</td>
<td>Source → fact → verdict</td>
</tr>
<tr>
<td>Across sessions</td>
<td>Stateless</td>
<td>Persistent</td>
</tr>
<tr>
<td>Reasoning trace</td>
<td>None</td>
<td>Full path in graph</td>
</tr>
<tr>
<td>Deduplication</td>
<td>Hard</td>
<td>Built-in via MERGE</td>
</tr>
<tr>
<td>Multi-hop</td>
<td>No</td>
<td>Native</td>
</tr>
</tbody></table>
<p>For an agent that needs to <em>reason</em> over what it knows — not just retrieve similar text — the graph is the right tool.</p>
<hr />
<h2>What's next</h2>
<p>This is Part 5 of the Genesis Agent series. Part 6 will add:</p>
<ul>
<li>Cross-session memory: one shared graph across all users, not per-session isolation</li>
<li>Agent self-reflection: the agent queries its own mistake history before acting</li>
<li>Graph pruning: automatically remove low-confidence facts after N sessions</li>
</ul>
<p>The codebase is on GitHub at <a href="https://github.com/recxcoder/genesis-graph">github.com/recxcoder/genesis-graph</a>.</p>
<p>If you're building agents and haven't tried FalkorDB yet — the free cloud tier takes 5 minutes to set up and the Python client is clean. Worth experimenting with.</p>
<hr />
<p><em>Built for Graph Hacks: Context for AI Agents by WeMakeDevs × FalkorDB</em><br /><em>by Shivam Vishwakarma — <a href="https://github.com/recxcoder">@recxcoder</a></em></p>
]]></content:encoded></item></channel></rss>