็น้ซไธญๆ | English
ไปฅ็ฅๆ็บๅป็ๅคๆบ่ฝ้ซ็ณป็ตฑ๏ผๅฎ่ญทๅฐๅไธญ่ฅฟๅ็ๆๅๆข็ดข่็คพๅๆฒป็ใ
A Multi-Agent System (MAS) that reimagines Tainan City's cultural heritage exploration through the metaphor of Taiwanese folk religion โ where a ๅๅฐๅ ฌ (Earth God) orchestrates 20 ๅฐๅบไธป (Street Guardians) to bid, debate, and negotiate the best travel itineraries and community insights for you.
๐ Live Demo: https://digital-earth-god.netlify.app
(Backend on Railway ยท Frontend on Netlify)
| Flow | Description | WebSocket |
|---|---|---|
| ๐งญ ๅๅๅฐๅ ฌๅ่ทฏ (Explore) | Input your travel intent + GPS โ 20 street guardians scout, bid, debate โ Earth God judges and produces a multi-day itinerary with a Leaflet map | /ws/explore/a2ui |
| ๐๏ธ ๅๅๅฐๅ ฌ (Community Ask) | Ask a community question โ guardians evaluate relevance, provide answers โ Earth God consolidates a summary | /ws/ask/a2ui |
| ๐๏ธ ้้ทๅคงๆ (Council) | Raise a community topic โ multi-round deliberation among guardians with support/oppose/question stances โ Earth God delivers a verdict | /ws/council/a2ui |
| ๐ ๅๅๅฐๅ ฌ่จฑ้ก (Wish) | Submit a prayer/wish to the Earth God | /ws/wish |
- Contract Net Protocol โ Decentralized task allocation: broadcast โ scout โ bid โ debate โ judge
- A2UI (Agent-to-UI) โ Server pushes component trees + data patches over WebSocket; the frontend renders them with a generic renderer + domain-specific decorators (seal stamps, jiaobei divination, incense backgrounds)
- 5 Agent Types โ ๅๅฐๅ ฌ (orchestrator), 20ร ๅฐๅบไธป (street guardians), ่็บ (Tiger God), ๅทกๅขไฝฟ (Patrol Officer), ไบ็ๅ ตๅฐ (Five Camps)
- 20 Autonomous Street Agents โ Each guardian has real NLSC village boundary polygons (from official ่บ็ฃๅๅๆธฌ็นชไธญๅฟ shapefiles) and pre-loaded spatial data (POIs, history, social posts) for one neighborhood in Tainan's West Central District
- Council: up to 15 participants โ Multi-round deliberation across the most relevant guardians; map stays at static overview (no per-statement zoom); compact inline transcript
- Divine Personality โ Random "mood of the day" phrases inject personality into the Earth God's judgments
- Theatrical UI โ Vermillion seal-stamp animations, jiaobei (ๆฒ็ญ) divination reveals, incense smoke backgrounds, chat-room-style scout reports, and mobile-friendly slide-out panels
- Cloud Deployed โ Backend on Railway (Docker/FastAPI), Frontend on Netlify (Next.js static export)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Frontend (Next.js) โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโ โ
โ โ Explore โ โ Ask โ โ Council โ โWish โ โ
โ โ / โ โ /ask โ โ /council โ โ/wishโ โ
โ โโโโโโฌโโโโโโ โโโโโโฌโโโโโโ โโโโโโฌโโโโโโ โโโโฌโโโ โ
โ โ WS โ WS โ WS โ WS โ
โโโโโโโโโผโโโโโโโโโโโโโโผโโโโโโโโโโโโโโผโโโโโโโโโโโโโผโโโโโ
โผ โผ โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ FastAPI Gateway (:8080) โ
โ apps/api/gateway.py โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ ๅๅฐๅ
ฌ Pipeline (ADK) โ โ
โ โ โโโโโโโโโโโโโ โ โ
โ โ โRouterAgentโ โ Top N agents โ โ
โ โ โโโโโโโโโโโโโ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โParallelAgent (Scout ร20) โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โParallelAgent (Bid รN) โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โParallelAgent (Debate รN)โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โLlmAgent (Judge) โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ
โผ โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Swarm Server (:9000) โ
โ โโโโโโโโ โโโโโโโโ โโโโโโโโ โโโโโโโโ โ
โ โ็ฅ่พฒ่กโ โๆตทๅฎ่ทฏโ โๆญฃ่่กโ โฆ โๅ
ฑ20้โ โ
โ โ:9001 โ โ:9002 โ โ:9003 โ โ โ โ
โ โโโโโโโโ โโโโโโโโ โโโโโโโโ โโโโโโโโ โ
โ (A2A JSON-RPC endpoints) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
| Layer | Technology |
|---|---|
| LLM | Google Gemini 3.1 Flash Lite |
| Agent Framework | Google ADK (Agent Development Kit) |
| Agent Communication | A2A Protocol (Agent-to-Agent) |
| Backend | FastAPI + WebSocket ยท deployed on Railway (Docker) |
| Frontend | Next.js 16 (Turbopack) + Motion (Framer Motion) + Leaflet ยท deployed on Netlify (static export) |
| Boundary Data | Official NLSC shapefiles (ๅๅๆธฌ็นชไธญๅฟ) โ real village polygon coordinates |
| Data | NGSI-LD inspired 5-layer model (spatial, dynamic, historical, citizen opinions, metadata) |
digital-earth-god/
โโโ agents/
โ โโโ tudigong/ # ๅๅฐๅ
ฌ (Earth God) โ orchestrator, judge, council chair, blessing
โ โ โโโ agent.py # Contract Net pipeline, mood pool, community/council judge
โ โ โโโ blessing_agent.py# Wish blessing agent
โ โโโ dijizhu/ # ๅฐๅบไธป (Street Guardians) โ 20 per-street agents
โ โ โโโ agent.py # Scout, bidding, debate, community, council speaker agents
โ โ โโโ a2a_server.py # A2A HTTP server (per street)
โ โ โโโ swarm_server.py # Launch all 20 A2A servers in parallel
โ โโโ huye/ # ่็บ (Tiger God) โ mock evidence adapter, A2A server
โ โโโ wuying/ # ไบ็ๅ
ตๅฐ (Five Camps) โ intent + wish categorizer agents
โ โโโ xunjingshi/ # ๅทกๅขไฝฟ (Patrol Officer) โ mock evidence adapter, A2A server
โ
โโโ apps/
โ โโโ api/
โ โ โโโ gateway.py # FastAPI gateway โ 4 WS endpoints, pipeline orchestration
โ โโโ web/ # Next.js 16 frontend
โ โโโ app/
โ โ โโโ page.tsx # Explore (ๅๅๅฐๅ
ฌๅ่ทฏ)
โ โ โโโ ask/page.tsx # Community Ask (ๅๅๅฐๅ
ฌ)
โ โ โโโ council/page.tsx # Council (้้ทๅคงๆ)
โ โ โโโ wish/page.tsx # Wish (่จฑ้ก)
โ โ โโโ dashboard/page.tsx # Dashboard (ๅๅธ้ขจๅ็)
โ โโโ components/
โ โ โโโ theater/ # SealStamp, Jiaobei, IncenseBackground
โ โ โโโ NegotiationBoard.tsx # Compact bid/debate viewer with pagination
โ โ โโโ ChatBubble.tsx # Scout chat-room bubbles
โ โ โโโ CouncilMap.tsx # Reactive ้ boundary map (Leaflet, SSR-safe wrapper)
โ โ โโโ ResultMap.tsx # Leaflet itinerary map
โ โโโ lib/a2ui/ # Generic A2UI renderer
โ โโโ Renderer.tsx
โ
โโโ deg/ # Core library (pip install -e .)
โ โโโ schemas/
โ โ โโโ contracts.py # Pydantic models (TaskBroadcast โ CouncilVerdict)
โ โโโ a2ui/
โ โ โโโ __init__.py # A2UI protocol (state, patches, builder)
โ โ โโโ surfaces.py # Component tree builders per flow (explore/ask/council/wish)
โ โโโ adapters/ # Sensor + social data adapters (่็บ/ๅทกๅขไฝฟ evidence)
โ โโโ warmdata/ # SQLite wish store (deg/warmdata/store.py)
โ โโโ mcp/spatial_db/ # MCP spatial database for POI queries
โ โโโ seed/loader.py # Load 5-layer NGSI-LD agent data from JSON
โ
โโโ dijizu_agent/ # 20 li JSON data files (5-layer NGSI-LD per neighborhood)
โ โโโ ไบๆขๆธฏ้.json # โฆ (20 files total)
โ โโโ โฆ
โ
โโโ data/seed/
โ โโโ streets.json # Street / POI seed data
โ โโโ sensor.json # Sensor readings seed data
โ โโโ social.json # Social / citizen opinion seed data
โ
โโโ tests/ # 80+ unit tests (integration tests skip without API key)
โโโ docs/ # Design documents & feature plans
โโโ scripts/demo.py # CLI demo script
โโโ start.ps1 # One-click startup script (Windows)
โโโ pyproject.toml # Python project config
โโโ .env.example # Environment variable template
- Python โฅ 3.11
- Node.js โฅ 20
- Google Gemini API Key (Get one here)
git clone https://github.com/bcshih/digital_earth_god.git
cd digital_earth_god
# Python dependencies
python -m venv .venv
.venv\Scripts\activate # Windows
# source .venv/bin/activate # macOS/Linux
pip install -e ".[dev]"
# Frontend dependencies
cd apps/web
npm install
cd ../..cp .env.example .env
# Edit .env and add your Gemini API key:
# GOOGLE_API_KEY=your-gemini-api-key-hereOption A: One-click (Windows PowerShell)
.\start.ps1This will start the Swarm Server, FastAPI Gateway, and Next.js frontend, then open your browser.
Option B: Manual (3 terminals)
# Terminal 1 โ Swarm Server (20 ๅฐๅบไธป A2A agents)
python agents/dijizhu/swarm_server.py
# Terminal 2 โ FastAPI Gateway
uvicorn apps.api.gateway:app --host 127.0.0.1 --port 8080 --reload
# Terminal 3 โ Next.js Frontend
cd apps/web && npm run devNavigate to http://localhost:3000 and start exploring Tainan!
- You type a travel intent (e.g., "ๆๆณๆพ่ๅททๅผ่ฃก็ๆ้ๅๅกๅปณ") and share your GPS location
- ๅๅฐๅ
ฌ broadcasts a
TaskBroadcastto all 20 street guardians - 20 Scouts quickly evaluate relevance (0-10 confidence score) โ results stream in real-time as chat bubbles
- Top N Guardians are selected and submit full
BiddingProposalwith POIs, fitness scores, and reasoning - Debate Round โ Guardians critique each other's proposals and defend their streets
- ๅๅฐๅ
ฌ Judge โ The Earth God reads all bids + debates, applies today's divine mood, and produces a
JudgmentResultwith a curated multi-day itinerary - ๆฒ็ญ (Jiaobei) โ The verdict is revealed with a divination animation, followed by an interactive Leaflet map
- Ask a community question (e.g., "ๆ่ฟไธญ่ฅฟๅๆไป้บผๆดปๅ๏ผ")
- Scouts evaluate which neighborhoods have relevant data
- Selected guardians provide detailed answers from their local data
- Earth God consolidates all answers into a unified summary
- Raise a topic for discussion (e.g., "ๆตทๅฎ่ทฏ็ไบค้ๆนๅ")
- Up to 15 most relevant guardians join; up to 3 deliberation rounds
- Each guardian picks a stance (support / oppose / question / inform / silent) and speaks in โค 40 characters โ compact statements stream in real-time
- The council map highlights the speaking boundary in gold; stance colors update as the debate unfolds; response lines connect who is replying to whom
- Earth God delivers a final verdict summarizing consensus and disagreements
# Run all tests
pytest
# Run specific test files
pytest tests/test_schemas.py
pytest tests/test_gateway.pyNote: Gateway tests require
google-adkto be installed. Schema tests run independently.
The project includes a visual Agent Editor to easily manage and edit the JSON-LD NGSI-LD files of the 20 street guardians.
- Run the local backend:
python scripts/agent_editor.py - Open your browser to http://localhost:8081
- Select any neighborhood from the left sidebar to edit the agent's persona, boundaries, and add infinite "Local Observations". Changes are saved directly to the local files.
The system uses a standard JSON-LD graph structure based on NGSI-LD. Each neighborhood contains a dataset with multiple entities:
- VillageAgent: The core entity representing the neighborhood. Contains metadata (personality, name), spatial boundaries (GeoJSON polygons), and historical context.
- LocalObservation: Granular data points representing events, locations, or citizen feedback within the neighborhood. These are dynamically loaded into the agent's 5-layer knowledge base:
daily_activity,weather,new_shopโ Layer 2 (Dynamic Activities)poi,local_historyโ Layer 3 (Spatial & POIs)citizen_feedbackโ Layer 4 (Citizen Opinions)
Note: To prevent LLM context overflow during parallel execution, the data loader (
deg/seed/loader.py) intelligently truncates observations to the Top 15 most relevant entities per agent.
TaskBroadcastโ Intent + GPS + constraints broadcast to all agentsScoutResultโ Quick confidence score (0-10) + one-line reasonBiddingProposalโ Full proposal with candidate POIs, fitness score, reasoningDebateMessageโ Inter-agent debate textJudgmentResultโ Final itinerary withItineraryStop[], recommendation, reasoningCommunityAnswer/CommunityQueryResultโ Community Q&A modelsCouncilStatement/CouncilAlignment/CouncilVerdictโ Council deliberation models (stance: support/oppose/question/inform/silent)
The Agent-to-UI (A2UI) protocol decouples the agent pipeline from the frontend:
- Server pushes a component tree (JSON) defining the UI structure
- Server pushes data model patches as agent results arrive
- Frontend renders the tree with a generic
Renderercomponent - Decorators layer domain-specific presentation (animations, maps) on top
This allows the same agent pipeline to power different frontends (web, mobile, voice) without changing agent code.
| Variable | Description | Default |
|---|---|---|
GOOGLE_API_KEY |
Google Gemini API key | (required) |
GOOGLE_GENAI_USE_VERTEXAI |
Use Vertex AI instead of AI Studio | FALSE |
NEXT_PUBLIC_GATEWAY_WS |
WebSocket URL for frontend | ws://127.0.0.1:8080/ws/explore/a2ui |
This project is part of an academic research initiative on multi-agent systems for smart city applications.
๐ฏ ๅฐๅใปไธญ่ฅฟๅใปๆธไฝๅๅฐๅ
ฌ ๐ฏ
Built with Google ADK ยท A2A Protocol ยท Gemini ยท Next.js