Termux-AIChain Logo

Termux-AIChain

v1.0.9
Foundation
pip / npm
Sponsor GitHub Founder CV

Complete API Reference

Complete technical specification of classes, functions, and interfaces across all 7 subsystems

1. Core Chaining Engine (termux_aichain.core)

Class / Function Type Description
PromptTemplate.from_template(template: str) ClassMethod Creates a template with named variable substitution and escape protection for double braces ({{...}}).
ChatPromptTemplate.from_messages(messages: List) ClassMethod Constructs structured multi-role chat message prompts (SystemMessage, HumanMessage, AIMessage).
RunnableSequence / | Operator Class Chains multiple runnables sequentially with synchronous (invoke) and streaming (stream) execution.
JsonOutputParser() Class Extracts and parses JSON payloads from LLM outputs with markdown fence stripping and fallback recovery.
RecursiveCharacterTextSplitter(chunk_size, chunk_overlap) Class Splits documents recursively along paragraph and sentence boundaries.

2. Multi-Agent Graph Engine (termux_aichain.graph)

Symbol Type Description
StateGraph(state_schema) Class Deterministic cyclic state machine supporting nodes, edges, conditional branches, and entry points.
create_react_agent(model, tools, system_prompt, max_iterations=10) Function Factory that compiles an autonomous Reasoning + Acting loop with declared Tool instances.
Tool(name, description, func) / @tool Decorator / Class Wraps arbitrary Python functions into tool definitions callable by ReAct agents.
START / END Constants Special terminal identifiers representing graph entry point and final exit point.

3. Memory & Vector Store (termux_aichain.memory)

Class Backend Description
ConversationBufferMemory(max_messages=20) RAM Sliding window rolling conversation history buffer.
SQLiteEntityMemory(db_path) SQLite ACID Persistent key-value entity memory table for long-term fact retention.
SQLiteVectorStore(db_path) SQLite + DotProduct Pure Python cosine similarity vector index operating without external ML libraries.

4. Local Serving & Telemetry (termux_aichain.serve & trace)

Symbol Module Description
serve(agent, host="0.0.0.0", port=8000) serve Starts zero-dependency HTTP server exposing REST, SSE streaming, and Web Dashboard.
Tracer() / TraceSpan trace Hierarchical latency profiler, token throughput (TPS) counter, and JSONL log exporter.
@traceable trace Function decorator automatically wrapping execution inside a named trace span.

5. Hardware & Ecosystem Tooling (termux_aichain.device)

Tool Name Execution Target Description
get_battery_status Termux-API / Sysfs Returns battery percentage, charging state, temperature, and health.
get_sensor_data Termux-API Reads real-time accelerometer, gyroscope, and ambient light sensors.
vibrate_device Termux-API Triggers haptic vibration pattern for specified duration in milliseconds.
transcribe_speech termux-stt Transcribes microphone audio or WAV files via Whisper.cpp / Vosk on-device.
generate_diffusion_image termux-diffusion Synthesizes images from text prompts using mobile device resources.
browse_web_headless termux-playwright Executes non-root headless Chromium automation and web scraping.