Skip to main content
Glama
gingsisi

gingsisi/AgentsHive

by gingsisi
README.md
# ๐Ÿ AgentsHive

<h3 align="center">
  <b>Shared knowledge architecture for AI agents</b><br>
  <i>Breaking limits through human data acquisition.</i>
</h3>

<p align="center">
  <b>Let agents say High Five.</b><br>
  ็พค่œ‚่šๆ™บใ€‚ไธ€ๆ‹ๅณๅˆใ€‚
</p>

<p align="center">
  <a href="#-why">Why</a> ยท
  <a href="#-features">Features</a> ยท
  <a href="#-quick-start">Quick Start</a> ยท
  <a href="#-api">API</a> ยท
  <a href="#-tag-system">Tag System</a> ยท
  <a href="#-deploy">Deploy</a>
</p>

---

## ๐Ÿค” Why

AI agents can't reach everywhere. Paywalled sites, geo-blocked content, login-walled forums โ€” bots hit walls every day. But humans don't.

AgentsHive is a **human-powered knowledge mesh** for AI agents. Real people browse the web โ€” their captures flow into a shared cache. Agents query the mesh instead of burning tokens on blocked searches. **One agent finds. Every agent knows.**

| Without AgentsHive | With AgentsHive |
|---|---|
| ๐Ÿ”ฅ Burn tokens on every search | โšก Cache check โ†’ if hit, $0 |
| ๐Ÿšซ Bots blocked everywhere | ๐Ÿ‘ค Humans go where bots can't |
| ๐Ÿ” Same queries, same cost | ๐Ÿค One agent scrapes, all benefit |
| ๐Ÿ”’ Siloed per-user | ๐ŸŒ Open protocol, anyone joins |

---

## โœจ Features

| Feature | Description |
|---|---|
| ๐Ÿง  **Shared Memory** | Agents cache search results. One finds, every agent reuses. Zero duplicate tokens. |
| ๐Ÿ‘ค **Human Bridge** | Browser extension lets humans feed paywalled/geo-blocked content into the mesh. |
| ๐ŸŒ **Region Auto-Detect** | Server auto-detects geo-context from URL (TLD + subdirectory). `.co.jp` โ†’ JP, `.gov.hk` โ†’ HK. No manual tagging needed. |
| ๐Ÿ”’ **Triple PII Defense** | 3 layers: agent-side strip โ†’ user review queue โ†’ server re-scan. Emails, phones, IDs, credit cards all caught. |
| ๐Ÿท๏ธ **Smart Tag System** | 22 canonical tags, 200+ aliases (EN/ZH/JP). Gaming, health, hobby, family โ€” plus HK gov, finance, AI/ML. Cross-category minimum for quality. |
| ๐Ÿ”“ **Open Protocol** | BCP v0.1 โ€” any agent joins. Any developer builds a node. The protocol is the moat. |
| โšก **JSON Config** | Edit `references/canonical_tags.json` โ†’ git push โ†’ live. No redeploy, no downtime. mtime-based auto-reload. |

---

## ๐Ÿ—๏ธ How It Works

**Agent โ†’ Mesh โ†’ Every Agent**

```
๐Ÿค– Agent A searches "Elden Ring boss guide" โ†’ cache miss โ†’ scrapes web โ†’ contributes
๐Ÿค– Agent B searches same query โ†’ cache HIT โ†’ instant answer, 0 tokens
๐Ÿ‘ค Human sees geo-blocked Tabelog page โ†’ Human Bridge capture โ†’ mesh now has JP content
```

**Contribution Schema (20 fields, 5 groups):**

```
โ”Œโ”€ Core โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ id                  โ”‚ wr_a1b2c3d4e5f6      โ”‚
โ”‚ query               โ”‚ "Elden Ringๆ”ป็•ฅ"     โ”‚
โ”‚ content             โ”‚ "Bossๅผฑ้ปžไฟ‚..."       โ”‚
โ”‚ source_url          โ”‚ https://...          โ”‚
โ”‚ content_hash        โ”‚ SHA-256 of content   โ”‚
โ”œโ”€ Context โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ language            โ”‚ zh (auto-detect)     โ”‚
โ”‚ region              โ”‚ JP (auto-detect)     โ”‚
โ”‚ token_size          โ”‚ 1250 (estimated)     โ”‚
โ”œโ”€ Classification โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ tags                โ”‚ gaming,hobby         โ”‚
โ”‚ privacy_class       โ”‚ public               โ”‚
โ”‚ filtration_status   โ”‚ scanned/redacted     โ”‚
โ”‚ verification        โ”‚ unverifiedโ†’verified  โ”‚
โ”œโ”€ Attribution โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ contributor_id      โ”‚ usr_998877           โ”‚
โ”‚ is_human_bridged    โ”‚ true/false           โ”‚
โ”œโ”€ Lifecycle โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ created             โ”‚ Unix timestamp       โ”‚
โ”‚ expires             โ”‚ +30 days             โ”‚
โ”‚ reproductions       โ”‚ reuse count          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

---

## ๐Ÿš€ Quick Start

```bash
# Clone
git clone https://github.com/gingsisi/AgentsHive.git
cd AgentsHive

# Install
pip install -r requirements.txt

# Run (default port 15000)
python3 server.py
# โ†’ http://localhost:15000
```

```bash
# Get an API key (2-step email verification)
# Open http://localhost:15000 in your browser โ†’ sign up

# Search the mesh
curl "http://localhost:15000/search?q=disability+allowance&n=3" \
  -H "X-API-Key: bc_YOUR_KEY"

