DEV Community

John Otienoh
John Otienoh

Posted on

My AI habit Tracker

Build an intelligent agent, connect it to Telex.im, and make it do something genuinely useful.

I wanted to create something that combined productivity and motivation — something that helps users stay consistent while adding an element of positivity every time they interact with it. That’s how I came up with the Motivational Habit Tracker AI Agent.


💡 Concept

The idea is simple but meaningful:
Users can create and manage habits (like “read 10 pages” or “exercise daily”), and each time they check their progress, they receive a motivational quote fetched from the ZenQuotes API.

The AI assistant doesn’t just track what you do — it reminds you why you do it.


🧩 Architecture Overview

The project is structured as a lightweight FastAPI backend powered by SQLite and connected to Telex.im via a JSON-RPC (A2A) API.

FastAPI App
 ┣━━ ai_helper.py         → Fetches motivational quotes (AI agent logic)
 ┣━━ database.py          → Handles SQLite database (habits, timestamps)
 ┣━━ habit_manager.py     → Business logic layer for CRUD + quotes
 ┗━━ main.py              → REST and JSON-RPC endpoints for Telex integration
Enter fullscreen mode Exit fullscreen mode

Each component has a focused responsibility — helping keep the project simple, modular, and easy to maintain.


⚙️ Why I Chose FastAPI

The original version of this project was written in Flask, but I decided to refactor it into FastAPI for several reasons:

  1. Asynchronous Support – Perfect for APIs that fetch external data like quotes.
  2. Automatic Documentation – FastAPI generates Swagger and ReDoc docs instantly.
  3. Modern Syntax – Type hints, Pydantic validation, and async endpoints make the code cleaner and more reliable.
  4. Better Performance – FastAPI is built on Starlette and Uvicorn, which are lightweight and fast.

🧠 AI Integration (ZenQuotes API)

For motivation, I integrated the ZenQuotes API, which provides a random inspirational quote on each call.

Here’s the core logic from ai_helper.py:

def get_motivational_quote():
    try:
        response = requests.get("https://zenquotes.io/api/random", timeout=5)
        if response.status_code == 200:
            data = response.json()[0]
            return f'"{data["q"]}" - {data["a"]}'
    except Exception:
        return "💡 Keep going — small, consistent steps lead to big change!"
Enter fullscreen mode Exit fullscreen mode

If the API is unreachable, the system gracefully falls back to a default motivational message.


🗃️ Data Model

SQLite was a natural choice for simplicity.
Each user has multiple habits stored in a table with frequency and timestamps:

id username habit frequency created_at last_done

The backend automatically determines when a habit is due based on frequency (daily, weekly, etc.) and adds reminders accordingly.


🧩 Telex Integration (A2A JSON-RPC)

Telex.im uses a JSON-RPC 2.0 protocol for agents.
I implemented an /a2a/habits endpoint that accepts structured messages like this:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "habits/get",
  "params": { "username": "john" }
}
Enter fullscreen mode Exit fullscreen mode

The agent responds with:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "habits": [...],
    "motivational_quote": "\"Action is the foundational key to all success.\" - Pablo Picasso"
  }
}
Enter fullscreen mode Exit fullscreen mode

It supports:

  • habits/get → View habits
  • habits/add → Add a new habit
  • habits/mark_done → Mark a habit as complete

This makes the agent easy to integrate with Telex.im or any client that supports JSON-RPC.


🧭 Thought Process & Design Decisions

Here’s how I approached the project step by step:

1️⃣ Simplicity First

I started with a small, clear goal — track habits and return motivational quotes. The simpler the core logic, the easier it is to expand later.

2️⃣ Separation of Concerns

I divided the code into modules:

  • database.py for persistence
  • habit_manager.py for core logic
  • ai_helper.py for AI tasks
  • main.py for API routes

This made debugging and testing straightforward.

3️⃣ User Experience as a Priority

Each API response includes a motivational quote, even when users just check their habits.
This transforms the backend into something encouraging — not just functional.

4️⃣ Error Handling and Validation

All endpoints validate JSON-RPC format, parameters, and catch exceptions gracefully.
Invalid requests return clear error messages instead of crashing the service.


⚡ Example Usage

POST /habits/john

{
  "habit": "Exercise",
  "frequency": "daily"
}
Enter fullscreen mode Exit fullscreen mode

GET /habits/john
Returns all habits with reminders and a motivational quote.

POST /a2a/habits

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "habits/mark_done",
  "params": {"username": "john", "habit": "Exercise"}
}
Enter fullscreen mode Exit fullscreen mode

🌍 Deployment

The app runs seamlessly on Railway, Render, or Fly.io using:

web: uvicorn main:app --host 0.0.0.0 --port $PORT
Enter fullscreen mode Exit fullscreen mode

💭 Key Takeaways

  • Building an “AI Agent” isn’t just about complex models — even a motivational quote generator can add emotional intelligence.
  • FastAPI made development fast, intuitive, and well-documented.
  • Clean architecture (small, focused modules) saved time debugging and made testing easier.
  • Integrating JSON-RPC taught me how structured communication between agents works.

🚀 What’s Next

Future improvements could include:

  • User authentication (JWT)
  • Tracking streaks or progress percentage
  • A web dashboard built with Vue or React
  • Integration with a real AI model for personalized motivational feedback

🏁 Final Thoughts

This project was a great exercise in combining backend logic, AI integration, and human-centered design.
It reminded me that small touches — like a random quote — can make digital tools feel alive and supportive.

If you’d like to try it or explore the source, check out the GitHub repo and connect with me on Telex.im!

“Discipline is choosing between what you want now and what you want most.”
— Abraham Lincoln


Top comments (0)