agent-rt

Local-first, agent-native developer tools.

View My GitHub Profile

Recipe: Accounting

Track expenses and income with categories. Ask natural-language questions like “how much did I spend on food last month?” and let the agent translate to structured queries.

1. Design

Make a synap app “ledger” with two entity types — “expense” and “income”. Both have amount, currency, description (vectorized), occurred_at, account.

{"tool": "init_app", "args": {
  "app": "ledger",
  "types": {
    "expense": [
      {"name": "amount",      "value_type": "number", "indexed": true, "required": true},
      {"name": "currency",    "value_type": "string", "default":   "JPY"},
      {"name": "category",    "value_type": "string", "indexed":   true},
      {"name": "description", "value_type": "string", "vectorized": true},
      {"name": "occurred_at", "value_type": "date",   "indexed":   true, "required": true},
      {"name": "account",     "value_type": "string"}
    ],
    "income": [
      {"name": "amount",      "value_type": "number", "indexed": true, "required": true},
      {"name": "currency",    "value_type": "string", "default":   "JPY"},
      {"name": "source",      "value_type": "string", "indexed":   true},
      {"name": "description", "value_type": "string", "vectorized": true},
      {"name": "occurred_at", "value_type": "date",   "indexed":   true, "required": true},
      {"name": "account",     "value_type": "string"}
    ]
  }
}}

Multi-type app, so we use types (not the fields shorthand). amount and occurred_at are required — half-populated ledger rows are a bug magnet. currency defaults to "JPY" server-side, so each transaction skips it unless the agent means a different currency. occurred_at is a proper date field so malformed input ("yesterday", "2026-13-40") is rejected on write rather than silently corrupting range queries.

2. Record transactions

Log: spent 1200 yen on lunch at Ichiran today, paid with SMBC card.

{"tool": "write", "args": {
  "app": "ledger",
  "ops": [{
    "op": "create",
    "type": "expense",
    "data": {
      "amount": 1200,
      "category": "food", "description": "Lunch at Ichiran",
      "occurred_at": "2026-04-19", "account": "SMBC card"
    },
    "returning": true
  }]
}}

returning: true echoes the persisted row so the agent can confirm currency defaulted to "JPY" and the entity_id without a second call. Response:

[{
  "op": "create",
  "entity_ids": ["eid_abc"],
  "entities": [{
    "entity_id": "eid_abc",
    "amount": 1200,
    "currency": "JPY",
    "category": "food",
    "description": "Lunch at Ichiran",
    "occurred_at": "2026-04-19",
    "account": "SMBC card"
  }]
}]

Log: received 500,000 yen salary from Acme Corp on 2026-04-25.

{"tool": "write", "args": {
  "app": "ledger",
  "ops": [{
    "op": "create",
    "type": "income",
    "data": {
      "amount": 500000,
      "source": "Acme Corp", "description": "Salary April 2026",
      "occurred_at": "2026-04-25", "account": "SMBC main"
    }
  }]
}}

3. Category rollups

How much did I spend on food in April?

{"tool": "query", "args": {
  "app":  "ledger",
  "type": "expense",
  "filters": [
    {"field": "category",    "op": "eq",      "value": "food"},
    {"field": "occurred_at", "op": "between", "value": ["2026-04-01", "2026-04-30"]}
  ],
  "aggregate": [{"fn": "sum", "field": "amount", "as": "total"}]
}}

TSV out: total\n48200. No row materialization, no client-side summation.

Grouped breakdown by category:

{"tool": "query", "args": {
  "app":  "ledger",
  "type": "expense",
  "filters": [{"field": "occurred_at", "op": "between",
               "value": ["2026-04-01", "2026-04-30"]}],
  "aggregate": [
    {"fn": "sum", "field": "amount", "as": "total"},
    {"fn": "count"}
  ],
  "group_by": "category"
}}

TSV out:

key	total	count
food	48200	13
transport	9400	4
streaming	6500	2

4. Cross-type net position

What’s my net for April?

Two queries (expenses + income), agent subtracts totals. Or a single cross-type query by omitting type:

{"tool": "query", "args": {
  "app": "ledger",
  "filters": [{"field": "occurred_at", "op": "between",
               "value": ["2026-04-01", "2026-04-30"]}]
}}

Result includes a type column — partition client-side.

Did I ever pay for that music subscription thing?

{"tool": "search", "args": {
  "app":        "ledger",
  "type":       "expense",
  "query_text": "music streaming subscription",
  "mode":       "semantic"
}}

Finds a “Spotify Family” line even if the description says only “Spotify” — embeddings capture meaning, not just tokens.

6. Monthly summary as a prompt

Give me a one-paragraph summary of my April finances.

The agent orchestrates:

  1. query all April expenses + incomes
  2. Group by category client-side (or use count_only + group_by for counts, then one query per category for totals)
  3. Compose prose (“spent ¥48,200 on food across 13 meals out, ¥9,400 on transport, ¥6,500 on streaming…”)

Design tips