Termux-AIChain Logo

Termux-AIChain

v1.0.9
Foundation
pip / npm
Sponsor GitHub Founder CV

Termux-AIChain

Sovereign Zero-Dependency AI Chaining & Multimodal Autonomous Agent Framework for Android Edge

PyPI Version npm Version License Tests Platform Cold Start Memory
1-Line Quick Installation

Install the official package directly into your Android Termux or Node.js runtime:

curl -sSL https://raw.githubusercontent.com/uno-km/termux-aichain/main/scripts/install.sh | bash
# or manually:
pip install --upgrade termux-aichain
npm install termux-aichain

The Engineering Challenge

Mainstream desktop AI frameworks (LangChain, LlamaIndex, CrewAI) introduce 40~80 heavy third-party dependencies (Pydantic, NumPy, aiohttp, requests, tenacity). On mobile ARM Android runtimes, these frameworks incur 200MB+ memory baselines, 1,200ms+ cold-start delays, and frequent C/C++ compilation failures during pip install.

The Architectural Breakthrough

termux-aichain is engineered under the Zero-Heavy-Dependency doctrine. Built entirely with the Python 3.10+ Standard Library (urllib, sqlite3, subprocess, json, math) and Pure Node.js 18+ ESM, it achieves an ultra-low 12.8ms cold-start import and runs seamlessly in under 14.2MB RSS RAM with zero external wheels required.

Core Capabilities & Architectural Pillars

Zero External Heavy Dependencies

Pure Python standard library and pure Node.js ESM. Cold start import in under 12.8ms with less than 268KB total package footprint.

StateGraph & Autonomous ReAct Engine

Deterministic cyclic state machines with entry points, explicit edges, conditional routing, and recursion limits (LangGraph lightweight alternative).

Local Server Hardware Fine-Tuning

12 hardware flags exposed for llama-server and BitNet.cpp (threads, n_ctx, GPU layers, FlashAttention, KV quantization q8_0/q4_0, RoPE).

SQLite Long-Term Memory & Cosine RAG

Persistent ACID key-value memory and pure cosine similarity vector search without ChromaDB, FAISS, or NumPy.

1-Line REST, SSE & Live Web Dashboard

Exposes any agent over local mobile WiFi with Server-Sent Events (SSE), live chat, interactive graph topology viewer, and tracer profiler table.

Native Android Hardware & Ecosystem Tools

Direct tool-calling wrappers for Termux-API (battery, sensors, GPS, STT, TTS, vibration) with 3-tier kernel sysfs fallbacks.

Supported Operations & Subsystems Matrix

Subsystem Category Supported Operations & Modules Status
Core Chaining PromptTemplate, ChatPromptTemplate, Runnable, | Pipe Operator, JsonOutputParser, Splitters Production
Multi-Agent Graph StateGraph, CompiledGraph, START, END, Tool, @tool, create_react_agent Production
Long-Term Memory ConversationBufferMemory, SQLiteEntityMemory, SQLiteVectorStore, FactExtractor Production
Local Serving & Tracing AgentServer, serve(), Tracer, TraceSpan, @traceable, Tree Renderer, Live Dashboard Production
Device Hardware API Battery, Accelerometer, Ambient Light, GPS Location, STT, TTS, Vibration, Shell Production
Ecosystem Tooling transcribe_speech (STT), generate_diffusion_image (Diffusion), browse_web_headless (Playwright) Production

Canonical Usage Example

from termux_aichain import (
    create_react_agent,
    BitNetChat,
    get_battery_status,
    transcribe_speech,
    generate_diffusion_image,
    vibrate_device,
    HumanMessage
)

# 1. Initialize local 1-bit / GGUF model brain
llm = BitNetChat(base_url="http://127.0.0.1:8080/v1", temperature=0.1)

# 2. Assemble multimodal sovereign agent
agent = create_react_agent(
    model=llm,
    tools=[get_battery_status, transcribe_speech, generate_diffusion_image, vibrate_device],
    system_prompt="You are a sovereign multimodal agent running on Android Termux."
)

# 3. Autonomous multi-step execution
state = agent.invoke({
    "messages": [HumanMessage(content="Check battery and generate sovereign emblem.")]
})
print("Final Output:", state["messages"][-1].content)

Next Steps & Navigation

Explore the full documentation suite: