> ## 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
* [Snow Leopard API key](https://auth.snowleopard.ai/account/api_keys)
* A datafile uploaded to [Snow Leopard Playground](https://try.snowleopard.ai)

<Note>
  The example includes a script to generate sample financial data, or you can use your own SQLite database with transaction data.
</Note>

### 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
```

Generate sample data (optional):

```bash theme={null}
python data/create_sample_data.py
```

Create a `.env` file:

```bash theme={null}
OPENAI_API_KEY=your-openai-key
SNOWLEOPARD_API_KEY=your-snowleopard-key
SNOWLEOPARD_DATAFILE_ID=your-datafile-id
```

Run the agent:

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

### Example queries

* "Show me my spending by category"
* "Which merchants did I spend the most at?"
* "Compare this month vs last month"
* "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](/quickstarts/langgraph)
