How to Integrate LlamaIndex for retail banking with Supabase for multi-agent systems

By Cyprian AaronsUpdated 2026-04-22
llamaindex-for-retail-bankingsupabasemulti-agent-systems

Retail banking agent systems need two things to work well: grounded retrieval and durable shared state. LlamaIndex gives you the retrieval layer for policy docs, product guides, account rules, and case notes; Supabase gives you Postgres-backed memory, auth, and event storage so multiple agents can coordinate without stepping on each other.

That combination is useful when one agent handles customer intent, another checks policy eligibility, and a third writes audit-safe outcomes back to a shared store. You get a system that can answer questions with bank-specific context and keep multi-agent workflows consistent across sessions.

Prerequisites

  • Python 3.10+
  • A Supabase project with:
    • SUPABASE_URL
    • SUPABASE_SERVICE_ROLE_KEY
  • A LlamaIndex setup with your banking knowledge sources ready:
    • PDFs, internal docs, FAQs, product sheets, or ticket exports
  • Installed packages:
    • llama-index
    • supabase
    • python-dotenv
  • Access to an LLM provider configured for LlamaIndex:
    • OpenAI, Azure OpenAI, Anthropic, or another supported backend
  • A Postgres table in Supabase for shared agent state

Example table:

create table if not exists agent_memory (
  id uuid primary key default gen_random_uuid(),
  session_id text not null,
  agent_name text not null,
  message ტექxt not null,
  created_at timestamptz default now()
);

Integration Steps

  1. Install dependencies and load configuration.
from dotenv import load_dotenv
import os

load_dotenv()

SUPABASE_URL = os.getenv("SUPABASE_URL")
SUPABASE_SERVICE_ROLE_KEY = os.getenv("SUPABASE_SERVICE_ROLE_KEY")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
  1. Connect to Supabase and create a shared store for multi-agent state.

Use the Supabase Python client to write each agent’s messages into a central table. In production, this becomes your coordination layer for handoffs, audit logs, and replay.

from supabase import create_client

supabase = create_client(SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY)

def save_agent_message(session_id: str, agent_name: str, message: str):
    response = supabase.table("agent_memory").insert({
        "session_id": session_id,
        "agent_name": agent_name,
        "message": message,
    }).execute()
    return response.data
  1. Index retail banking documents with LlamaIndex.

For banking use cases, keep your source data scoped by domain: deposits, cards, loans, disputes, KYC/AML policy. Use SimpleDirectoryReader plus VectorStoreIndex for a clean baseline.

from llama_index.core import SimpleDirectoryReader, VectorStoreIndex

docs = SimpleDirectoryReader("./banking_docs").load_data()
index = VectorStoreIndex.from_documents(docs)

query_engine = index.as_query_engine(similarity_top_k=3)
  1. Wire the retrieval layer into an agent workflow.

Each agent can query the same index but write different outputs to Supabase. That gives you a clean pattern: retrieve from LlamaIndex, persist coordination state in Supabase.

def banking_agent_answer(session_id: str, question: str):
    result = query_engine.query(question)
    answer_text = str(result)

    save_agent_message(
        session_id=session_id,
        agent_name="retail_banking_agent",
        message=f"Q: {question}\nA: {answer_text}",
    )

    return answer_text
  1. Add a second agent that reads from Supabase before acting.

This is where multi-agent behavior becomes useful. One agent can inspect prior decisions stored in Supabase and then decide whether to continue retrieval or escalate.

def get_recent_messages(session_id: str):
    response = (
        supabase.table("agent_memory")
        .select("*")
        .eq("session_id", session_id)
        .order("created_at", desc=False)
        .execute()
    )
    return response.data

def compliance_agent(session_id: str):
    history = get_recent_messages(session_id)

    prompt = "\n".join(
        f"[{row['agent_name']}] {row['message']}" for row in history[-5:]
    )

    result = query_engine.query(
        f"Review this interaction for retail banking policy risk:\n{prompt}"
    )

    save_agent_message(
        session_id=session_id,
        agent_name="compliance_agent",
        message=str(result),
    )

    return str(result)

Testing the Integration

Run a single end-to-end check: ask a retail banking question, persist the answer in Supabase, then have the compliance agent review it.

if __name__ == "__main__":
    session_id = "session_001"

    answer = banking_agent_answer(
        session_id,
        "What documents are required to open a checking account for a new customer?"
    )
    print("Banking Agent Answer:", answer)

    review = compliance_agent(session_id)
    print("Compliance Review:", review)

Expected output:

Banking Agent Answer: Customers typically need government-issued ID...
Compliance Review: The response aligns with onboarding policy...

If you want to verify persistence directly:

rows = get_recent_messages("session_001")
for row in rows:
    print(row["agent_name"], "=>", row["message"][:120])

You should see both agents’ messages returned from Supabase in order.

Real-World Use Cases

  • Customer support triage

    • One agent retrieves product and policy answers from LlamaIndex.
    • Another writes the case summary into Supabase for handoff to human support.
  • Loan prequalification workflows

    • A retrieval agent checks lending criteria and required documents.
    • A rules agent stores eligibility decisions and reasons in Supabase for auditability.
  • Dispute handling and escalation

    • An intake agent extracts dispute details from chat or email.
    • A compliance agent reviews policy references and records the final decision in shared storage.

The pattern is simple: use LlamaIndex as the knowledge brain and Supabase as the coordination backbone. For retail banking multi-agent systems, that separation keeps your retrieval accurate and your workflow state durable.


Keep learning

By Cyprian Aarons, AI Consultant at Topiax.

Want the complete 8-step roadmap?

Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.

Get the Starter Kit

Related Guides