How to Integrate LlamaIndex for fintech with Supabase for multi-agent systems

By Cyprian AaronsUpdated 2026-04-22
llamaindex-for-fintechsupabasemulti-agent-systems

Combining LlamaIndex for fintech with Supabase gives you a clean pattern for building agent systems that can retrieve financial context, persist shared state, and coordinate multiple agents without wiring up a separate backend. In practice, this is useful when one agent needs to search policy docs or transaction notes while another agent stores approvals, audit trails, and task handoffs in a Postgres-backed system.

Prerequisites

  • Python 3.10+
  • A Supabase project with:
    • SUPABASE_URL
    • SUPABASE_SERVICE_ROLE_KEY or anon key for local testing
  • A LlamaIndex setup for fintech:
    • LlamaIndex installed
    • Access to your chosen LLM provider
    • Financial documents or structured data to index
  • Basic Postgres familiarity
  • Optional but recommended:
    • python-dotenv for local env management
    • A vector store strategy if you want embeddings persisted in Supabase

Install the packages:

pip install llama-index supabase python-dotenv sqlalchemy psycopg2-binary

Integration Steps

  1. Set up environment variables and initialize Supabase.

Use Supabase as the shared state layer for your agents. For multi-agent systems, this is where you store conversation state, tool outputs, approvals, and routing metadata.

import os
from dotenv import load_dotenv
from supabase import create_client, Client

load_dotenv()

SUPABASE_URL = os.environ["SUPABASE_URL"]
SUPABASE_KEY = os.environ["SUPABASE_SERVICE_ROLE_KEY"]

supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)

Create a table for agent messages and task state:

create table if not exists agent_messages (
  id bigserial primary key,
  session_id text not null,
  agent_name text not null,
  role text not null,
  content text not null,
  created_at timestamptz default now()
);
  1. Build a LlamaIndex financial knowledge layer.

For fintech use cases, you usually want one index over policy docs, product docs, compliance notes, or internal runbooks. This example uses SimpleDirectoryReader and VectorStoreIndex.

from llama_index.core import SimpleDirectoryReader, VectorStoreIndex

documents = SimpleDirectoryReader("./fintech_docs").load_data()
index = VectorStoreIndex.from_documents(documents)

query_engine = index.as_query_engine(similarity_top_k=3)
response = query_engine.query("What are the escalation rules for suspicious transactions?")
print(response)

If you need structured finance data instead of documents, use LlamaIndex readers or SQL-backed retrieval. The point is the same: let the agent query domain knowledge instead of hardcoding business logic.

  1. Persist agent outputs in Supabase.

Once an agent gets a result from LlamaIndex, store it in Supabase so other agents can consume it later. This is the coordination layer for your multi-agent workflow.

session_id = "case_10291"
agent_name = "risk_agent"

result_text = str(response)

supabase.table("agent_messages").insert({
    "session_id": session_id,
    "agent_name": agent_name,
    "role": "assistant",
    "content": result_text,
}).execute()

Read back the latest messages when another agent needs context:

messages = (
    supabase.table("agent_messages")
    .select("*")
    .eq("session_id", session_id)
    .order("created_at", desc=True)
    .limit(10)
    .execute()
)

print(messages.data)
  1. Wire the two together in an agent workflow.

This is where the integration becomes useful. One agent retrieves financial context from LlamaIndex; another agent stores or reads state from Supabase; a coordinator decides which one runs next.

def financial_research_agent(question: str) -> str:
    answer = query_engine.query(question)
    return str(answer)

def persist_agent_result(session_id: str, agent_name: str, role: str, content: str):
    supabase.table("agent_messages").insert({
        "session_id": session_id,
        "agent_name": agent_name,
        "role": role,
        "content": content,
    }).execute()

question = "What documents are required before approving a high-value wire transfer?"
answer_text = financial_research_agent(question)

persist_agent_result(
    session_id="case_10291",
    agent_name="research_agent",
    role="assistant",
    content=answer_text,
)

A practical pattern here is:

  • Retrieval agent uses LlamaIndex
  • Coordination/state agent uses Supabase
  • Supervisor agent reads Supabase history and routes work
  1. Add retrieval from Supabase into a second agent.

For multi-agent systems, agents often need shared memory. You can pull prior outputs from Supabase and inject them into a prompt or downstream tool call.

def get_session_context(session_id: str) -> list[str]:
    result = (
        supabase.table("agent_messages")
        .select("agent_name, role, content")
        .eq("session_id", session_id)
        .order("created_at", desc=False)
        .execute()
    )
    return [f"{row['agent_name']}:{row['role']} => {row['content']}" for row in result.data]

context_lines = get_session_context("case_10291")
for line in context_lines:
    print(line)

That gives your supervisor enough context to decide whether to ask another LlamaIndex query or move to approval handling.

Testing the Integration

Run one end-to-end check: query fintech knowledge through LlamaIndex, write it to Supabase, then read it back.

test_question = "What is the approval threshold for manual review?"
test_answer = financial_research_agent(test_question)

persist_agent_result(
    session_id="test_session_001",
    agent_name="policy_agent",
    role="assistant",
    content=test_answer,
)

check = (
    supabase.table("agent_messages")
    .select("session_id,agent_name,role,content")
    .eq("session_id", "test_session_001")
    .execute()
)

print(check.data[-1]["content"])

Expected output:

The approval threshold for manual review is defined in the compliance policy...

If you get a row back with the same answer stored in Supabase, the integration is working. If the answer is empty or missing, check your document ingestion path and your Supabase table permissions.

Real-World Use Cases

  • Fraud investigation copilots

    • One agent searches internal fraud playbooks with LlamaIndex.
    • Another stores case notes and analyst decisions in Supabase.
    • A supervisor agent tracks unresolved cases across sessions.
  • Loan underwriting workflows

    • Retrieval agents pull underwriting policy and product rules.
    • State agents persist applicant status changes in Supabase.
    • Review agents coordinate document requests and approvals.
  • Compliance Q&A systems

    • Agents answer questions from policy manuals using LlamaIndex.
    • Supabase keeps audit logs of every question and response.
    • Multiple agents handle legal review, escalation, and final sign-off.

If you’re building multi-agent systems in fintech, this combination gives you two things that matter: grounded retrieval and durable shared state. That’s enough to move from demos to workflows that can survive audits and real operational load.


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