← IteraTools / Use Cases
Tutorial ⏱ 5 minutes

Build an AI Agent with
Persistent Memory

Give your agent the ability to remember. Store knowledge, search by meaning, and maintain context across sessions — no vector database to set up, no infrastructure to manage.

🤖 Your Agent
POST /memory/upsert
store facts
🗄️ Vector Store
OpenAI embeddings
POST /memory/search
retrieve by meaning
POST /ai/chat
answer with context

Prerequisites

Just an IteraTools API key. No database, no embedding model to configure, no vector store to deploy.

export ITERA_KEY="it-XXXX-XXXX-XXXX" # get yours at iteratools.com/keys
1

Store facts into memory

Use POST /memory/upsert to save any text as a searchable memory. Each item is embedded and stored under your namespace.

curl -X POST https://api.iteratools.com/memory/upsert \ -H "Authorization: Bearer $ITERA_KEY" \ -H "Content-Type: application/json" \ -d '{ "namespace": "my-agent", "key": "user-pref-1", "text": "User prefers concise answers under 3 sentences. Dislikes bullet points.", "metadata": { "category": "preferences", "user_id": "u_123" } }'
{ "status": "ok", "key": "user-pref-1", "namespace": "my-agent", "embedded": true }
$0.003 / upsert includes OpenAI embedding generation
2

Add more facts — batch or over time

Your agent can keep adding to its memory as it learns. Different keys, same namespace. Memories persist across sessions.

curl -X POST https://api.iteratools.com/memory/upsert \ -H "Authorization: Bearer $ITERA_KEY" \ -H "Content-Type: application/json" \ -d '{ "namespace": "my-agent", "key": "user-context-2", "text": "User is building a SaaS product for restaurant owners in Brazil.", "metadata": { "category": "context" } }' # Add as many memories as you need — each is instantly searchable
3

Search memory by meaning (semantic search)

When the user sends a message, search memory for relevant context. Returns top-K results ranked by semantic similarity — not just keyword match.

curl -X POST https://api.iteratools.com/memory/search \ -H "Authorization: Bearer $ITERA_KEY" \ -H "Content-Type: application/json" \ -d '{ "namespace": "my-agent", "query": "How should I format my response?", "limit": 3 }'
{ "results": [ { "key": "user-pref-1", "text": "User prefers concise answers under 3 sentences. Dislikes bullet points.", "score": 0.94, "metadata": { "category": "preferences", "user_id": "u_123" } }, { "key": "user-context-2", "text": "User is building a SaaS product for restaurant owners in Brazil.", "score": 0.71, "metadata": { "category": "context" } } ] }
$0.002 / search returns top results sorted by cosine similarity
4

Inject context and call the LLM

Pass the retrieved memories as system context to POST /ai/chat. Your agent now responds with full awareness of past interactions.

USER_MSG="How should I explain our pricing?" # 1. Search for relevant memories CONTEXT=$(curl -sX POST https://api.iteratools.com/memory/search \ -H "Authorization: Bearer $ITERA_KEY" \ -H "Content-Type: application/json" \ -d "{\"namespace\":\"my-agent\",\"query\":\"$USER_MSG\",\"limit\":3}" \ | python3 -c "import sys,json; r=json.load(sys.stdin)['results']; print('\n'.join(x['text'] for x in r))") # 2. Call AI with memory context injected curl -X POST https://api.iteratools.com/ai/chat \ -H "Authorization: Bearer $ITERA_KEY" \ -H "Content-Type: application/json" \ -d "{ \"model\": \"gpt-4o-mini\", \"messages\": [ { \"role\": \"system\", \"content\": \"You are a helpful assistant.\n\nContext from memory:\n$CONTEXT\" }, { \"role\": \"user\", \"content\": \"$USER_MSG\" } ] }"
{ "reply": "Keep the pricing explanation to 2-3 sentences max, focusing on value rather than features.", "model": "gpt-4o-mini", "tokens_used": 112 }
$0.005 / chat call
🐍

