<?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: Alecu</title>
    <description>The latest articles on DEV Community by Alecu (@alecu382).</description>
    <link>https://dev.to/alecu382</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4267129%2F22463b62-0c3f-4c65-b75a-1ce7e9f1cb74.png</url>
      <title>DEV Community: Alecu</title>
      <link>https://dev.to/alecu382</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alecu382"/>
    <language>en</language>
    <item>
      <title>I built an AI agent that runs entirely on my Android phone (Termux + Python)</title>
      <dc:creator>Alecu</dc:creator>
      <pubDate>Thu, 26 Nov 2026 14:52:07 +0000</pubDate>
      <link>https://dev.to/alecu382/i-built-an-ai-agent-that-runs-entirely-on-my-android-phone-termux-python-3hf1</link>
      <guid>https://dev.to/alecu382/i-built-an-ai-agent-that-runs-entirely-on-my-android-phone-termux-python-3hf1</guid>
      <description>&lt;p&gt;I don't have a laptop for this project. Everything I write about below was built, compiled and run on one Android phone: Termux, Python, a Java Android app compiled on the device, and AI models through APIs.&lt;/p&gt;

&lt;p&gt;The result is &lt;strong&gt;AXON&lt;/strong&gt;, my personal assistant. It can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;operate the phone (open apps, tap, type and read the screen through Android Accessibility),&lt;/li&gt;
&lt;li&gt;run code in Termux,&lt;/li&gt;
&lt;li&gt;search the web with sources,&lt;/li&gt;
&lt;li&gt;split big tasks between several AI sub-agents,&lt;/li&gt;
&lt;li&gt;show every step it takes live, while it is working.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's how it fits together and what I learned.&lt;/p&gt;

&lt;h2&gt;
  
  
  The architecture (simpler than it sounds)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Android app (Java, built in Termux)
        │  HTTP on 127.0.0.1
        ▼
Python gateway (Termux)  ──►  AI models (OpenAI-compatible APIs)
        │
        ├─ tools: shell, files, web search, phone actions
        └─ job journal (every step written to disk)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;1. A small Python gateway in Termux.&lt;/strong&gt; It listens only on &lt;code&gt;127.0.0.1&lt;/code&gt;, uses a bearer token, and turns every request into a &lt;em&gt;job&lt;/em&gt; with its own folder, a status and a journal of steps. The app never talks to an AI provider directly; it only talks to the gateway.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. The model loop.&lt;/strong&gt; A classic tool-calling loop: send the conversation and the tool definitions, run the tool calls the model asks for, append the results, repeat. Most providers speak the OpenAI chat format, so one client covers many of them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;urllib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"model"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"messages"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"tools"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt;
    &lt;span class="n"&gt;req&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;urllib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rstrip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;"/chat/completions"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"Authorization"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Bearer "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                 &lt;span class="s2"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;urllib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;urlopen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"choices"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code uses only the standard library: no pip, no build problems on ARM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. The phone as a tool.&lt;/strong&gt; The Android app runs an Accessibility service, so the agent can call actions like &lt;code&gt;screen&lt;/code&gt;, &lt;code&gt;tap&lt;/code&gt;, &lt;code&gt;type&lt;/code&gt;, &lt;code&gt;back&lt;/code&gt; and &lt;code&gt;screenshot&lt;/code&gt;. The screen comes back as a tree of text and bounds, which models read surprisingly well.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Termux:API for the native bits.&lt;/strong&gt; Notifications with buttons, clipboard and scheduled jobs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;termux-notification --id job-42 --title &lt;span class="s2"&gt;"Task finished"&lt;/span&gt; \
  --content &lt;span class="s2"&gt;"Tap to review"&lt;/span&gt; \
  --button1 &lt;span class="s2"&gt;"Approve"&lt;/span&gt; --button1-action &lt;span class="s2"&gt;"python ~/agent/approve.py 42"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Things that bit me (so they don't bite you)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Termux:API calls can hang.&lt;/strong&gt; Wrap every one in a timeout. One stuck &lt;code&gt;termux-media-scan&lt;/code&gt; froze a whole job.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Background limits.&lt;/strong&gt; Android kills long-running processes and blocks starting activities from the background. A periodic &lt;code&gt;termux-job-scheduler&lt;/code&gt; job that checks the worker and restarts it if needed fixed this for me.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run services natively.&lt;/strong&gt; If you use a proot Linux distro inside Termux, start Android-facing services from native Termux, not from inside proot. Some APIs only work there.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transparency beats magic.&lt;/strong&gt; The most useful feature was a &lt;em&gt;live trace&lt;/em&gt;: every model call, web search, file read and sub-agent step, shown while the agent works and cleared when the answer arrives. Once you can see what it's doing, you start to trust it, and you can debug it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Approval gates.&lt;/strong&gt; Anything that spends money, sends messages or changes something public needs an explicit "yes" from me. The agent prepares; I decide.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Building an Android app on Android
&lt;/h2&gt;

&lt;p&gt;Yes, you can compile an APK in Termux: &lt;code&gt;javac&lt;/code&gt; against &lt;code&gt;android.jar&lt;/code&gt;, &lt;code&gt;d8&lt;/code&gt; for dex, &lt;code&gt;aapt2&lt;/code&gt; for resources, then &lt;code&gt;apksigner&lt;/code&gt;. A full build takes about 30 seconds on a mid-range phone. My tip is to split the UI into small classes early. My &lt;code&gt;MainActivity&lt;/code&gt; grew past 100 KB before I split it into modules, and every change got slower until I did.&lt;/p&gt;

&lt;h2&gt;
  
  
  Was AI used to build it?
&lt;/h2&gt;

&lt;p&gt;Absolutely. I work with AI coding agents the way you'd work with a fast junior team. I decide the architecture, review the changes and test on the device. That combination is the real superpower: one person, one phone, a lot of output.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's next
&lt;/h2&gt;

&lt;p&gt;I'm using the same setup for freelance work: Python automation, CSV/CRM data cleaning, REST API → SQLite pipelines and FFmpeg media automation. Some small examples, each with a verified run, are on my GitHub: &lt;strong&gt;&lt;a href="https://github.com/Alecu382" rel="noopener noreferrer"&gt;github.com/Alecu382&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you're building on Termux too, I'd love to hear what you're making, and I'm happy to answer questions in the comments. 👇&lt;/p&gt;

</description>
      <category>android</category>
      <category>python</category>
      <category>ai</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
