Android Call Agent Home
Android Call Agent · v1.1 · Setup & Operations Guide

Building a Korean AI Call & SMS System
with Rooted Samsung Android & LiveKit

Walk through every layer without a VoIP SIP trunk or a persistent USB cable: connect a SIM-enabled, rooted Samsung Android (12–14, Magisk) handset over Wi-Fi LAN to your telephony/messaging bridge, from wireless-first quick start to 24/7 Linux/LXC deployment, industry personas, external booking webhooks, and FAQs.

1Understanding the Architecture in Plain Words

Why Samsung phones over Wi-Fi solve South Korea's SIP barrier in 10 seconds.

Why This Architecture?

AI brain on your server;
real SIM lines on Wi-Fi Samsung phones.

In South Korea, obtaining a telecom SIP trunk is effectively restricted to registered business contracts — individual builders and small teams cannot easily plug Twilio or SIP voice tutorials into a Korean mobile number. Android Call Agent solves this by turning SIM-enabled rooted Samsung Android phones over Wi-Fi into live telephony bridges.

Run the AI agent brain on your server (PC, Linux, or Proxmox LXC), and place calls, answer calls, and reply to SMS/LMS/RCS over Wi-Fi through real 010 mobile numbers. No USB cable is needed during continuous operation, and callers simply dial or text a normal phone number.

Multi-Phone Setup · 1 Server + Multiple Phones

Separate --config files for independent inbound/outbound lines

Rather than a single-process multiplexer, each phone pairs 1:1 with its own flip4-call-agent --config <phone>.yaml gateway / agent process pair. For example, Phone #1 can handle office/clinic reception, Phone #2 bookings and cancellations, and Phone #3 outbound personal-assistant calls simultaneously.

5 fields separated per phone config file
# phone-a.yaml (Phone #1: reception)  |  phone-b.yaml (Phone #2: bookings)
bridge.host: "192.168.0.101"         |  bridge.host: "192.168.0.102"
gateway.port: 18780                  |  gateway.port: 18781
gateway.agent_name: "agent-phone-a"  |  gateway.agent_name: "agent-phone-b"
gateway.db_path: "data/phone-a.db"   |  gateway.db_path: "data/phone-b.db"
persona: { ...reception... }         |  persona: { ...bookings... }