# Contribute (requires 2+ cross-category canonical tags)
curl -X POST http://localhost:15000/contribute \
  -H "X-API-Key: bc_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "HK immigration FAQ",
    "content": "Visit visa extension requires...",
    "source_url": "https://www.immd.gov.hk/eng/faq.html",
    "tags": ["immigration", "hong-kong"]
  }'

# Human Bridge capture (auto-sets is_human_bridged=true)
curl -X POST http://localhost:15000/bcp/v1/bridge-capture \
  -H "X-API-Key: bc_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query":"...","content":"...","source_url":"...","tags":["travel","food"]}'
```

---

## ๐Ÿท๏ธ Tag System

22 canonical tags across 6 categories. Every contribution needs **2+ cross-category tags**. Aliases handle the mapping โ€” use any alias, server normalizes.

| Category | Tags | Example Aliases |
|---|---|---|
| **Domain** | welfare, tax, education, medical, law, finance, policy, housing, immigration | `swd`, `cssa`, `ird`, `edb`, `asd`, `adhd`, `ๆธฏ่‚ก` |
| **Technical** | tech-dev, tech-creative, ai-ml | `godot`, `blender`, `zbrush`, `llm`, `python` |
| **Geo** | hong-kong, china, international | `hk`, `้ฆ™ๆธฏ`, `ๅคง้™ธ` |
| **Lifestyle** | travel, food, shopping, transport, lifestyle | `japan`, `jr`, `fukuoka`, `ๆ‹‰้บต`, `่ณผ็‰ฉ` |
| **Consumer** | gaming, health, hobby, family | `rpg`, `steam`, `fitness`, `anime`, `่‚ฒๅ…’`, `sen` |
| **Meta** | temporary, evergreen | `covid`, `basics` |

**Region auto-detect**: If no `region` field provided, server detects from URL:
- TLD: `.co.jp` โ†’ `JP`, `.gov.hk` โ†’ `HK`, `.co.uk` โ†’ `UK`
- Subdirectory: `/ja-jp/` โ†’ `JP`, `/en-us/` โ†’ `US`
- Fallback: `Global`

**Tag config**: Edit `references/canonical_tags.json` โ€” structured by category with aliases + decay_days. JSON is mtime-cached for zero-overhead reload.

---

## ๐Ÿ”Œ API

### Public Endpoints

| Endpoint | Description |
|---|---|
| `GET /` | Landing page (5 languages: EN/ไธญๆ–‡/ๆ—ฅๆœฌ่ชž/ํ•œ๊ตญ์–ด) |
| `GET /health` | Health check |
| `GET /stats` | Cache statistics |
| `POST /api/keys/request-verification` | Step 1: email verification |
| `POST /api/keys/generate` | Step 2: verify code โ†’ get API key |
| `GET /tos` | Terms of Service |
| `GET /privacy` | Privacy Policy |

### Authenticated (X-API-Key header)

| Endpoint | Description |
|---|---|
| `GET /search?q=...&n=3` | Semantic search the mesh |
| `POST /contribute` | Contribute a web result |
| `POST /bcp/v1/bridge-capture` | Human Bridge capture (Layer 3 PII scan) |
| `GET /api/keys/stats` | Your key's usage stats |

### Rate Limits (Beta)

| Tier | Search | Contribute | Price |
|------|--------|------------|-------|
| Free | 10,000/min | 10,000/min | $0/mo (beta) |
| Pro | Unlimited | 50/min | Coming soon |

---

## ๐ŸŒ Multi-Language

The landing page supports 5 languages with instant switching, no page reload:

- ๐Ÿ‡ฌ๐Ÿ‡ง English
- ๐Ÿ‡ญ๐Ÿ‡ฐ ็น้ซ”ไธญๆ–‡
- ๐Ÿ‡ฏ๐Ÿ‡ต ๆ—ฅๆœฌ่ชž
- ๐Ÿ‡ฐ๐Ÿ‡ท ํ•œ๊ตญ์–ด
- ๐Ÿ‡จ๐Ÿ‡ณ ็ฎ€ไฝ“ไธญๆ–‡

---

## โ˜๏ธ Deploy

```bash
# Railway (free tier)
# Just point to server.py โ€” single FastAPI app
# Procfile: web: uvicorn server:app --host 0.0.0.0 --port $PORT

# Environment variables:
#   BC_SYSTEM_KEY   โ€” system key for production
#   RESEND_API_KEY  โ€” email service (Resend)
#   PORT            โ€” server port (default 15000)

# Docker
docker build -t agenthive .
docker run -p 15000:15000 agenthive
```

---

## ๐Ÿ›ก๏ธ Privacy & Security

- All contributed content is **user-contributed and unverified**
- PII auto-stripped at 3 layers: agent โ†’ review โ†’ server re-scan
- API keys SHA-256 hashed in SQLite
- No personal data stored โ€” queries cached by content hash, not user identity
- 13 PII patterns caught: emails, phones (HK/CN/US/UK/JP/TW/SG/KR), national IDs (HKID, SSN, NIN, NRIC, RRN, CPF), IPs, API keys, credit cards, passports

---

## ๐Ÿ“ฆ Tech Stack

- **FastAPI** โ€” REST API
- **ChromaDB** โ€” Vector storage
- **SQLite** โ€” API key management
- **Sentence Transformers** โ€” Embeddings (English)
- **Ollama** โ€” Chinese embeddings (nomic-embed-text)

---

## ๐Ÿค Contributing

AgentsHive is open source under MIT License. See [CONTRIBUTING.md](CONTRIBUTING.md).

---

<p align="center">
  <b>๐Ÿ Built for agents. Contributed by humans.</b><br>
  <i>Let agents say High Five. ็พค่œ‚่šๆ™บใ€‚ไธ€ๆ‹ๅณๅˆใ€‚</i>
</p>