Ana Brainiall

Build your first AI agent with memory

intermediario · 12 min · Por Ana Brainiall

Agent vs chatbot: what's the difference

A chatbot responds to messages independently. Each conversation is isolated. If you shared your name yesterday, it has no idea today.

An agent has 3 extra characteristics:

1. Persistent memory: remembers you across sessions
2. Tools: can call external APIs (search Google, send emails, run code)
3. Planning: can break down complex tasks into steps

In this course we'll focus on (1): persistent memory. Tools and planning are covered in separate courses.

ilustração de 2 personagens — à esquerda um chatbot sem memória (balão vazio ao

Basic memory architecture

What the agent needs to store about you:

Storage pattern:

`
user_memory = {
"facts": [
{"text": "Pedro works with Python", "pinned": False},
{"text": "prefers short answers", "pinned": True}
],
"summary_last_10_sessions": "User learned about TLS, APIs and authentication...",
"preferences": {"response_language": "pt-BR", "tone": "technical"}
}
`

How Brainiall does it

Our backend already implements persistent memory. You can:

1. Click the 🧠 icon in the chat sidebar
2. View the list of facts the AI has learned about you
3. Pin important facts (never forgotten)
4. Edit or delete them
5. Disable memory via toggle

Under the hood we use:
- PostgreSQL JSONB to store facts per user
- Eviction policy: maximum 50 unpinned facts, oldest ones are removed first
- Extraction: every 10 messages, an LLM reads the conversation and suggests new facts for your approval
- Retrieval: before responding, relevant facts are fetched and injected into the prompt

Building your agent via API

Minimal Python example:

`python
import httpx

BASE = "https://api.brainiall.com"
KEY = "brnl-xxxxx"

def chat(message, user_memory):
# Inject memory as system prompt context
memory_text = "\n".join(f"- {f}" for f in user_memory["facts"])
system = f"You are a personal assistant. About the user:\n{memory_text}"

r = httpx.post(
f"{BASE}/v1/chat/completions",
json={
"model": "claude-sonnet-4-6",
"messages": [
{"role": "system", "content": system},
{"role": "user", "content": message}
]
},
headers={"Authorization": f"Bearer {KEY}"}
)
return r.json()["choices"][0]["message"]["content"]

# Usage
memory = {"facts": ["Pedro works with Python", "likes coffee without sugar"]}
print(chat("What did I drink this morning?", memory))
# → "You probably had a coffee without sugar, right?"
`

This is a basic agent. Adding automatic extraction (LLM reads and pulls out new facts) and retrieval (only injecting relevant facts) would bring the code to ~100 lines.

Common pitfalls

lista visual de 5 armadilhas com ícones e exemplos curtos — caderno inflado, "??

Use cases

Try it right now

In the Brainiall chat, open a conversation, share something about yourself, close it, then open a new conversation the next day — the agent will remember. Enable or disable memory via the 🧠 icon in the sidebar. The Pro plan at $29 includes full memory; the free plan is limited to 10 facts.

Enjoyed this course?

Unlock 17 Pro courses + 40+ AIs in chat + video, music and full Studio generation.

Go Pro · $5.99/mo

Cancel anytime · No commitment