Communitygithub.com

curiositech/windags-skills

使用 Token Bucket、Sliding Window 和 Redis 進行 API 速率限制,以保護 API 免受濫用與 DDoS 攻擊。

windags-skills 是什麼?

此技能專注於實作公平且高效的 API 速率限制,支援 Token Bucket、Sliding Window Log、Sliding Window Counter 與 Fixed Window 等多種演算法,並可搭配 Redis 7.4+、Valkey 或 DragonflyDB 等分散式儲存後端。開發者可以依據 API Key、IP 或使用者層級定義不同的請求限制,並透過 Lua 腳本或原子性操作確保計數一致性。技能提供完整的架構模式,包括多層級速率限制(依使用者層級與端點分流)以及符合 IETF 草案標準的回應標頭(RateLimit-Limit、RateLimit-Remaining、Retry-After)。它不僅適用於 Node.js 生態(如 rate-limiter-flexible、express-rate-limit),也支援 Kong、Nginx 與 Traefik 等閘道外掛,是實作 API 保護與配額管理的必備工具。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/curiositech/windags-skills/tree/HEAD/skills/api-rate-limiting-throttling-expert

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

API 速率限制專家

使用 Token Bucket、Sliding Window 與 Fixed Window 演算法,搭配 Redis 分散式計數器,實作公平且高效的速率限制。

啟用觸發條件

啟用於:「速率限制」、「節流」、「Token Bucket」、「Sliding Window」、「API 濫用」、「DDoS 防護」、「配額管理」、「429 Too Many Requests」、「請求限制」

不適用於: API 閘道器設定 → api-gateway-reverse-proxy-expert | 快取策略 → cache-strategy-invalidation-expert | WAF/防火牆規則 → 相關安全技能

快速起步

  1. 定義限制 — 根據 API Key、IP 或用戶層級設定每分鐘請求數
  2. 選擇演算法 — Sliding Window Log(精確)、Token Bucket(允許突發)、Fixed Window(簡單)
  3. 使用 Redis — 使用 MULTI/EXEC 或 Lua 腳本進行原子操作,實現分散式速率限制
  4. 回傳正確標頭 — X-RateLimit-Limit、X-RateLimit-Remaining、Retry-After
  5. 區分層級 — 免費版/專業版/企業版擁有不同限制

核心能力

領域技術
演算法Token Bucket、Sliding Window Log、Sliding Window Counter、Fixed Window
儲存Redis 7.4+、Valkey、DragonflyDB、記憶體內(單節點)
函式庫rate-limiter-flexible、@upstash/ratelimit、express-rate-limit
閘道器外掛Kong rate-limiting、Nginx limit_req、Traefik ratelimit
標準RFC 6585(429)、RateLimit 標頭(draft-ietf-httpapi-ratelimit)

架構模式

Sliding Window Counter(Redis Lua)

-- Redis Lua 腳本:Sliding Window 速率限制
-- KEYS[1] = 速率限制鍵
-- ARGV[1] = 視窗大小(秒)
-- ARGV[2] = 最大請求數
-- ARGV[3] = 目前時間戳

local key = KEYS[1]
local window = tonumber(ARGV[1])
local limit = tonumber(ARGV[2])
local now = tonumber(ARGV[3])

-- 移除已過期的項目
redis.call('ZREMRANGEBYSCORE', key, 0, now - window)

-- 計算目前視窗內的數量
local count = redis.call('ZCARD', key)

if count < limit then
  redis.call('ZADD', key, now, now .. '-' .. math.random(1000000))
  redis.call('EXPIRE', key, window)
  return {1, limit - count - 1}  -- 允許,剩餘次數
else
  return {0, 0}  -- 拒絕,剩餘 0 次
end

多層級速率限制

請求 → IP 速率限制(100/分鐘)
              │ 通過
              ↓
         驗證檢查 → API Key 速率限制(依層級)
              │           免費版:60/分鐘
              │           專業版:600/分鐘
              │           企業版:6000/分鐘
              ↓ 通過
         端點速率限制(依路由)
              │   POST /upload:10/分鐘
              │   GET /search:120/分鐘
              ↓ 通過
         處理請求

回應標頭(IETF 草案標準)

// 中介軟體:附加速率限制標頭
function rateLimitHeaders(limit: number, remaining: number, resetAt: number) {
  return {
    'RateLimit-Limit': limit.toString(),
    'RateLimit-Remaining': Math.max(0, remaining).toString(),
    'RateLimit-Reset': Math.ceil((resetAt - Date.now()) / 1000).toString(),
  };
}

// 在 429 回應時:
res.status(429).set({
  ...rateLimitHeaders(limit, 0, resetAt),
  'Retry-After': Math.ceil((resetAt - Date.now()) / 1000).toString(),
}).json({ error: 'Too Many Requests', retryAfter: resetAt });

