Building My Personal Telegram AI Agent: A Practical, Tool-Using Assistant

I wanted an assistant that could do more than chat. I wanted one that could run useful tools, remember context, automate scheduled tasks, and stay close to my real workflow.

So I built this project: a personal Telegram-based AI agent powered by pydantic-ai, a Google model, and a focused Python architecture.

Source Code: You can find the complete project repository on GitHub at alaminkouser/agent.

This post walks through what I built, why I designed it this way, and what makes it portfolio-worthy.

Project Goal

The goal was simple: create a reliable personal AI operator that I can message from Telegram and use for real tasks, not demos.

The bot can:

In short, this is an AI assistant with action capability, not just text generation.

High-Level Architecture

The system is intentionally modular:

This separation keeps transport (Telegram), reasoning (agent), and automation (cron/jobs) loosely coupled and easy to extend.

diagram

Why Telegram as the Interface?

Telegram gives me:

For a personal operator, Telegram is the fastest route to daily usability.

AI Layer: pydantic-ai + Tool-First Design

The core agent is created in agent_main() with:

I chose a tool-first architecture so the model can decide when to call utilities and external systems rather than forcing brittle hardcoded flows.

Streaming Events for Better UX

Instead of waiting for one final response, the bot streams agent events and displays progress in chunks:

This makes interactions feel alive and transparent. Users can see when the assistant is reasoning versus executing.

diagram

Scheduled Automation with a File-Based Cron Queue

One of my favorite parts is the scheduled task system.

The cron_create tool writes jobs into .DATA/cron as timestamped files.
The background worker continuously checks this directory, runs due tasks through the same agent pipeline, and delivers results to Telegram.

Why this approach works well:

It is simple infrastructure with practical power.

Real-World Utility: Website Status Updates

The status_put tool bridges AI and personal branding.
From chat, I can set a concise status shown on my website (alaminkouser.com/status/) through a dedicated CLI command.

This is a good example of “small feature, high leverage”: tiny code footprint, immediate day-to-day value.

Reliability and Safety Choices

A few implementation choices help keep the system reliable:

These are not flashy features, but they make the assistant trustworthy in real use.

Tech Stack

Challenges I Solved

1) Turning model output into chat-safe content

Raw model responses are not always Telegram-ready. I used telegramify-markdown to split long content and support rich output types (text, photo, file) in a unified path.

2) Keeping context between messages

I persist message history per user session so the assistant can continue conversations naturally across turns.

3) Mixing synchronous and async runtime concerns

The bot runs polling while a cron worker runs in parallel. I handled this with a separate daemon thread that runs an async worker loop.

What I Learned

This project reinforced an important engineering lesson:

use simple, composable pieces to build powerful systems.

I did not need a massive platform. A clean Telegram client layer, a capable tool-using agent core, and a small scheduler gave me a personal AI system that is genuinely useful.

What’s Next

Planned improvements:


agent, ai, ai-agent, automation, bot, cron, gemma, llm, mcp, model-context-protocol, personal-assistant, pydantic, pydantic-ai, python, python-telegram-bot, scheduling, serpapi, telegram, telegram-bot, tool-calling, web-search