> ## Documentation Index
> Fetch the complete documentation index at: https://docs.snowleopard.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Financial Coach (LangGraph)

> Build a CLI financial coaching agent that analyzes spending data and provides personalized recommendations.

A CLI agent that analyzes personal spending data and provides AI-powered financial coaching. Built with [LangGraph](https://langchain-ai.github.io/langgraph/) for multi-step workflows.

## What it does

This agent acts as a personal financial coach through a command-line interface. Users can:

* Ask questions about their spending in natural language
* Get breakdowns by category, merchant, or time period
* Receive personalized recommendations and savings opportunities
* Have multi-turn conversations with conversation memory

Example interaction:

```
You: Show me my spending by category

╔══════════════════════════════════════════════════════════╗
║           💡 FINANCIAL COACHING INSIGHTS                 ║
╚══════════════════════════════════════════════════════════╝

📊 YOUR SPENDING ANALYSIS
──────────────────────────────────────────────────────────────
  💰 Real Monthly Spending: $2,543.22
  🔴 Highest Expense: Rent @ $1,200.00 (47.2% of total)
  💡 Found 3 optimization opportunities totaling $425/month

💡 RECOMMENDATIONS FOR YOU
──────────────────────────────────────────────────────────────
  1. Your Rent is your largest expense (47.2%). This should be priority #1.
  2. Meal prep 2x/week could save $127/month (Highest impact)
```

## Architecture

The agent uses a 4-node LangGraph workflow:

1. **Enrich query** - Adds context about time period, categories, and merchants
2. **Query Snow Leopard** - Converts natural language to SQL and retrieves data
3. **Analyze and coach** - Generates insights, recommendations, and follow-up questions
4. **Format response** - Creates formatted CLI output with Rich

### Key components

* **LangGraph** orchestrates the multi-step workflow
* **Snow Leopard** handles natural language to SQL conversion
* **Coaching analyzer** generates personalized financial insights
* **Memory manager** maintains conversation context across turns
* **Rich CLI** provides formatted terminal output

## Run the example

### Prerequisites

* Python 3.10+
* OpenAI API key
* A [Snow Leopard Cloud](https://cloud.snowleopard.ai) instance and [API key](https://docs.snowleopard.ai/cloud/getting-started.md#api-keys)
* A PostgreSQL database that Snow Leopard Cloud can reach, such as a free [Neon](https://neon.com) or [Supabase](https://supabase.com) database. See the [PostgreSQL setup guide](https://github.com/SnowLeopard-AI/snowy-examples/blob/main/docs/postgres-setup.md) for details.

> [!NOTE]
>
> The example includes `data/finance_coach.sql`, a sample dataset built from the [Kaggle Personal Finance dataset](https://www.kaggle.com/datasets/entrepreneurlife/personal-finance/data) that covers January 2018 through September 2019. You can also use your own transaction data.

### Setup

Clone the [repository](https://github.com/SnowLeopard-AI/snowy-examples/tree/main/agent_examples/financial_coach_langchain):

```bash theme={null}
git clone https://github.com/SnowLeopard-AI/snowy-examples.git
cd snowy-examples/agent_examples/financial_coach_langchain
```

Install dependencies:

```bash theme={null}
pip install -r requirements.txt
```

Load the sample dataset into your PostgreSQL database:

```bash theme={null}
psql "postgresql://USER:PASSWORD@HOST/DBNAME?sslmode=require" -f data/finance_coach.sql
```

In [Snow Leopard Cloud](https://cloud.snowleopard.ai), [add the database as a data source](https://docs.snowleopard.ai/cloud/getting-started.md#adding-a-data-source) to your instance. Then create an API key on the **Keys** tab and copy the instance ID from the **Connection Info** tab.

Create a `.env` file:

```bash theme={null}
OPENAI_API_KEY=your-openai-key
SNOWLEOPARD_API_KEY=your-snowleopard-key
SNOWLEOPARD_INSTANCE_ID=your-instance-id
```

Run the agent:

```bash theme={null}
python main.py
```

### Example queries

The sample data covers January 2018 through September 2019, so ask about those months rather than "this month".

* "Show me my spending by category"
* "Which merchants did I spend the most at?"
* "Compare March 2019 vs February 2019"
* "How much did I spend on groceries?"

## Next steps

* View the [full source code on GitHub](https://github.com/SnowLeopard-AI/snowy-examples/tree/main/agent_examples/financial_coach_langchain)
* Learn more about [LangGraph](https://langchain-ai.github.io/langgraph/)
* Explore the [LangGraph quickstart](https://docs.snowleopard.ai/quickstarts/langgraph.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.