反模式

  1. 在分散式系統中使用記憶體內計數器 — 速率限制必須跨實例共享;請使用 Redis 或同等解決方案
  2. 缺少 Retry-After 標頭 — 未附帶 Retry-After 的 429 回應會迫使客戶端猜測,導致驚群效應
  3. 僅基於 IP 的速率限制 — 僅 IP 限制會遺漏已驗證的濫用行為,並懲罰共享 IP(NAT、VPN);應與 API Key 限制結合
  4. 無突發能力的硬性截止 — Token Bucket 可在維持平均速率的同時允許小突發;純 Fixed Window 過於僵化
  5. 未對內部 API 設定限制 — 行為異常的內部服務可能導致資料庫連鎖故障;務必加以限制

品質檢查清單

  • 速率限制使用分散式儲存(Redis/Valkey),而非記憶體內
  • 每個回應都附帶 RateLimit-Limit、RateLimit-Remaining、RateLimit-Reset 標頭
  • 429 回應附帶 Retry-After 標頭
  • 根據驗證層級(免費/專業/企業)設定不同的限制
  • 對昂貴操作(上傳、搜尋)設定每個端點的限制
  • 使用 Lua 腳本或原子性管線進行計數器遞增(無競爭條件)
  • 速率限制鍵包含身分(API Key)和作用域(端點)
  • 監控儀表板顯示速率限制命中次數、拒絕次數與最高使用量
  • 優雅降級:在可能的情況下,優先佇列或減速,而非直接拒絕

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

curiositech/windags-skills

Expert in 2000s-era music visualization (Milkdrop, AVS, Geiss) and modern WebGL implementations. Specializes in Butterchurn integration, Web Audio API AnalyserNode FFT data, GLSL shaders for audio-reactive visuals, and psychedelic generative art. Activate on "Milkdrop", "music visualization", "WebGL visualizer", "Butterchurn", "audio reactive", "FFT visualization", "spectrum analyzer". NOT for simple bar charts/waveforms (use basic canvas), video editing, or non-audio visuals.

curiositech/windags-skills

Expert legal research agent for finding and scraping expungement data state by state. Knows authoritative sources, URL patterns, Firecrawl configuration, and 2026 legal landscape.

curiositech/windags-skills

Expert in 3D computer vision labeling tools, workflows, and AI-assisted annotation for LiDAR, point clouds, and sensor fusion. Covers SAM4D/Point-SAM, human-in-the-loop architectures, and vertical-specific training strategies. Activate on '3D labeling', 'point cloud annotation', 'LiDAR labeling', 'SAM 3D', 'SAM4D', 'sensor fusion annotation', '3D bounding box', 'semantic segmentation point cloud'. NOT for 2D image labeling (use clip-aware-embeddings), general ML training (use ml-engineer), video annotation without 3D (use computer-vision-pipeline), or VLM prompt engineering (use prompt-engineer).

curiositech/windags-skills

Implement WCAG 2.2 AA/AAA compliance with automated testing, keyboard navigation, screen reader support, and focus management. Activate on: accessibility audit, WCAG compliance, keyboard navigation, screen reader, aria attributes, axe-core, focus trap. NOT for: design-level accessibility review (use design-accessibility-auditor), color contrast only (use css-in-js-architect).

curiositech/windags-skills

Time-blind friendly planning, executive function support, and daily structure for ADHD brains. Specializes in realistic time estimation, dopamine-aware task design, and building systems that actually work for neurodivergent minds.

curiositech/windags-skills

Designs digital experiences for ADHD brains using neuroscience research and UX principles. Expert in reducing cognitive load, time blindness solutions, dopamine-driven engagement, and compassionate design patterns. Activate on 'ADHD design', 'cognitive load', 'accessibility', 'neurodivergent UX', 'time blindness', 'dopamine-driven', 'executive function'. NOT for general accessibility (WCAG only), neurotypical UX design, or simple UI styling without ADHD context.

curiositech/windags-skills

>- Apply crisis decision-making research to agent routing, uncertainty triage, and coordination failure analysis in time-pressured systems. Use when diagnosing handoff failures, analytical paralysis, or expert judgment under incomplete information. NOT for routine coding, simple CRUD design, or static single-agent tasks with complete information.

curiositech/windags-skills

Extend and modify the admin dashboard, developer portal, and operations console. Use when adding new admin tabs, metrics, monitoring features, or internal tools. Activates for dashboard development, analytics, user management, and internal tooling.

curiositech/windags-skills

Conversation patterns and interaction protocols for multi-agent systems. Covers request/response, pub/sub, blackboard, delegation chains, debate, critique, consensus, fan-out/fan-in, supervisor-worker, and peer negotiation. Deep analysis of AutoGen conversation patterns, CrewAI delegation, LangGraph state passing, and FIPA-ACL performatives. Teaches how to design what agents say to each other and in what order. Activate on: "agent conversation", "agent protocol", "multi-agent debate", "agent delegation", "supervisor worker pattern", "agent voting", "consensus protocol", "fan-out fan-in", "agent negotiation", "blackboard pattern", "agent dialogue", "conversation topology", "agent handoff". NOT for: wire format or serialization (use agent-interchange-formats), orchestration infrastructure (use agentic-infrastructure-2026), single agent behavior (use agentic-patterns).

