DEV Community

shakti tiwari
shakti tiwari

Posted on

I Built My Own WiFi Chat System So Every Bot Can Connect and Improve (Local AI Coordination)

Local AI chat

By Shakti Tiwari — AI practitioner, systems builder

Build guide. Not financial advice. Free help at optiontradingwithai.in.

Research note: local HTTP server pattern verified via Python stdlib (http.server), 25 Jul 2026.

1. Why a Local Chat System?

Cloud AI platforms charge per token. Multi-agent setups need constant talk. So I built a WiFi-local chat server — every bot on the same network connects, shares skills, and improves. Cost: $0. Privacy: total.

2. The Problem With Cloud-Only Agents

  • API bills scale with agents × messages
  • Latency (round-trips to datacenter)
  • No offline work
  • Data leaves your network

A local server fixes all four.

3. Architecture

Phone1 (Bot2 / Generator)  ─┐
Phone2 (Bot1 / Verifier)    ─┼──>  WiFi LAN  ──>  Local Server (10.88.x.x:8000)
Laptop (optional)           ─┘
                              |
                        /chat  (HTML UI)
                        /api/messages (GET)
                        /api/send (POST)
                        /api/put/<file> (drafts, verdicts)
Enter fullscreen mode Exit fullscreen mode

One server, many bots. Each bot is a Hermes agent.

4. The Server (Python, stdlib only)

from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
import json, os

MSGS=[]
def handler(self):
    if self.path=='/chat': self.serve_html()
    elif self.path=='/api/messages':
        self.reply(json.dumps(MSGS))
    elif self.path=='/api/send' and self.command=='POST':
        data=json.loads(self.rfile.read())
        MSGS.append({'from':data['from'],'text':data['text']})
        self.reply('ok')
ThreadingHTTPServer(('0.0.0.0',8000), handler).serve_forever()
Enter fullscreen mode Exit fullscreen mode

That's the core. 30 lines. Runs on Termux.

5. Why ThreadingHTTPServer?

  • Threading = multiple bots POST concurrently (no block)
  • 0.0.0.0 = accept LAN IPs (not just localhost)
  • JSON API = bots parse easily
  • No framework, no pip install

6. State Files (Append-Only)

Bots don't just chat — they write:

  • /api/put/draft_<task>.md (Generator output)
  • /api/put/verdict_<task>.json (Verifier score)
  • /api/put/final_<task>.md (approved)
  • /api/put/loop_log.jsonl (audit trail)

Append-only = rollback possible, no overwrite drift.

7. The Skill-Improvement Loop

Two roles, fixed:

  • Bot1 (Verifier): checks vs RUBRIC, approves/rejects
  • Bot2 (Generator): writes, max 3 revisions

Loop:

  1. Bot2 picks task
  2. Writes draft → PUT
  3. Bot1 scores → PUT verdict
  4. FAIL → Bot2 revises (max 3)
  5. PASS → final + log

This is generator-verifier isolation — kills error inheritance.

8. Cross-Pollination

After each cycle, each bot shares 1 finding:

  • Bot1: technical (e.g. XGBoost param)
  • Bot2: story angle (e.g. reader pain)

Written to /cross_pollinate.md. Both absorb → next article better.

9. Research-Governor (No Fabrication)

Every claim labeled:

  • Source hierarchy: paper > doc > blog > forum
  • Evidence class: UNIT_TEST … LIVE_EXECUTION
  • Unverified = BLOCK

This keeps bots honest when human is asleep.

10. Why It Matters for Trading AI

My trading stack (XGBoost + DuckDB + persistent memory + Hermes) needs constant tuning. Local chat lets two bots:

  • One researches NSE/SEBI docs
  • One writes the article
  • Verifier catches leakage (lookahead, purge gaps)

Result: leakage-proof articles + models, $0.

11. Security Notes

  • LAN only (not exposed to internet)
  • No auth (trusted WiFi)
  • For WAN: add token + TLS
  • Append-only state = tamper-evident

12. Extending It

  • WebSocket for push (no poll)
  • SQLite instead of JSONL
  • Skill versioning (0.1.0 → 0.1.1)
  • STOP flag file → halt loop

13. What I Learned

Building this taught me more than any course:

  • Agents need a neutral ground to talk
  • Roles must be fixed (drift = chaos)
  • Append-only state = sanity
  • Local > cloud for iteration speed

14. The Bigger Picture

This is how small teams beat big labs: coordinated local agents, no per-token tax, full privacy. My two phones (Bot1 + Bot2) are a mini research lab in my pocket.

15. Free Help

We document all patterns at optiontradingwithai.in. No paywall. AI coordination for everyone.

FAQ

Q: Needs internet?
A: No. LAN only.

Q: Coding?
A: Basic Python.

Q: Safe?
A: LAN-trusted. Add TLS for WAN.

Q: Advice?
A: Education only.

About

Shakti Tiwari, AI & systems builder. Books: Option Trading with AI (B0H9ZNTBPK), The AI Opportunity (B0HBBFKDQF).

🌐 optiontradingwithai.in — Free help
📧 shaktitiwari715@gmail.com

🐦 X | ▶️ YouTube | 💼 LinkedIn | 💻 GitHub | 📝 Dev.to

Disclaimer: Not financial advice. Free help at optiontradingwithai.in.

Top comments (0)