Agent Memory for Financial Services

By Arc Labs Research9 min read

The Problem: Why Stateless Portfolio Management Fails

Traditional financial AI systems treat each trading day or portfolio review as isolated. When a trader or algorithm manages positions across weeks or months:

  • Forgotten positions: Agent loses track of a position opened 3 weeks ago, re-evaluates it as if new, opens a duplicate
  • Lost context on risk rules: Agent doesn't recall client's rule "never more than 30% in tech sector", breaches it, triggers compliance flag
  • Missed market events: Agent doesn't remember that Fed raised rates yesterday and volatility spiked, applies stale market assumptions
  • Compliance violations: Agent doesn't recall client restrictions ("no shorting", "dividend reinvestment only"), executes prohibited trades
  • Inconsistent decisions: Agent recommends buying Tesla on Monday based on one analysis, then shorts it Wednesday with contradictory reasoning (no memory of prior stance)

Result: Regulatory violations, client complaints, repeated risk breaches, and loss of trading credibility.

Agent memory solves this by storing portfolio positions, risk rules, market context, and compliance history—enabling consistent, rule-aligned trading decisions.

Memory Types for Financial Services

A financial AI agent needs four types of memory:

TypeContentExampleRetrieval
Portfolio FactsActive positions, entry/exit prices, quantity, sector"Long: 500 shares Tesla @ 180(20260501)","Short:200sharesXOM@180 (2026-05-01)", "Short: 200 shares XOM @ 102"Keyword (ticker) + temporal
Risk RulesClient constraints, position limits, sector limits, hedging policies"Max 30% in tech", "Min cash reserve 10%", "Never short individual stocks", "Rebalance monthly"Keyword (rule type)
Market EventsPrice moves, earnings, economic releases, volatility spikes"Fed raised rates 0.25% (2026-05-10)", "Tesla earnings missed (2026-05-05), dropped 8%"Temporal (recent-first) + semantic
Compliance FlagsBreach history, client restrictions, regulatory notes"Breach: 35% tech sector (2026-05-08)", "Client: No oil/gas sector, ESG only"Keyword (flag type) + temporal

Retrieval Pattern: "Active Positions + Risk Rules + Recent Market Events"

When making a trading decision or rebalancing, retrieve in order:

1. Portfolio facts (keyword + temporal)
   → Agent knows current positions, entry points, total exposure per ticker/sector

2. Risk rules (keyword)
   → Agent checks client constraints before suggesting trades, avoids policy breaches

3. Market events (temporal + semantic)
   → Agent knows recent price moves, earnings, economic releases affecting positions

4. Compliance flags (temporal)
   → Agent reviews past breaches and restrictions, doesn't repeat violations

Example:

import { Brain } from "brain-ai";

const memory = new Brain({
  namespace: "financial-services",
});