Complete Python agent example

A minimal but complete memory-aware agent loop in ~30 lines.

import requests API_KEY = "it-XXXX-XXXX-XXXX" BASE = "https://api.iteratools.com" HEADERS = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"} NS = "my-agent" def remember(key, text, metadata=None): """Store a fact in agent memory.""" requests.post(f"{BASE}/memory/upsert", headers=HEADERS, json={ "namespace": NS, "key": key, "text": text, "metadata": metadata or {} }) def recall(query, limit=3): """Retrieve semantically similar memories.""" r = requests.post(f"{BASE}/memory/search", headers=HEADERS, json={"namespace": NS, "query": query, "limit": limit}) return [m["text"] for m in r.json().get("results", [])] def chat(user_msg): """Answer user question with memory context.""" memories = recall(user_msg) context = "\n".join(f"- {m}" for m in memories) system = f"You are a helpful assistant.\n\nWhat you know about this user:\n{context}" r = requests.post(f"{BASE}/ai/chat", headers=HEADERS, json={ "model": "gpt-4o-mini", "messages": [ {"role": "system", "content": system}, {"role": "user", "content": user_msg} ] }) return r.json()["reply"] # --- Seed some memories --- remember("pref-format", "User wants concise answers, max 3 sentences, no bullet points.") remember("context-biz", "User builds SaaS for restaurant owners in Brazil.") remember("context-lang", "User writes code in Python and JavaScript.") # --- Chat loop --- while True: msg = input("You: ") if msg.lower() in ("quit", "exit"): break print("Agent:", chat(msg))

💰 What does this cost?

A typical agent interaction: store 1 memory + 1 search + 1 chat call.

$0.003
POST /memory/upsert
$0.002
POST /memory/search
$0.005
POST /ai/chat
$0.010
per full interaction

$1 of credits = 100 full agent interactions with memory. No monthly fees, no minimums.

🔀 Pro tip: use namespaces to separate contexts

Each API key can have unlimited namespaces — perfect for multi-tenant apps or separating agent memories by user or session.

# Each user gets their own isolated memory space remember("pref-1", "Likes formal tone", namespace="user-alice") remember("pref-1", "Prefers casual language", namespace="user-bob") # Searching is always scoped to a namespace — no cross-contamination recall("communication style", namespace="user-alice") # → ["Likes formal tone"]

🗑️ Clear memory when needed

# Delete a specific key curl -X DELETE https://api.iteratools.com/memory/clear \ -H "Authorization: Bearer $ITERA_KEY" \ -H "Content-Type: application/json" \ -d '{"namespace": "my-agent", "key": "user-pref-1"}' # Or wipe the entire namespace curl -X DELETE https://api.iteratools.com/memory/clear \ -H "Authorization: Bearer $ITERA_KEY" \ -H "Content-Type: application/json" \ -d '{"namespace": "my-agent"}'
$0.001 / clear

🚀 What you can build with this

💬
Customer support bot

Remembers past tickets, user preferences, and product knowledge. Gets smarter over time.

📚
Personal research assistant

Ingest documents, articles, and notes. Ask questions and get answers grounded in your own knowledge base.

🧑‍💻
Coding agent with context

Remember architecture decisions, coding patterns, and past bugs. Context carries across sessions.

🛒
E-commerce agent

Track user preferences, purchase history, and browsing patterns to personalize every interaction.

✅ What you just built

  • An agent that stores facts as vector embeddings ($0.003/upsert)
  • Semantic search that finds relevant context by meaning, not keywords ($0.002/search)
  • An LLM call grounded in retrieved memory ($0.005/call)
  • Isolated namespaces per user or session
  • Zero infrastructure — no database, no embedding model, no vector store
  • Full agent interaction for $0.01

Ready to give your agent memory?

Get an API key, add $1 in credits, and your agent can make 100 memory-aware interactions. No subscription, no infrastructure.

Get API Key → Memory API Docs

Also works with the MCP package for Claude, Cursor, and other MCP clients.