<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: utestwalter</title>
    <description>The latest articles on DEV Community by utestwalter (@utestwalter).</description>
    <link>https://dev.to/utestwalter</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3256509%2Fb080c9da-0b29-45bb-a6aa-dd493459eb06.png</url>
      <title>DEV Community: utestwalter</title>
      <link>https://dev.to/utestwalter</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/utestwalter"/>
    <language>en</language>
    <item>
      <title>Telegram AI Agent step by step (my first experience)</title>
      <dc:creator>utestwalter</dc:creator>
      <pubDate>Tue, 10 Jun 2025 18:51:27 +0000</pubDate>
      <link>https://dev.to/utestwalter/telegram-ai-agent-step-by-step-my-first-experience-364o</link>
      <guid>https://dev.to/utestwalter/telegram-ai-agent-step-by-step-my-first-experience-364o</guid>
      <description>&lt;p&gt;Hi everyone!&lt;/p&gt;

&lt;p&gt;I love science, and recently I explored how AI could help me stay updated with scientific news — automatically and on schedule. To do this, I built an &lt;strong&gt;AI agent&lt;/strong&gt; as a Telegram bot that performs scheduled web searches and sends links directly to my Telegram channel. Additionally, this agent can send me any reminder.&lt;/p&gt;

&lt;p&gt;It was my first real experiment with building an autonomous AI agent, and it turned out to be both fun and practical.&lt;/p&gt;

&lt;h3&gt;
  
  
  Here’s the tech stack I used:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Telegram Chatbot
&lt;/li&gt;
&lt;li&gt;OpenAI Assistant API
&lt;/li&gt;
&lt;li&gt;APScheduler
&lt;/li&gt;
&lt;li&gt;SerpAPI
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What can this AI agent do?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Composes a search query based on user input
&lt;/li&gt;
&lt;li&gt;Performs web search on schedule
&lt;/li&gt;
&lt;li&gt;Sends results to a Telegram channel
&lt;/li&gt;
&lt;li&gt;Delivers reminders at set times
&lt;/li&gt;
&lt;li&gt;Works fully autonomously
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Step-by-Step Implementation
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1 – Create a Telegram Bot
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Open Telegram and message &lt;code&gt;@BotFather&lt;/code&gt; → &lt;code&gt;/newbot&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Choose a name and username
&lt;/li&gt;
&lt;li&gt;Save the provided HTTP API Token — it will be used in the code
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 2 – Get your API Key
&lt;/h3&gt;

&lt;p&gt;This depends on the LLM you plan to use. I chose ChatGPT, so I registered at OpenAI, generated an API key, and stored it securely.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3 – Set up the Project in your IDE
&lt;/h3&gt;

&lt;p&gt;Once you have these three:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Telegram bot
&lt;/li&gt;
&lt;li&gt;Telegram token
&lt;/li&gt;
&lt;li&gt;OpenAI API key
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;…you can start building!&lt;/p&gt;

&lt;p&gt;I used VS Code and Python 3.10. Project structure:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;bot_prompt_setup.py&lt;/code&gt; — Telegram bot functionality
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;assistant_core.py&lt;/code&gt; — LLM and web search logic
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.env&lt;/code&gt; — stores secrets (gitignored)
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;prompts/&lt;/code&gt; — saved task definitions
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 4 – Write the Python Scripts
&lt;/h3&gt;

&lt;p&gt;I used an AI assistant to help write the core logic (you can find the full code on GitHub — link below). The main functionality is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;bot_prompt_setup.py&lt;/code&gt;: bot UI, prompt generation, file creation, scheduling, task management
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;assistant_core.py&lt;/code&gt;: handles communication with OpenAI and SerpAPI
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Security tips:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;API keys and tokens are stored in &lt;code&gt;.env&lt;/code&gt; (not pushed to GitHub)
&lt;/li&gt;
&lt;li&gt;Bot access is limited to a whitelist of Telegram user IDs
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 5 – Run &amp;amp; Test the Bot
&lt;/h3&gt;

&lt;p&gt;Run &lt;code&gt;bot_prompt_setup.py&lt;/code&gt; and test the workflow end-to-end:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start the bot
&lt;/li&gt;
&lt;li&gt;Create a task
&lt;/li&gt;
&lt;li&gt;Confirm the task runs correctly
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I tested various task frequencies:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;daily, weekly, monthly, once
&lt;/li&gt;
&lt;li&gt;with and without web search
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also fine-tune UX: rename buttons, add hints, translate the interface.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The most important part: prompt design.&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
I use 4 different prompts for LLM to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Parse and prepare task-specific instructions
&lt;/li&gt;
&lt;li&gt;Format the results nicely for the user
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 6 – Deploy to Production
&lt;/h3&gt;

&lt;p&gt;After testing and bug fixing, I deployed the agent based on the criteria:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Code should be accessible to other developers
&lt;/li&gt;
&lt;li&gt;Keys and tokens must remain secure
&lt;/li&gt;
&lt;li&gt;Support for always-on execution
&lt;/li&gt;
&lt;li&gt;Reasonable service cost
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s why I chose GitHub + PythonAnywhere as a hosting solution.&lt;/p&gt;




&lt;h2&gt;
  
  
  Screenshots
&lt;/h2&gt;

&lt;p&gt;Start&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx81azz7enzdq16e23fkv.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx81azz7enzdq16e23fkv.jpeg" alt="Image description" width="800" height="485"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Search task&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffi64fkthukeylplllluv.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffi64fkthukeylplllluv.jpeg" alt="Image description" width="800" height="788"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Reminder&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvc2zfbd2iwac00unkv5b.jpeg" alt="Image description" width="800" height="568"&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Links
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/utestwalter/Mila" rel="noopener noreferrer"&gt;GitHub repo&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://t.me/MilaAgentBot" rel="noopener noreferrer"&gt;Public Telegram bot&lt;/a&gt; - &lt;em&gt;you can enter &lt;code&gt;/start&lt;/code&gt;, but main functionality works by invitation only&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  So, what exactly does my AI agent do?
&lt;/h3&gt;

&lt;p&gt;Performs autonomous web searches, formats the results, and sends them (or reminders) on a schedule — all inside Telegram.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Convenient?&lt;/strong&gt; Yes.&lt;br&gt;
&lt;strong&gt;Perfect?&lt;/strong&gt; Not yet.&lt;/p&gt;

&lt;p&gt;Currently, the LLM controls logic and formatting, but not the search itself. As a result, I can get links that are not always relevant. That’s why for the next version I’d like to add:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Automatic HTML parsing
&lt;/li&gt;
&lt;li&gt;PDF extraction from pages
&lt;/li&gt;
&lt;li&gt;Clicking links and analyzing embedded content
&lt;/li&gt;
&lt;li&gt;Summarizing &amp;amp; translating content on schedule
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s a more advanced challenge. If you’ve built something like this — I’d love to hear your experience: &lt;strong&gt;what parser and web-search API work best&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>python</category>
      <category>learning</category>
      <category>openai</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
