jaeswift-website/api/agent_tiers.py
jae e73b74cfa2 feat(agent): agentic chat with wallet auth and tiered model routing
- New /api/agent/chat endpoint with Venice tool-calling loop (max 8 iter)
- Tiered models: glm-4.7-flash default, kimi-k2-thinking for Elite+
- Wallet auth: /api/auth/{nonce,verify,whoami,logout} with Ed25519 + JWT
- 10 tools registered: site search, crypto prices, SITREP, .sol lookup,
  wallet xray, contraband/awesomelist search, changelog, trigger_effect
- Per-tool rate limits, 30s timeout, \$30/mo budget guard
- Frontend: tier badge, tool call cards, wallet sign-in handshake
- Changelog v1.40.0
2026-04-20 10:40:27 +00:00

44 lines
1.2 KiB
Python

"""Tier system for JAE-AI agent — access control + model routing."""
TIERS = ['anonymous', 'operator', 'elite', 'admin']
TIER_RANK = {name: idx for idx, name in enumerate(TIERS)}
# Admin wallets — Solana base58 pubkeys. Populate when confirmed.
ADMIN_WALLETS = [
'9NuiHnHQ9kQVj8JwPCpmE4VU1MhwcYL9gWbkiAyn8', # jaeswift.sol
]
# Model routing per tier
MODEL_ROUTING = {
'anonymous': 'zai-org-glm-4.7-flash',
'operator': 'zai-org-glm-4.7-flash',
'elite': 'kimi-k2-thinking',
'admin': 'kimi-k2-thinking',
}
def compute_tier(address: str | None, balance_sol: float = 0.0) -> str:
"""Derive tier from wallet address + SOL holdings."""
if not address:
return 'anonymous'
if address in ADMIN_WALLETS:
return 'admin'
try:
if float(balance_sol) >= 1.0:
return 'elite'
except (TypeError, ValueError):
pass
return 'operator'
def tier_rank(tier: str) -> int:
return TIER_RANK.get(tier, 0)
def tier_allows(user_tier: str, required_tier: str) -> bool:
"""True when user_tier >= required_tier in the hierarchy."""
return tier_rank(user_tier) >= tier_rank(required_tier)
def pick_model(tier: str) -> str:
return MODEL_ROUTING.get(tier, MODEL_ROUTING['anonymous'])