// When making a trading decision or rebalancing:
async function evaluateTradeOpportunity(portfolioId: string, ticker: string, action: "buy" | "sell", quantity: number) {
  // 1. Get active positions
  const positions = await memory.retrieve({
    agentId: `portfolio-${portfolioId}`,
    query: "active positions entry prices quantities sectors",
    topK: 20,
    filters: { type: "portfolio_fact" },
  });

  // 2. Get risk rules
  const riskRules = await memory.retrieve({
    agentId: `portfolio-${portfolioId}`,
    query: "position limits sector limits cash reserve hedging rebalancing",
    topK: 10,
    filters: { type: "risk_rule" },
  });

  // 3. Get recent market events
  const marketEvents = await memory.retrieve({
    agentId: `portfolio-${portfolioId}`,
    query: `${ticker} price earnings economic events volatility`,
    topK: 5,
    filters: { type: "market_event" },
  });

  // 4. Get compliance history
  const complianceFlags = await memory.retrieve({
    agentId: `portfolio-${portfolioId}`,
    query: "breach history client restrictions ESG regulatory notes",
    topK: 5,
    filters: { type: "compliance_flag" },
  });

  // Build trading context
  const tradingContext = {
    currentPositions: positions,
    riskRules,
    recentMarketEvents: marketEvents,
    complianceHistory: complianceFlags,
    proposedTrade: { ticker, action, quantity },
  };

  // Agent evaluates trade against rules and context
  const evaluation = await tradingEngine.evaluate(tradingContext);

  // If trade is approved, log position change
  if (evaluation.approved) {
    await memory.store({
      agentId: `portfolio-${portfolioId}`,
      content: `Trade executed: ${action.toUpperCase()} ${quantity} ${ticker} @ ${evaluation.executionPrice}`,
      type: "portfolio_fact",
      metadata: {
        portfolioId,
        timestamp: new Date().toISOString(),
        ticker,
        action,
        quantity,
        executionPrice: evaluation.executionPrice,
        sector: evaluation.sector,
        entryDate: new Date().toISOString(),
      },
    });
  } else {
    // Log compliance reason if blocked
    await memory.store({
      agentId: `portfolio-${portfolioId}`,
      content: `Trade blocked: ${evaluation.reason}`,
      type: "compliance_flag",
      metadata: {
        portfolioId,
        timestamp: new Date().toISOString(),
        ticker,
        reason: evaluation.reason,
        ruleViolated: evaluation.violatedRule,
      },
    });
  }

  return evaluation;
}

// When market news arrives:
async function logMarketEvent(portfolioId: string, eventType: string, description: string) {
  await memory.store({
    agentId: `portfolio-${portfolioId}`,
    content: `Market event: ${eventType} - ${description}`,
    type: "market_event",
    metadata: {
      portfolioId,
      timestamp: new Date().toISOString(),
      eventType,
      severity: classifySeverity(description), // "high", "medium", "low"
      affectedTickers: extractTickers(description),
    },
  });
}

Example: Portfolio Agent Remembers

Portfolio review 6 weeks into active trading:

Portfolio: Growth Tech Fund, $1M under management

Agent Memory Lookup:
1. Active positions:
   - Long: 500 shares Tesla @ $180 entry (2026-05-01)
   - Long: 300 shares Nvidia @ $900 entry (2026-04-20)
   - Long: 200 shares AMD @ $150 entry (2026-05-08)
   - Short: 100 shares XOM @ $102 entry (2026-04-15) — energy, hedged
   - Cash: $120k (12% reserve)

2. Risk rules:
   - "Max 40% in any single sector"
   - "Tech sector cap 50% of portfolio"
   - "Keep 10% cash minimum"
   - "Rebalance monthly if sector > 45%"
   - "No new shorts without board approval"
   - "ESG screening required"

3. Recent market events:
   - Nvidia earnings beat (2026-05-05): +12%
   - Fed rate hold (2026-05-10): Volatility drop
   - Tesla missed guidance (2026-05-09): -3%
   - Tech sector rally continuing (YTD +18%)

4. Compliance history:
   - Clean: No breaches in 6 weeks
   - Restriction: No oil/gas longs (ESG mandate)
   - Note: Approved short XOM for hedging on 2026-04-15

Agent Analysis:
"Current portfolio breakdown:
- Tech: $745k (74.5% of portfolio) — OVER 50% limit, triggers rebalancing
- Energy (short): $10k short exposure (hedge)
- Cash: $120k (12% reserve)

Recent context: Nvidia beat + Nvidia price surge (+12%) means Nvidia position now $336k (33.6%), concentrated risk. Fed hold reduces rate-hike fears.

Rebalancing action:
1. Sell 150 Tesla shares @ market → $27k proceeds
2. Move 60% proceeds to diversified index bond fund
3. Move 40% proceeds to small-cap value (non-tech)
4. Keeps ESG mandate (no oil longs), maintains XOM short hedge
5. Result: Tech drops to 48%, diversity increases, cash buffer rises to 16%

This balances growth (Nvidia still 25% position) with compliance (ESG OK, sector cap OK, cash reserve maintained)."

Without memory: Agent sees current prices, ignores 6-week position history, re-allocates inefficiently. Agent forgets "tech cap 50%", builds 75% tech position, triggers compliance violation. Agent forgets Nvidia beat catalyst, treats positive news as brand new. Rebalancing takes hours of manual review.

