Skip to main content
A Telegram bot built with Upsonic’s AutonomousAgent that reads receipt photos via OCR, extracts structured data, and logs expenses to a CSV file in its workspace. The agent’s behavior (how to parse receipts, what CSV columns to use, how to handle duplicates) is defined entirely in AGENTS.md, not in code.

Overview

The setup has three parts:
  1. AutonomousAgent with a workspace directory and one custom tool (ocr_extract_text)
  2. TelegramInterface in CHAT mode for conversational context
  3. Workspace files (AGENTS.md, SOUL.md) that define the agent’s behavior and identity
The agent handles CSV creation, writing, duplicate checking, and monthly summaries on its own through workspace filesystem access. The only custom tool is OCR, because the agent can’t read images natively.

Project Structure

Environment Variables

Installation

Create a Telegram bot via @BotFather, then start ngrok:

Usage

The server starts on 0.0.0.0:8000 and registers the Telegram webhook.

How It Works

Flow

  1. User sends a receipt photo in Telegram
  2. Agent calls ocr_extract_text (auto-detects the image path)
  3. Agent parses OCR output following rules in AGENTS.md: converts dates, normalizes amounts, picks a category
  4. Agent reads expenses.csv to check for duplicates, then appends the new row
  5. Agent replies with a short confirmation and monthly running total

Complete Implementation

main.py

No system prompt, no hardcoded behavior. The agent reads everything from its workspace.

tools.py

One tool. Auto-detects Telegram media files, runs EasyOCR, returns text with confidence scores.

Workspace: AGENTS.md

The key to this example. Instead of hardcoding CSV logic in Python, the agent reads its instructions from AGENTS.md:
  • Receipt workflow: call OCR, parse output, check duplicates, save, confirm
  • CSV schema: columns, types, format rules (dates as YYYY-MM-DD, amounts as floats)
  • Summary logic: group by category, compute percentages, show totals
  • Rules: always use ocr_extract_text for images, never delete data files
Change the CSV schema or add new categories by editing AGENTS.md. The agent adapts without touching code.

Notes

  • OCR language is set to Turkish (tr). Change the languages parameter in tools.py for other languages.
  • Install with upsonic[ocr] to get EasyOCR and its dependencies.
  • The agent has full filesystem access within the workspace but no shell access (enable_shell defaults to disabled for this setup).

Repository

View the full example: Expense Tracker Bot