Drop in your own documents, ask anything, and watch three agents answer side by side: a plain LLM, an LLM with RAG, and an LLM reasoning through MemoryLayer. Only the last one grounds every claim — and refuses to guess when it can't.
No smoke. Three functions, one prompt each. The only difference is grounding and the verify()gate. Here's the actual code.
// 01 — Direct LLM. No grounding. This is the baseline that hallucinates.
import Groq from "groq-sdk";
const groq = new Groq({ apiKey: process.env.GROQ_API_KEY });
export async function direct(prompt) {
const r = await groq.chat.completions.create({
model: "llama-3.3-70b-versatile",
messages: [
{ role: "system", content: "You are a helpful AI assistant." },
{ role: "user", content: prompt },
],
});
return r.choices[0].message.content;
}// 02 — LLM + basic RAG. Retrieve, stuff, answer. Still guesses when docs miss.
import Groq from "groq-sdk";
const groq = new Groq({ apiKey: process.env.GROQ_API_KEY });
// MemoryLayer's recall() used purely as a retriever (explore:false = plain hybrid search).
async function retrieve(namespace, query) {
const res = await fetch(process.env.MEMORYLAYER_DEMO_URL + "/mcp", {
method: "POST",
headers: { "Content-Type": "application/json", "x-api-key": process.env.MEMORYLAYER_DEMO_KEY },
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call",
params: { name: "recall", arguments: { query, namespace, explore: false, limit: 6 } } }),
});
const j = await res.json();
return JSON.parse(j.result.content[0].text).results ?? [];
}
export async function rag(namespace, prompt) {
const hits = await retrieve(namespace, prompt);
const context = hits.map((h, i) => `[${i + 1}] ${h.content ?? h.summary}`).join("\n");
const r = await groq.chat.completions.create({
model: "llama-3.3-70b-versatile",
messages: [
{ role: "system", content: "Use this context if relevant, else general knowledge:\n" + context },
{ role: "user", content: prompt },
],
});
return r.choices[0].message.content;
}// 03 — LLM + MemoryLayer memory + verify. Grounds, abstains, then proves.
import Groq from "groq-sdk";
const groq = new Groq({ apiKey: process.env.GROQ_API_KEY });
async function mcp(name, args) {
const res = await fetch(process.env.MEMORYLAYER_DEMO_URL + "/mcp", {
method: "POST",
headers: { "Content-Type": "application/json", "x-api-key": process.env.MEMORYLAYER_DEMO_KEY },
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call",
params: { name, arguments: args } }),
});
const j = await res.json();
return JSON.parse(j.result.content[0].text);
}
export async function memory(namespace, prompt) {
// recall WITH weave — pulls related context via tag/temporal/semantic edges.
const recall = await mcp("recall", { query: prompt, namespace, explore: true, limit: 8 });
const context = (recall.results ?? []).map((h, i) => `[${i + 1}] ${h.content ?? h.summary}`).join("\n");
const r = await groq.chat.completions.create({
model: "llama-3.3-70b-versatile",
messages: [
{ role: "system", content:
"Answer ONLY from this memory context. If it doesn't cover the question, say " +
"\"I don't have enough grounded information to answer that.\" Do not guess.\n" + context },
{ role: "user", content: prompt },
],
});
const answer = r.choices[0].message.content;
// Honest-mouth gate: WCM checks every claim in the answer against what it knows.
const verdict = await mcp("verify", { text: answer });
return { answer, claims: verdict.claims, hallucinations: verdict.hallucinations };
}Install MemoryLayer and run this on your own stack in 5 minutes.