Why Memory Matters

Most AI agents forget everything after each session. Persistent memory solves this by storing past decisions, outcomes, and lessons.

TradeMemory Protocol

Purpose-built for trading. Three-layer architecture:

  • Layer 1 (Store): Records trades with context - strategy, confidence, market regime
  • Layer 2 (Recall): Retrieves similar past trades weighted by outcome
  • Layer 3 (Evolve): Discovers patterns and generates new strategy hypotheses

Mem0

Open-source memory layer for AI agents. Not trading-specific but can be adapted.

  • Pros: General purpose, active development
  • Cons: Not trading-specific, requires customization

Custom Memory Systems

Build your own with:

  • SQLite: Simple, local, fast
  • PostgreSQL: Production-grade, relational
  • Pinecone: Vector database for semantic search
  • Redis: Fast caching for recent trades

Memory Design Patterns

Episodic Memory

Store complete trade episodes: entry, exit, P&L, market conditions.

Semantic Memory

Store learned rules: when RSI is above 70, expect reversal.

Procedural Memory

Store strategies: iron condor setup for range-bound markets.

SEBI Disclaimer

AI trading involves substantial risk of loss. This article is for educational purposes only.

A Reference Schema for TradeMemory

The TradeMemory protocol concept is that conversational and decision state should live outside the LLM context and be addressable like a database. A practical reference schema separates memory cleanly:

  • Episodic records: timestamped events with a trader's action and the market outcome, like 2026-07-14: sold 8 lots Nifty CEF short-dated, exited at +12k, reason: theta capture.
  • Semantic rules: durable beliefs with expiry, like post-rally IV rank below 20 favours strangles during expiry week.
  • State variables: currently open positions, assigned risk budgets, broker-side orders pending.
  • Procedures: the exact steps of a strategy, stored once and retrieved by name instead of re-typed each session.

The design rule that matters is provenance on every record: each memory entry stores which strategy, which model verison, and which market session created it, so any later contradiction is debuggable.

Embedding Choice for Market Text

Retrieval quality is decided by the embedding model, not by the memory framework. For Indian market prose, choose embeddings and then test retrieval on your own vocabulary:

  1. Benchmark the embedder on terms like CE short, IV crush, option chain, MIS position to confirm near-synonyms map near each other.
  2. Prefer smaller, cheap-to-run embedders for a single-machine setup; MTEB score differences rarely matter when your corpus is charts and chains.
  3. Chunk by logical unit (a trade, a review, a note) rather than fixed token counts, so retrieval returns whole coherent memories.

Recency Weighting and Eviction

Unbounded memory degrades a trading agent because stale market states get retrieved beside fresh ones. Two mechanisms keep that under control:

  • Recency decay: multiply retrieval score by an exponential decay on record age, so a pre-crash rule does not dominate a post-crash regime.
  • Eviction policy: summarise episodic records older than a threshold into a lower-detail aggregate, an approach called memory consolidation, rather than deleting them outright.

In practice, a weekly consolidation job that rolls raw trade records into monthly summaries keeps retrieval sets small while preserving the audit trail.

Versioned Memory and Rollback

Memory that cannot be rolled back is dangerous. A wrong semantic rule injected by a bad model update will be retrieved forever:

  1. Snapshot memory at the start of every training or ingestion run.
  2. Tag each rule with the model or script version that wrote it.
  3. Compare a model's decisions with memory enabled versus disabled to measure how much the memory is actually shaping outcomes.

Shaping the Morning Brief

The highest-value memory use is a daily briefing. An agent that combines the ledger of yesterday's mental notes, the current option-chain snapshot and the embedded semantic rules can produce a structured morning brief in minutes:

  • Flag conflicts: a rule that says "avoid premium selling before budget" while open positions contradict it should be surfaced, not silently merged.
  • Propose two candidate trades consistent with memory, with refusal reasons for anything the memory contradicts.

A trading memory that only recalls the past faithfully, but never argues with the present, is already half-broken.

Memory Hygiene for Trading Bots

Separate short-term reasoning memory from long-term preference storage, and prune stale memory entries weekly to stop drift. Version every memory write with the model and prompt that produced it so regressions are auditable. A memory layer only compounds an edge that already exists; it does not create one.