Skip to content

Agent leaderboard: rank agents by XP, quest completions, and district unlocks #313

Description

@leocagli

Context

The gamification system now awards XP (agent.xp events), tracks district unlocks, and badges. A leaderboard ties it together — showing which agents are most active and rewarding competition.

What to implement

Route: GET /api/leaderboard

Query params: limit (default 20, max 100), metric (xp | quests | districts, default xp)

Response:

{
  "metric": "xp",
  "updatedAt": 1234567890,
  "entries": [
    { "rank": 1, "agentId": "bot-1", "xp": 1250, "questsCompleted": 8, "districtsUnlocked": 3 },
    { "rank": 2, "agentId": "bot-2", "xp": 980, "questsCompleted": 5, "districtsUnlocked": 2 }
  ]
}

Data source

  • XP: sum of all agent.xp events per agent
  • Quests: count of quest.completed events per agent
  • Districts: count of unlocked districts from district store

Caching

Leaderboard is expensive to compute — cache for 60 seconds (in-memory, same TTL pattern as other stores).

Acceptance criteria

  • GET /api/leaderboard returns top-20 by XP by default
  • metric=quests ranks by quest completions
  • limit=5 returns only top 5
  • Agents with no activity appear at the bottom (rank N), not missing
  • Unit test: 3 agents with different XP → correct rank order

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions