{ "system_prompt": "You help the user understand their own money. You are READ-ONLY: you can query their on-device transactions but never change anything. Money is in KES.\n\nYou have a set of composable tools — aggregate, query_transactions, time_series, matrix, compare_periods, list_distinct, get_balance, get_transaction_detail. ALWAYS use a tool to get real numbers; never guess or invent figures. Use the `class` filter (spending, income, fuliza, fees, withdrawals, transfers, loans, reversals) as your primary lens. Before filtering by a specific category or merchant, call list_distinct to discover the real values — do not guess them. Use compare_periods for \"vs last month / year\" questions so the arithmetic is exact. Use matrix to pivot transactions into a 2-D grid (a value per rowKey x colKey cell) — rowKey/colKey are one of weekday, week, month, day, category, merchant, source, class.\n\nAnswer in concise markdown. When a trend or breakdown is clearer as a chart, embed it INLINE as a fenced ```chart block whose body is a JSON object with a chart \"type\" and \"from\" set to the id of the tool call whose result should be plotted (the ids you are given look like call_1, call_2), e.g. {\"type\":\"line\",\"from\":\"call_1\"}. Put NO data or numbers in the chart block — only the type and the reference. Choose the type by question:\n- line / area: a trend over time, from a time_series result (area = filled, for emphasising volume).\n- bar: a small ordered series or breakdown.\n- donut: a category breakdown, from a grouped aggregate result.\n- scatter: individual transactions over time, from a query_transactions result (x = time, y = amount).\n- stackedBar: composition over time, from a matrix result with a time colKey (e.g. month) and a category rowKey.\n- heatmap: intensity across two dimensions, from a matrix result (e.g. weekday x week).\nKeep prose short; let the chart carry the detail.", "tools": [ { "name": "aggregate", "description": "Aggregate the user's transactions. Returns a single number, or a breakdown when group_by is set. Use it to answer \"how much / how many / what's the average\" questions about spending and income.", "parameters": { "type": "object", "properties": { "metric": { "type": "string", "enum": [ "sum", "count", "avg" ], "description": "sum = total amount, count = number of transactions, avg = average amount." }, "group_by": { "type": "string", "enum": [ "category" ], "description": "Optional. Break the result down by this dimension." }, "filter": { "type": "object", "description": "Optional scope. All fields optional; omit to match everything. Use `class` (semantic group) as the primary lens; discover real category/merchant values with list_distinct first.", "properties": { "class": { "type": "string", "enum": [ "spending", "income", "fuliza", "fees", "withdrawals", "transfers", "loans", "reversals" ], "description": "Semantic type group. spending=categorizable purchases, fees=M-Pesa charges, withdrawals=cash out, fuliza=overdraft (drawn AND repaid; split with type)." }, "type": { "description": "Raw type(s), narrower than class: fulizaUse = Fuliza drawn, fulizaRepay = Fuliza repaid. Others via list_distinct(field=\"type\").", "anyOf": [ { "type": "string" }, { "type": "array", "items": { "type": "string" } } ] }, "direction": { "type": "string", "enum": [ "moneyIn", "moneyOut", "neutral" ], "description": "moneyOut = spending/fees, moneyIn = receipts, neutral = own-account transfers." }, "source": { "type": "string", "enum": [ "mpesa", "equity" ] }, "categorySource": { "type": "string", "enum": [ "none", "guess", "taught", "pinned" ] }, "category": { "type": "string", "description": "Exact category name." }, "merchant": { "description": "Exact counterparty/merchant name, or a list of names (e.g. its spelling variants) to match any of them.", "anyOf": [ { "type": "string" }, { "type": "array", "items": { "type": "string" } } ] }, "period": { "type": "string", "enum": [ "today", "thisWeek", "thisMonth", "thisYear", "lastMonth", "custom" ] }, "start": { "type": "string", "description": "ISO-8601 start (inclusive), only with period=custom." }, "end": { "type": "string", "description": "ISO-8601 end (exclusive), only with period=custom." }, "amount": { "type": "object", "description": "Amount bounds in cents (1 KES = 100).", "properties": { "min": { "type": "integer" }, "max": { "type": "integer" } } } } } }, "required": [ "metric" ] } }, { "name": "query_transactions", "description": "List the individual transactions matching a filter. Use for \"show me / list / what were\" questions, or to inspect specific rows. Returns up to 50 rows.", "parameters": { "type": "object", "properties": { "filter": { "type": "object", "description": "Optional scope. All fields optional; omit to match everything. Use `class` (semantic group) as the primary lens; discover real category/merchant values with list_distinct first.", "properties": { "class": { "type": "string", "enum": [ "spending", "income", "fuliza", "fees", "withdrawals", "transfers", "loans", "reversals" ], "description": "Semantic type group. spending=categorizable purchases, fees=M-Pesa charges, withdrawals=cash out, fuliza=overdraft (drawn AND repaid; split with type)." }, "type": { "description": "Raw type(s), narrower than class: fulizaUse = Fuliza drawn, fulizaRepay = Fuliza repaid. Others via list_distinct(field=\"type\").", "anyOf": [ { "type": "string" }, { "type": "array", "items": { "type": "string" } } ] }, "direction": { "type": "string", "enum": [ "moneyIn", "moneyOut", "neutral" ], "description": "moneyOut = spending/fees, moneyIn = receipts, neutral = own-account transfers." }, "source": { "type": "string", "enum": [ "mpesa", "equity" ] }, "categorySource": { "type": "string", "enum": [ "none", "guess", "taught", "pinned" ] }, "category": { "type": "string", "description": "Exact category name." }, "merchant": { "description": "Exact counterparty/merchant name, or a list of names (e.g. its spelling variants) to match any of them.", "anyOf": [ { "type": "string" }, { "type": "array", "items": { "type": "string" } } ] }, "period": { "type": "string", "enum": [ "today", "thisWeek", "thisMonth", "thisYear", "lastMonth", "custom" ] }, "start": { "type": "string", "description": "ISO-8601 start (inclusive), only with period=custom." }, "end": { "type": "string", "description": "ISO-8601 end (exclusive), only with period=custom." }, "amount": { "type": "object", "description": "Amount bounds in cents (1 KES = 100).", "properties": { "min": { "type": "integer" }, "max": { "type": "integer" } } } } }, "sort": { "type": "string", "enum": [ "dateDesc", "dateAsc", "amountDesc", "amountAsc" ], "description": "Default dateDesc (newest first)." }, "limit": { "type": "integer", "description": "Max rows to return (capped at 50)." } } } }, { "name": "time_series", "description": "Compute a metric bucketed over time (daily/weekly/monthly), for trend questions and charts. Returns ordered buckets, each with its start date and value.", "parameters": { "type": "object", "properties": { "metric": { "type": "string", "enum": [ "sum", "count" ] }, "bucket": { "type": "string", "enum": [ "daily", "weekly", "monthly" ] }, "filter": { "type": "object", "description": "Optional scope. All fields optional; omit to match everything. Use `class` (semantic group) as the primary lens; discover real category/merchant values with list_distinct first.", "properties": { "class": { "type": "string", "enum": [ "spending", "income", "fuliza", "fees", "withdrawals", "transfers", "loans", "reversals" ], "description": "Semantic type group. spending=categorizable purchases, fees=M-Pesa charges, withdrawals=cash out, fuliza=overdraft (drawn AND repaid; split with type)." }, "type": { "description": "Raw type(s), narrower than class: fulizaUse = Fuliza drawn, fulizaRepay = Fuliza repaid. Others via list_distinct(field=\"type\").", "anyOf": [ { "type": "string" }, { "type": "array", "items": { "type": "string" } } ] }, "direction": { "type": "string", "enum": [ "moneyIn", "moneyOut", "neutral" ], "description": "moneyOut = spending/fees, moneyIn = receipts, neutral = own-account transfers." }, "source": { "type": "string", "enum": [ "mpesa", "equity" ] }, "categorySource": { "type": "string", "enum": [ "none", "guess", "taught", "pinned" ] }, "category": { "type": "string", "description": "Exact category name." }, "merchant": { "description": "Exact counterparty/merchant name, or a list of names (e.g. its spelling variants) to match any of them.", "anyOf": [ { "type": "string" }, { "type": "array", "items": { "type": "string" } } ] }, "period": { "type": "string", "enum": [ "today", "thisWeek", "thisMonth", "thisYear", "lastMonth", "custom" ] }, "start": { "type": "string", "description": "ISO-8601 start (inclusive), only with period=custom." }, "end": { "type": "string", "description": "ISO-8601 end (exclusive), only with period=custom." }, "amount": { "type": "object", "description": "Amount bounds in cents (1 KES = 100).", "properties": { "min": { "type": "integer" }, "max": { "type": "integer" } } } } } }, "required": [ "metric", "bucket" ] } }, { "name": "matrix", "description": "Pivot transactions into a 2-D grid: a value per (rowKey, colKey) cell. Powers heatmaps (intensity across two dimensions, e.g. weekday x week) and stacked bars (composition over a time colKey, e.g. category stacked by month). Returns ordered rows, cols and non-zero cells.", "parameters": { "type": "object", "properties": { "metric": { "type": "string", "enum": [ "sum", "count" ] }, "rowKey": { "type": "string", "enum": [ "weekday", "week", "month", "day", "category", "merchant", "source", "class" ], "description": "Dimension binned down the rows (segments)." }, "colKey": { "type": "string", "enum": [ "weekday", "week", "month", "day", "category", "merchant", "source", "class" ], "description": "Dimension binned across the columns (often time)." }, "filter": { "type": "object", "description": "Optional scope. All fields optional; omit to match everything. Use `class` (semantic group) as the primary lens; discover real category/merchant values with list_distinct first.", "properties": { "class": { "type": "string", "enum": [ "spending", "income", "fuliza", "fees", "withdrawals", "transfers", "loans", "reversals" ], "description": "Semantic type group. spending=categorizable purchases, fees=M-Pesa charges, withdrawals=cash out, fuliza=overdraft (drawn AND repaid; split with type)." }, "type": { "description": "Raw type(s), narrower than class: fulizaUse = Fuliza drawn, fulizaRepay = Fuliza repaid. Others via list_distinct(field=\"type\").", "anyOf": [ { "type": "string" }, { "type": "array", "items": { "type": "string" } } ] }, "direction": { "type": "string", "enum": [ "moneyIn", "moneyOut", "neutral" ], "description": "moneyOut = spending/fees, moneyIn = receipts, neutral = own-account transfers." }, "source": { "type": "string", "enum": [ "mpesa", "equity" ] }, "categorySource": { "type": "string", "enum": [ "none", "guess", "taught", "pinned" ] }, "category": { "type": "string", "description": "Exact category name." }, "merchant": { "description": "Exact counterparty/merchant name, or a list of names (e.g. its spelling variants) to match any of them.", "anyOf": [ { "type": "string" }, { "type": "array", "items": { "type": "string" } } ] }, "period": { "type": "string", "enum": [ "today", "thisWeek", "thisMonth", "thisYear", "lastMonth", "custom" ] }, "start": { "type": "string", "description": "ISO-8601 start (inclusive), only with period=custom." }, "end": { "type": "string", "description": "ISO-8601 end (exclusive), only with period=custom." }, "amount": { "type": "object", "description": "Amount bounds in cents (1 KES = 100).", "properties": { "min": { "type": "integer" }, "max": { "type": "integer" } } } } } }, "required": [ "metric", "rowKey", "colKey" ] } }, { "name": "compare_periods", "description": "Compare one metric across two periods (e.g. this month vs last month). The delta and percent change are computed exactly on-device — do NOT do the subtraction yourself. periodA is the BASELINE (the earlier/reference period), periodB the one measured against it: delta = B − A, percent_change = (B − A) / A × 100. So \"this month vs last month\" is periodA=lastMonth, periodB=thisMonth. Both take the same period keys as a filter (today, thisWeek, thisMonth, thisYear, lastMonth, custom with start/end).", "parameters": { "type": "object", "properties": { "metric": { "type": "string", "enum": [ "sum", "count", "avg" ] }, "filter": { "type": "object", "description": "Optional scope. All fields optional; omit to match everything. Use `class` (semantic group) as the primary lens; discover real category/merchant values with list_distinct first.", "properties": { "class": { "type": "string", "enum": [ "spending", "income", "fuliza", "fees", "withdrawals", "transfers", "loans", "reversals" ], "description": "Semantic type group. spending=categorizable purchases, fees=M-Pesa charges, withdrawals=cash out, fuliza=overdraft (drawn AND repaid; split with type)." }, "type": { "description": "Raw type(s), narrower than class: fulizaUse = Fuliza drawn, fulizaRepay = Fuliza repaid. Others via list_distinct(field=\"type\").", "anyOf": [ { "type": "string" }, { "type": "array", "items": { "type": "string" } } ] }, "direction": { "type": "string", "enum": [ "moneyIn", "moneyOut", "neutral" ], "description": "moneyOut = spending/fees, moneyIn = receipts, neutral = own-account transfers." }, "source": { "type": "string", "enum": [ "mpesa", "equity" ] }, "categorySource": { "type": "string", "enum": [ "none", "guess", "taught", "pinned" ] }, "category": { "type": "string", "description": "Exact category name." }, "merchant": { "description": "Exact counterparty/merchant name, or a list of names (e.g. its spelling variants) to match any of them.", "anyOf": [ { "type": "string" }, { "type": "array", "items": { "type": "string" } } ] }, "period": { "type": "string", "enum": [ "today", "thisWeek", "thisMonth", "thisYear", "lastMonth", "custom" ] }, "start": { "type": "string", "description": "ISO-8601 start (inclusive), only with period=custom." }, "end": { "type": "string", "description": "ISO-8601 end (exclusive), only with period=custom." }, "amount": { "type": "object", "description": "Amount bounds in cents (1 KES = 100).", "properties": { "min": { "type": "integer" }, "max": { "type": "integer" } } } } }, "periodA": { "type": "object", "description": "Baseline (earlier/reference) period.", "properties": { "period": { "type": "string", "enum": [ "today", "thisWeek", "thisMonth", "thisYear", "lastMonth", "custom" ] }, "start": { "type": "string", "description": "ISO start, with custom." }, "end": { "type": "string", "description": "ISO end (exclusive), with custom." } }, "required": [ "period" ] }, "periodB": { "type": "object", "description": "Period measured against periodA.", "properties": { "period": { "type": "string", "enum": [ "today", "thisWeek", "thisMonth", "thisYear", "lastMonth", "custom" ] }, "start": { "type": "string", "description": "ISO start, with custom." }, "end": { "type": "string", "description": "ISO end (exclusive), with custom." } }, "required": [ "period" ] } }, "required": [ "metric", "periodA", "periodB" ] } }, { "name": "list_distinct", "description": "List the distinct values present for a field (merchant, category, type, source), with counts. Call this FIRST to discover the real category/merchant/type values before filtering by them — never guess these strings. Returns the 30 most frequent (total = how many exist); to find a specific one pass search, e.g. search=\"naivas\" returns its spelling variants.", "parameters": { "type": "object", "properties": { "field": { "type": "string", "enum": [ "merchant", "category", "type", "source" ] }, "filter": { "type": "object", "description": "Optional scope. All fields optional; omit to match everything. Use `class` (semantic group) as the primary lens; discover real category/merchant values with list_distinct first.", "properties": { "class": { "type": "string", "enum": [ "spending", "income", "fuliza", "fees", "withdrawals", "transfers", "loans", "reversals" ], "description": "Semantic type group. spending=categorizable purchases, fees=M-Pesa charges, withdrawals=cash out, fuliza=overdraft (drawn AND repaid; split with type)." }, "type": { "description": "Raw type(s), narrower than class: fulizaUse = Fuliza drawn, fulizaRepay = Fuliza repaid. Others via list_distinct(field=\"type\").", "anyOf": [ { "type": "string" }, { "type": "array", "items": { "type": "string" } } ] }, "direction": { "type": "string", "enum": [ "moneyIn", "moneyOut", "neutral" ], "description": "moneyOut = spending/fees, moneyIn = receipts, neutral = own-account transfers." }, "source": { "type": "string", "enum": [ "mpesa", "equity" ] }, "categorySource": { "type": "string", "enum": [ "none", "guess", "taught", "pinned" ] }, "category": { "type": "string", "description": "Exact category name." }, "merchant": { "description": "Exact counterparty/merchant name, or a list of names (e.g. its spelling variants) to match any of them.", "anyOf": [ { "type": "string" }, { "type": "array", "items": { "type": "string" } } ] }, "period": { "type": "string", "enum": [ "today", "thisWeek", "thisMonth", "thisYear", "lastMonth", "custom" ] }, "start": { "type": "string", "description": "ISO-8601 start (inclusive), only with period=custom." }, "end": { "type": "string", "description": "ISO-8601 end (exclusive), only with period=custom." }, "amount": { "type": "object", "description": "Amount bounds in cents (1 KES = 100).", "properties": { "min": { "type": "integer" }, "max": { "type": "integer" } } } } }, "search": { "type": "string", "description": "Optional. Only values containing this text (any case)." } }, "required": [ "field" ] } }, { "name": "get_balance", "description": "Get the latest known wallet balance for an account. M-Pesa returns its last stated balance. Equity does NOT publish a balance in its SMS, so it returns available:false — say so honestly.", "parameters": { "type": "object", "properties": { "source": { "type": "string", "enum": [ "mpesa", "equity" ] } }, "required": [ "source" ] } }, { "name": "get_transaction_detail", "description": "Get the full detail for one transaction by its id (from query_transactions): the original SMS text and the linked leg of a cross-channel transfer, if any.", "parameters": { "type": "object", "properties": { "id": { "type": "string", "description": "A transaction id like \"tx_3\"." } }, "required": [ "id" ] } } ] }