curiositech/windags-skills

Meta-agent for creating new custom agents, skills, and MCP integrations. Expert in agent design, MCP development, skill architecture, and rapid prototyping. Activate on 'create agent', 'new skill', 'MCP server', 'custom tool', 'agent design'. NOT for using existing agents (invoke them directly), general coding (use language-specific skills), or infrastructure setup (use deployment-engineer).

curiositech/windags-skills

AI-powered calendar management and agent-based scheduling coordination. Covers calendar APIs (Google Calendar, CalDAV/iCal), AI scheduling assistants (Reclaim, Clockwise, Motion, Cal.com), building custom calendar agents with MCP, multi-calendar merging, timezone management, focus block protection, meeting fatigue detection, and agent-to-agent meeting negotiation protocols. Activate on: "calendar agent", "AI scheduling", "calendar coordination", "meeting scheduling", "calendar API", "focus time protection", "calendar optimization", "Google Calendar MCP", "Reclaim", "Clockwise", "Motion", "Cal.com", "smart scheduling", "calendar-aware agent", "timezone scheduling", "agent negotiation meetings". NOT for: manual calendar UI component design (use form-validation-architect), project management scheduling or Gantt charts (use project-management-guru-adhd), general time-tracking or pomodoro apps (use adhd-daily-planner for time-awareness), building the agent itself from scratch (use agent-creator).

curiositech/windags-skills

Build and adopt production AI agent infrastructure in 2026. Covers framework selection (LangGraph, CrewAI, AutoGen, MCP), orchestration patterns, evaluation, observability, memory systems, and tool use. Also covers the SOCIAL dimension: how to sell agent infrastructure internally, change management, measuring ROI, building trust in autonomous systems, and scaling adoption across teams. Activate on: "agent infrastructure", "agent framework comparison", "which agent framework", "sell AI tools internally", "agent adoption", "agent observability", "agent evaluation", "MCP architecture", "agentic mesh", "enterprise AI agents", "AI change management", "agent ROI". NOT for: building specific agents (use ai-engineer), designing agent behavior patterns (use agentic-patterns), prompt tuning (use prompt-engineer).

curiositech/windags-skills

Fundamental patterns for effective agentic behavior. Teaches decomposition, tool orchestration, error recovery, context management, quality self-assessment, and knowing when to stop. Model-agnostic principles that make any agent more effective regardless of domain. Activate on: "how should I structure this agent", "agentic workflow", "agent patterns", "multi-step task", "tool orchestration", "/agentic-patterns", "decompose this", "agent best practices", "chain of actions", "when should the agent stop", "agent loop design". NOT for: creating agent infrastructure (use agent-creator), building DAGs (use windags-architect), specific tool implementation.

curiositech/windags-skills

Automated discovery and matching of agent skills for dynamic task routing and capability assessment

curiositech/windags-skills

Cryptographic security for agentic systems — zero-trust agent networking, signed message envelopes (JWS/JWE), capability-based security (ocaps), Merkle tree audit trails, WASM sandboxing, and formal verification. Covers CLI dev tool security, mTLS between agents, permission boundaries (least privilege for AI agents), and supply chain security for skills/plugins. Activate on: "agent security", "zero trust agents", "secure agent communication", "capability-based security", "ocap", "signed messages between agents", "agent audit trail", "sandbox agent execution", "agent permissions", "mTLS agents", "cryptographic verification", "agent supply chain", "OWASP agentic", "prove agent did X", "tamper-proof agent logs". NOT for: application-level SAST scanning (use security-auditor), network firewall rules (use infrastructure), SOC2/HIPAA compliance (organizational), or prompt injection defense (use prompt-engineer).

curiositech/windags-skills

Data structures and serialization formats for agent-to-agent communication. Covers message envelopes, structured output schemas, capability declarations, task handoff payloads, error/retry signaling, and context windows as data structures. Deep comparison of A2A protocol, MCP, OpenAI function calling, and LangChain message types. Teaches when to use rigid schemas vs free-form with validation, typed vs untyped, streaming vs batch. Activate on: "agent message format", "agent communication schema", "agent-to-agent protocol", "A2A protocol", "MCP message format", "structured output for agents", "agent interop", "interchange format", "agent serialization", "task handoff format", "capability declaration". NOT for: what agents say to each other (use agent-conversation-protocols), orchestration topology (use multi-agent-coordination), building agent infrastructure (use agentic-infrastructure-2026).

curiositech/windags-skills

Logic-based agent programming language implementing BDI architecture for practical autonomous agent development

curiositech/windags-skills

>- Design AgentSpeak(L)-style BDI agents with context-guarded plans, selection functions, and intention stacks. Use for interruptible autonomy, agent policy, and multi-agent orchestration in dynamic environments. NOT for simple rule engines, static planners, or centralized workflows.

curiositech/windags-skills

Foundational concurrent computation model where actors communicate exclusively through asynchronous message passing

curiositech/windags-skills

license: Apache-2.0 NOT for unrelated tasks outside this domain.

相關技能