# Run a 1:1 process pair per handset
uv run flip4-call-agent --config phone-a.yaml agent --mode start
uv run flip4-call-agent --config phone-a.yaml gateway
uv run flip4-call-agent --config phone-b.yaml agent --mode start
uv run flip4-call-agent --config phone-b.yaml gateway
4-stage flow diagram: Caller handset, Rooted Samsung Android 12-14 bridge, Python CallGateway, LiveKit AgentWorker and MCP Server
Caller (VoLTE · SMS/LMS/RCS) ↔ Samsung Android Bridge (:18765/:18766) ↔ Python CallGateway (127.0.0.1:18780) ↔ LiveKit AgentWorker + stdio · Streamable HTTP MCP Server (:18781/mcp, 13 tools).
Primary Network Ports
Port Protocol Direction Purpose
18765 HTTP / WebSocket (/events) Gateway → Phone /health, /call/*, /sms/*, /audio/*, live call & SMS events
18766 Framed TCP (!BI header + payload) Bidirectional 16kHz 16-bit mono PCM (20ms = 640B) real-time telephony audio
18780 HTTP (default 127.0.0.1) CLI / MCP → Gateway Local control API (/health, /calls/*, /sms/*, /policy/*)
18781 Streamable HTTP (/mcp, /healthz) Remote MCP → MCP Server Remote agent hub transport (Bearer auth + allowed_hosts; use Caddy or Cloudflare Tunnel)

2Device & SDK Prerequisites

Ensure both the Samsung handset and host build toolchain meet these versions.

2.1 Handset Requirements

2.2 Host Requirements (macOS / Linux / PC)

35-Minute Quick Start (Wireless-First, USB Optional)

Configure .env and config.yaml, deploy over Wireless Debugging (adb connect), and start the worker and gateway.

Required .env keys
LIVEKIT_URL=wss://<YOUR_PROJECT>.livekit.cloud
LIVEKIT_API_KEY=<YOUR_LIVEKIT_API_KEY>
LIVEKIT_API_SECRET=<YOUR_LIVEKIT_API_SECRET>
BRIDGE_AUTH_TOKEN=<YOUR_64HEX_TOKEN>
# Optional (initial ADB deploy only): FLIP4_ADB_SERIAL=<PHONE_WIFI_IP>:<ADB_PORT>
Env precedence: process env > repo .env > LIVEKIT_ENV_FILE (~/.config/android-call-agent/livekit.env)
First-Test Safety Rule
Never start live testing with mode: all

inbound.mode, outbound.mode, and sms.inbound_reply_mode all ship set to disabled in config.example.yaml and deploy/config.lxc.example.yaml. For wireless operation, set bridge.host to your phone's Wi-Fi IP and keep bridge.auto_adb_forward: false, then switch modes to whitelist with only your test phone number in allowlist.

Build, Wireless Deploy & Run Commands (No USB Required)
cp .env.example .env && cp config.example.yaml config.yamlCopy untracked config templates (.gitignore excludes both)
uv syncCreate .venv and install locked dependencies
adb pair <PHONE_WIFI_IP>:<PAIR_PORT> && adb connect <PHONE_WIFI_IP>:<ADB_PORT>Connect via Android 12–14 Wireless Debugging (no USB cable needed)
TOKEN="$(openssl rand -hex 32)" && adb -s <PHONE_WIFI_IP>:<ADB_PORT> shell "su -c 'printf %s \"$TOKEN\" > /data/local/tmp/flip4-bridge.token && chmod 600 /data/local/tmp/flip4-bridge.token'"Generate 64-char hex shared token and store on handset (match BRIDGE_AUTH_TOKEN in .env)
export ADB_SERIAL="<PHONE_WIFI_IP>:<ADB_PORT>" BRIDGE_BIND_HOST="<PHONE_WIFI_IP>" BRIDGE_AUTH_TOKEN_FILE="/data/local/tmp/flip4-bridge.token"Target wireless ADB and enable LAN token auth (set ANDROID_JAR / D8_BIN on custom Linux paths)
bash android-bridge/scripts/build_and_deploy.shCompile Java 11 → dex with d8 → push /data/local/tmp/flip4-bridge.dex → start root daemon on LAN with Bearer auth
uv run flip4-call-agent agent --mode startTerminal 1: start the LiveKit Voice Agent Worker
BRIDGE_AUTH_TOKEN="$TOKEN" uv run flip4-call-agent gatewayTerminal 2: start CallGateway and HTTP control API (:18780)
Optional · Local USB Loopback Testing

For quick local 127.0.0.1 loopback testing over USB without LAN auth, omit BRIDGE_BIND_HOST and BRIDGE_AUTH_TOKEN_FILE, set ADB_SERIAL=<USB_SERIAL> for build_and_deploy.sh, and run bash android-bridge/scripts/verify_bridge.sh to verify /health, /audio/probe, WS /events, and TCP CTRL_PING.

Post-Start Verification
Check /health, /sms/status, and calls

Verify curl -s -H "Authorization: Bearer $TOKEN" http://<PHONE_WIFI_IP>:18765/sms/status (or http://127.0.0.1:18765/sms/status in loopback mode) returns "ok": true, "telephony_service_manager_ready": true, "sms_max_korean_bytes": 80, "lms_max_korean_bytes": 2000, and "lms_ready": true. Place a whitelisted test call, test barge-in and end_call, then inspect uv run flip4-call-agent calls --limit 10 and --detail <call_id>.

4Customizing persona by Industry

Adapt clinics, law/tax offices, support desks, or booking shops purely in config.yaml.

The persona: section feeds both the voice assistant prompt (agent_worker.py) and the SMS auto-responder prompt (sms_responder.py) simultaneously.

Key Persona Fields

Identity, Scripts & Guardrails

Voice Pipeline Modes
voice_pipeline.mode: realtime vs pipeline
realtime (default): Single low-latency openai/gpt-realtime-2.1 + gpt-4o-mini-transcribe (ko) model.
pipeline: Modular deepgram/nova-3 or cartesia/ink-whisper STT + google/gemma-4-31b-it LLM + cartesia/sonic-3 TTS + silero VAD.
v1.1 Outbound Profiles & Guardrails

Dual organization vs personal Profiles · dry_run · Hard Blocks

5Korean Carrier SMS, LMS & RCS Internals

Engineered around Korean carrier UDH multipart issues and Samsung Chat+ providers.

SmsController.java measures outbound text using text.getBytes("EUC-KR"). Messages up to 80 bytes and 68 characters (1 part in SmsManager.divideMessage()) send via SmsManager.sendTextMessage() with automatic ISms Binder reflection fallback. Larger Korean messages (up to 2000B) skip UDH multipart SMS and instead encode a pure Java OMA-TS-MMS-ENC v1.2 M-Send.req binary PDU (MmsPduBuilder.java, UTF-8 text/plain single part), staged through content://mms/drm and sent as 1 LMS.

3-Channel Inbound Polling (3s interval, seeded at startup via seedAllProviders)
Channel Content URI bridge_sms_id Offset Notes
Standard SMS (sms) content://sms/inbox (type=1) 0 + _id Standard Android SMS inbox
Samsung Chat+ (rcs) content://im/chat (type=1) 1,000,000,000 + _id Samsung Messages RCS text messages
Long LMS / MMS (mms) content://mms/inbox (msg_box=1) 2,000,000,000 + _id Reads body from content://mms/part with up to 2 delayed retries

CallGateway deduplicates via a UNIQUE index on sms_messages.bridge_sms_id in data/calls.db. When ignore_shortcodes: true, only 10+ digit 010 mobile numbers are answered and automated messages containing [Web발신], 인증번호, OTP, 보안코드, or 본인확인 are ignored. Policy enforces max_outbound_per_hour (20), max_replies_per_sender_per_hour (5), and max_agent_sms_per_call (2).

624/7 Wireless LXC & Magisk Operation

Static DHCP lease, 64-char hex token auth, Magisk boot autostart, and systemd services.

  1. Static DHCP lease: Reserve a fixed LAN IP (e.g., 192.168.0.100) for the handset MAC in your router.
  2. Shared 64-char hex token: Generate openssl rand -hex 32 and write it via Wireless Debugging (adb connect <PHONE_WIFI_IP>:<ADB_PORT>) or optional USB to /data/local/tmp/flip4-bridge.token (chmod 600) on the phone, and set BRIDGE_AUTH_TOKEN in /etc/flip4-call-agent/env. Non-loopback binds fail closed without a non-empty token.
  3. Magisk boot autostart: Push magisk_service_flip4_bridge.sh via wireless ADB (or USB) to /data/adb/service.d/99-flip4-bridge.sh (chmod 755). Thereafter, reboots wait for sys.boot_completed=1 and wlan0 IPv4 and launch com.flip4.bridge.Main with zero USB or ADB needed.
  4. 80% charge cap: Run ADB_SERIAL=<PHONE_WIFI_IP>:<ADB_PORT> bash android-bridge/scripts/enable_battery_protect.sh (or over USB) for continuous plugged-in safety.
Linux / Proxmox LXC systemd setup
sudo useradd -r -s /usr/sbin/nologin flip4 || true
sudo mkdir -p /opt/flip4-call-agent /etc/flip4-call-agent /var/lib/flip4-call-agent
sudo chown -R flip4:flip4 /opt/flip4-call-agent /var/lib/flip4-call-agent
sudo rsync -a --exclude '.git' --exclude '.venv' ./ /opt/flip4-call-agent/
cd /opt/flip4-call-agent && sudo -u flip4 uv sync --no-dev
sudo cp deploy/config.lxc.example.yaml /etc/flip4-call-agent/config.yaml
# Set bridge.host to the phone's static IP and keep auto_adb_forward: false
# Write /etc/flip4-call-agent/livekit.env (LIVEKIT_*) and /etc/flip4-call-agent/env (BRIDGE_AUTH_TOKEN), chmod 600
sudo cp deploy/flip4-gateway.service deploy/flip4-agent.service deploy/flip4-mcp.service /etc/systemd/system/
sudo systemctl daemon-reload && sudo systemctl enable --now flip4-gateway.service flip4-agent.service
# Optional remote Streamable HTTP MCP (/mcp on :18781) behind deploy/caddy-mcp.example.caddy or Cloudflare Tunnel:
# sudo systemctl enable --now flip4-mcp.service
Phone HTTP/WS checks Authorization: Bearer <token>, TCP audio validates CTRL_AUTH (0x08), and remote MCP enforces MCP_AUTH_TOKEN + MCP_ALLOWED_HOSTS.

7Optional booking_api & admin_webhook v1.0 Contracts

JSON contracts for live availability lookup and post-call summary webhooks.

7.1 booking_api Real-Time Availability Lookup

With booking_api.enabled: true, calls to check_consultation_availability(mode="phone"|"visit", date_hint) or schedule-related SMS queries issue GET <base_url>/api/consultation/availability?mode=phone (or visit). Responses are cached for cache_ttl_sec (default 60s), zero caller PII is sent, and timeouts fall back safely to persona.booking_url.

Expected booking_api JSON response (200 OK)
{
  "mode": "phone",
  "timeZone": "Asia/Seoul",
  "from": "2026-12-07",
  "to": "2027-01-03",
  "days": {
    "2026-12-07": ["10:00", "10:30", "14:00"],
    "2026-12-08": [],
    "2026-12-09": ["11:00", "11:30", "15:00", "15:30"]
  }
}

7.2 admin_webhook (schema_version: "1.0")

Setting ADMIN_WEBHOOK_URL and ADMIN_WEBHOOK_TOKEN in .env triggers a JSON POST after each call ends. Even when disabled or failing, data/calls.db always preserves the transcript and webhook_status (pending | sent | failed | skipped).

admin_webhook POST JSON payload (schema_version "1.0")
{
  "schema_version": "1.0",
  "call_id": "in-abc123",
  "direction": "inbound",
  "caller_number": "01012345678",
  "contact_name": null,
  "started_at": "2026-12-04T13:00:00+00:00",
  "ended_at": "2026-12-04T13:01:12+00:00",
  "duration_sec": 72.0,
  "status": "completed",
  "summary_ko": "통화유형: 수신 (72.0초) | 상대방: 01012345678 | 핵심내용: ...",
  "intake_fields": {
    "caller_name": "홍길동",
    "callback_number": "01012345678",
    "consultation_type": "phone",
    "preferred_time": "오후 2시",
    "inquiry_category": "상담·예약 문의"
  },
  "follow_up_needed": true,
  "transcript": [
    {
      "speaker": "agent",
      "text": "안녕하세요, 샘플 상담센터 AI 상담 도우미입니다...",
      "created_at": "2026-12-04T13:00:02+00:00"
    }
  ]
}

8Troubleshooting FAQ (Q1–Q6)

Six real-device edge cases and how the starter handles them.

Q1

Caller number becomes masked as *********** when a call turns ACTIVE on Samsung.

One UI dumpsys shows the real number during RINGING and can mask it once answered. TelecomController.java and CallGateway._handle_active preserve the real caller number prewarmed during RINGING so whitelist, SQLite logging, and send_sms_to_caller still work. Unprewarmed masked ACTIVE calls are terminated for safety.

Q2

Long Korean texts get truncated or split inconsistently (UDH multipart SMS issue).

Korean carriers frequently drop or reorder UDH multipart SMS. Above 80B EUC-KR or 68 chars, the bridge switches automatically to 1 LMS PDU (M-Send.req). Check curl -s -H "Authorization: Bearer $TOKEN" http://<PHONE_WIFI_IP>:18765/sms/status (or http://127.0.0.1:18765/sms/status in loopback mode) for lms_ready: true, imms_binder_ready: true, and default_sms_sub_id >= 0.

Q3

build_and_deploy.sh fails inside d8 with an anonymous class error.

Recent javac + build-tools 34.0.0 d8 can hit an NPE on InnerClasses attributes in anonymous inner classes (*$1.class). Keep all Java bridge classes using explicit private static final class declarations; both build_and_deploy.sh and pytest enforce zero *$[0-9]*.class outputs.

Q4

ADB fails because multiple Android devices are attached.

Check adb devices and set export ADB_SERIAL=<YOUR_ADB_SERIAL>, or configure FLIP4_ADB_SERIAL in .env and bridge.adb_serial in config.yaml. Wireless mode (auto_adb_forward: false) connects directly to bridge.host.

Q5

Wireless LAN gateway fails to connect or gets 401 Unauthorized.

Confirm the contents of /data/local/tmp/flip4-bridge.token on the phone match BRIDGE_AUTH_TOKEN with no extra whitespace or newlines, verify auth=enabled and wlan0 bind IP in /data/local/tmp/flip4-bridge.log, and verify Wi-Fi AP Isolation is disabled for TCP ports 18765 and 18766.

Q6

Audio echo during calls or the caller cannot hear AI voice.

Check bridge.samsung_uplink_mode: "translation_tx_mute", enable bridge.mute_mic_during_call: true if needed, and tune gateway.aec_enabled: true with aec_stream_delay_ms between 80 and 140. Test non-call audio with POST http://127.0.0.1:18780/calls/test-tone ({"allow_probe_mode": true}) or GET http://<PHONE_WIFI_IP>:18765/audio/probe (or bash android-bridge/scripts/verify_bridge.sh in loopback mode).

Final Pre-Launch Checklist

Confirm end-to-end readiness

  1. Run uv run pytest -v: Verify all Python tests, Java d8 zero-anonymous-class checks, and JVM self-tests pass.
  2. Place a whitelisted test call: Verify greeting → barge-in interruption → end_call → uv run flip4-call-agent calls --detail <call_id>.
  3. Promote policy carefully: Update inbound.mode and sms.inbound_reply_mode from whitelist to all or non_contacts when ready.
Android Call Agent v1.1 · MIT License · GitHub Repository · MANUAL.md (KO) Back to Landing Page