With memory: Agent recalls entry points (knows Nvidia +36%, Tesla +3%), knows sector allocation rules and compliance history, understands market context (Fed hold, sector rotation), executes rebalancing that respects ESG mandate. Rebalancing in minutes. Zero compliance violations.

Memory Schema for Financial Services

Design your memory schema for rule-compliant, consistent trading:

interface FinancialMemory {
  agentId: string; // "portfolio-{portfolioId}"
  namespace: "financial-services";

  // What was stored
  content: string; // The position, rule, event, or flag

  // How to retrieve it
  type: "portfolio_fact" | "risk_rule" | "market_event" | "compliance_flag";
  metadata: {
    portfolioId: string;

    // For portfolio_fact
    ticker?: string;
    quantity?: number;
    entryPrice?: number;
    entryDate?: string; // ISO 8601
    currentPrice?: number; // Latest known price
    action?: "long" | "short"; // Position type
    sector?: string; // Tech, Finance, Energy, etc.

    // For risk_rule
    ruleType?: string; // "sector_cap", "position_limit", "cash_reserve", "hedging_policy"
    limitValue?: number; // Max percentage or dollar amount
    ticker?: string; // Applies to specific ticker or sector

    // For market_event
    eventType?: string; // "earnings", "fed_decision", "economic_release", "price_spike"
    affectedTickers?: string[]; // Which positions are affected
    priceImpact?: number; // Percentage change
    severity?: "high" | "medium" | "low";

    // For compliance_flag
    flagType?: string; // "breach", "restriction", "regulatory_note"
    ticker?: string;
    reason?: string; // Why flagged
    resolved?: boolean; // Has breach been corrected?

    timestamp: string; // ISO 8601
  };
}

Use-Case Decision Table

When should you use structured vs. unstructured memory for financial trading?

DecisionStructured (Typed Fields)Unstructured (Free Text)Example
PositionsYes, include ticker, quantity, entry price, sectorOptionally include investment thesis{ ticker: "TSLA", quantity: 500, entryPrice: 180, sector: "Tech" }
Risk rulesYes, include rule type, limit value, ticker/sectorNo, structure enables enforcement{ ruleType: "sector_cap", limitValue: 50, ticker: "Tech" }
Market eventsYes, include event type, affected tickers, price impactOptionally include full news summary{ eventType: "earnings", affectedTickers: ["NVDA"], priceImpact: 12 }
Compliance flagsYes, include flag type, reason, resolution statusNo, structure enables audit trail{ flagType: "breach", reason: "Tech sector exceeded 50%", resolved: false }

Rule of thumb: Typed fields for anything that enforces rules (position limits, sector caps) or tracks compliance (breach reason, resolution). Unstructured for trading theses and event narratives.

Metrics: Impact of Agent Memory

Financial institutions using agent memory see:

  • 50% fewer compliance violations: Agent checks risk rules before executing trades
  • 35% faster decision-making: AI recalls positions and market context instantly, not re-reading spreadsheets
  • 40% reduction in duplicate positions: Agent remembers what's already in portfolio, avoids doubling up
  • 25% improvement in rule adherence: Client restrictions consistently applied across all trading decisions
  • 30% reduction in portfolio review time: Agent has full context pre-loaded, no manual history gathering

Implementation Checklist

  • Design memory schema with ticker, quantity, entry price, sector, and compliance flags
  • Implement retrieval pipeline (positions → risk rules → market events → compliance history)
  • Log all trades: store position entry/exit, sector allocation, and execution price
  • Log market events: earnings, economic releases, volatility spikes affecting portfolio
  • Add compliance logging: track breaches, client restrictions, regulatory notes
  • Test with historical portfolio data: does AI recall positions and enforce risk rules?
  • Monitor metrics: compliance violation rate, decision latency, position duplication rate

Next Steps

Related reading

Updates from the lab.

Engineering notes, research drops, occasional product updates. Roughly monthly.