Skip to content

feat(plugin-knowledge): add configurable rate limits for high-through…#49

Merged
0xbbjoker merged 1 commit into1.xfrom
feat/knowledge-configurable-rate-limits
Dec 24, 2025
Merged

feat(plugin-knowledge): add configurable rate limits for high-through…#49
0xbbjoker merged 1 commit into1.xfrom
feat/knowledge-configurable-rate-limits

Conversation

@0xbbjoker
Copy link
Copy Markdown

@0xbbjoker 0xbbjoker commented Dec 24, 2025

  • Add RATE_LIMIT_ENABLED option to completely disable rate limiting
  • Add configurable settings: MAX_CONCURRENT_REQUESTS, REQUESTS_PER_MINUTE,
    TOKENS_PER_MINUTE, BATCH_DELAY_MS
  • Increase default limits 5x for high-throughput APIs (Vercel gateway):
    • MAX_CONCURRENT_REQUESTS: 30 → 150
    • REQUESTS_PER_MINUTE: 60 → 300
    • TOKENS_PER_MINUTE: 150k → 750k
    • BATCH_DELAY_MS: 500ms → 100ms
  • Remove provider-specific rate caps to respect user configuration
  • Fix TypeScript type errors in service.ts and document-processor.ts

Set RATE_LIMIT_ENABLED=false and BATCH_DELAY_MS=0 for maximum throughput
with APIs that don't have rate limits.


Note

Enables high-throughput and configurable ingestion with explicit rate control and an option to disable limits entirely.

  • Adds RATE_LIMIT_ENABLED, MAX_CONCURRENT_REQUESTS, REQUESTS_PER_MINUTE, TOKENS_PER_MINUTE, BATCH_DELAY_MS to config/types; increases defaults and wires through getProviderRateLimits, document-processor, and batching logic
  • Removes provider-specific rate caps; honors user-configured values and supports "unlimited" mode (no RPM/TPM caps, optional 0ms batch delay)
  • Improves setting parsing (e.g., CTX_KNOWLEDGE_ENABLED, KNOWLEDGE_PATH) and fixes TypeScript types/usages in service.ts and document-processor.ts
  • Minor behavior tweak: combines system+prompt when caching via runtime.useModel
  • Bumps package version and updates deps (notably @elizaos/core^1.7.0)

Written by Cursor Bugbot for commit fdceddb. This will update automatically on new commits. Configure here.

Summary by CodeRabbit

  • New Features

    • Rate limiting is now configurable, including enable/disable toggle, maximum concurrent requests, per-minute request limits, and token rate limits.
    • Added batch processing delay configuration for request timing control.
  • Chores

    • Upgraded @elizaos/core dependency to version 1.7.0.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 24, 2025

Walkthrough

Version bump from 1.5.15 to 1.5.16 with dependency upgrade. Configuration fields for rate limiting and batch delay are added to model config validation. Rate limit handling now reads from config instead of per-provider hardcoded values. Document processor receives rate limit settings to control concurrent requests, request throttling, and batch delays.

Changes

Cohort / File(s) Summary
Dependency & Version
package.json
Version bumped 1.5.15 → 1.5.16; @elizaos/core upgraded ^1.6.4 → ^1.7.0
Configuration Schema
src/types.ts
Added rate-limiting fields (RATE_LIMIT_ENABLED, MAX_CONCURRENT_REQUESTS, REQUESTS_PER_MINUTE, TOKENS_PER_MINUTE, BATCH_DELAY_MS) to ModelConfigSchema and ProviderRateLimits interface with string-or-number coercion and defaults
Config Validation & Defaults
src/config.ts
Rate-limiting config now validated and defaults applied; getProviderRateLimits reads from config instead of per-provider hardcoding; returns unlimited profile when rate limiting disabled; expanded logging for batch delay and rate-limit status
Document Processing & Batching
src/document-processor.ts
Rate limiter accepts rateLimitEnabled flag for unlimited mode; CONCURRENCY_LIMIT derived from providerLimits; batchDelayMs parameterized (default 500ms) and threaded through batch functions; conditional batch delay logic and rate-limiting logging; safer string coercion for CTX_KNOWLEDGE_ENABLED; enhanced embedding error handling
Service Runtime Handling
src/service.ts
Safer type handling for KNOWLEDGE_PATH retrieval: fetch as knowledgePathSetting, derive knowledgePath as string or undefined before passing to loadDocsFromPath

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A bunny hops with config in hand,
Rate limits dance where batches stand,
No more hardcoding provider walls—
Delays and speeds now answer calls!
Hop faster, slower—we control the way,
Configurability saves the day! 🚀

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding configurable rate limits to the plugin-knowledge package.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/knowledge-configurable-rate-limits

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
package.json (1)

197-217: Inconsistent defaults: agentConfig.pluginParameters does not match new schema defaults.

The PR increases defaults 5× for high-throughput APIs, but agentConfig.pluginParameters still shows the old values:

  • MAX_CONCURRENT_REQUESTS: 30 here vs 150 in schema
  • REQUESTS_PER_MINUTE: 60 here vs 300 in schema
  • TOKENS_PER_MINUTE: 150000 here vs 750000 in schema

Additionally, the new RATE_LIMIT_ENABLED and BATCH_DELAY_MS parameters are missing from agentConfig.

🔎 Proposed fix
       "MAX_CONCURRENT_REQUESTS": {
         "type": "number",
         "description": "Upper bound on concurrent API requests for rate limiting.",
         "required": false,
-        "default": 30,
+        "default": 150,
         "sensitive": false
       },
       "REQUESTS_PER_MINUTE": {
         "type": "number",
         "description": "Maximum number of API requests allowed per minute.",
         "required": false,
-        "default": 60,
+        "default": 300,
         "sensitive": false
       },
       "TOKENS_PER_MINUTE": {
         "type": "number",
         "description": "Maximum number of tokens that can be processed per minute.",
         "required": false,
-        "default": 150000,
+        "default": 750000,
+        "sensitive": false
+      },
+      "RATE_LIMIT_ENABLED": {
+        "type": "boolean",
+        "description": "Enables or disables rate limiting. Set to false for maximum throughput with APIs that don't impose rate limits.",
+        "required": false,
+        "default": true,
+        "sensitive": false
+      },
+      "BATCH_DELAY_MS": {
+        "type": "number",
+        "description": "Delay between batches in milliseconds. Set to 0 for no delay.",
+        "required": false,
+        "default": 100,
         "sensitive": false
       },
🧹 Nitpick comments (1)
src/document-processor.ts (1)

364-378: Default value inconsistency: batchDelayMs default is 500ms here but 100ms in config.

The function parameter default of 500 conflicts with the schema default of 100 (line 87 in types.ts). Since batchDelayMs is always passed from the caller at line 182, this default is effectively dead code, but it could cause confusion if the code path changes.

🔎 Proposed fix
-  batchDelayMs = 500,
+  batchDelayMs = 100,
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between ad2e154 and fdceddb.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • package.json
  • src/config.ts
  • src/document-processor.ts
  • src/service.ts
  • src/types.ts
🧰 Additional context used
🧬 Code graph analysis (2)
src/config.ts (1)
src/types.ts (1)
  • ProviderRateLimits (95-108)
src/document-processor.ts (2)
src/config.ts (1)
  • getProviderRateLimits (198-239)
src/llm.ts (1)
  • getProviderRateLimits (12-12)
🪛 Biome (2.1.2)
src/document-processor.ts

[error] 706-706: This hook is being called conditionally, but all hooks must be called in the exact same order in every component render.

For React to preserve state between calls, hooks needs to be called unconditionally and always in the same order.
See https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level

(lint/correctness/useHookAtTopLevel)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Cursor Bugbot
🔇 Additional comments (12)
src/types.ts (3)

54-88: LGTM: Rate limiting schema additions are well-structured.

The new rate limiting configuration fields follow the existing pattern for string-or-number transforms with sensible high-throughput defaults. The inline comments provide clear documentation for users.


104-107: LGTM: ProviderRateLimits interface extended correctly.

The new rateLimitEnabled and batchDelayMs fields are properly typed and documented. This aligns with the return type updates in getProviderRateLimits.


201-206: LGTM: KnowledgeConfig interface extended for rate limiting.

The optional rate limiting fields are correctly typed and consistent with the schema definitions.

src/service.ts (1)

65-66: LGTM: Type-safe handling of KNOWLEDGE_PATH setting.

The two-step approach correctly validates that the setting is a string before passing to loadDocsFromPath, preventing potential type errors from misconfigured settings.

src/config.ts (3)

91-98: LGTM: Rate limiting configuration parsing.

The new rate limiting settings are properly integrated into the config validation with appropriate string defaults that will be parsed by the schema transforms.


211-223: Clarify: maxConcurrentRequests is still enforced in "unlimited" mode.

When rateLimitEnabled=false, requestsPerMinute and tokensPerMinute are set to MAX_SAFE_INTEGER, but maxConcurrentRequests retains its configured value (default 150). This means concurrency is still bounded even in "unlimited throughput mode."

If this is intentional (to prevent overwhelming the system with too many parallel requests), the log message and documentation should clarify this. If truly unlimited is desired, consider also setting maxConcurrentRequests to a very high value.


229-238: LGTM: User-configured rate limits are respected.

The removal of provider-specific caps allows users to configure rate limits appropriate for their gateway/API setup (e.g., Vercel gateway with higher limits).

src/document-processor.ts (5)

44-47: LGTM: Defensive handling of non-string settings.

The conversion of settingValue to string before comparison handles cases where the runtime might return non-string types, ensuring consistent boolean parsing.


150-166: LGTM: Rate limiting initialization with clear logging.

The logging clearly distinguishes between unlimited mode and rate-limited mode, providing useful debugging information including concurrency limits, RPM, TPM, and batch delay.


474-478: LGTM: Conditional batch delay respects BATCH_DELAY_MS=0 configuration.

The batchDelayMs > 0 check correctly skips the delay when users set BATCH_DELAY_MS=0 for maximum throughput.


701-707: Static analysis false positive: runtime.useModel is not a React hook.

The Biome linter incorrectly flagged runtime.useModel as a React hook being called conditionally. This is a method call on the runtime object, not a React hook (useState, useEffect, etc.). The conditional logic here is correct and intentional.


919-932: LGTM: Efficient early return when rate limiting is disabled.

The rate limiter correctly short-circuits when rateLimitEnabled=false, avoiding unnecessary timestamp tracking and calculations in unlimited mode.

Comment thread package.json
"@ai-sdk/google": "^2.0.14",
"@ai-sdk/openai": "^2.0.32",
"@elizaos/core": "^1.6.4",
"@elizaos/core": "^1.7.0",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# Search for ProviderRateLimits usage in the codebase
rg "ProviderRateLimits" --type ts --type js -n

Repository: elizaos-plugins/plugin-knowledge

Length of output: 775


🏁 Script executed:

# Look for any breaking change documentation or changelog references
fd -e md | xargs grep -l "@elizaos/core" 2>/dev/null | head -5

Repository: elizaos-plugins/plugin-knowledge

Length of output: 58


🏁 Script executed:

# Check the actual diff context to see what changed in package.json
git diff package.json | head -50

Repository: elizaos-plugins/plugin-knowledge

Length of output: 58


🌐 Web query:

@elizaos/core v1.7.0 changelog breaking changes release notes

💡 Result:

I can't find a published @elizaos/core v1.7.0 release or changelog. The package on npm shows latest published v1.5.7. [1] The elizaOS GitHub releases page lists up through v1.6.5 (alpha) tags but no v1.7.0 release. [2]

If you want, I can:

  • search commit/compare logs for changes planned for v1.7.0 (if in a branch or tag), or
  • watch the repo and notify when v1.7.0 is released.

Sources:
[1] npm: @elizaos/core package page.
[2] GitHub: elizaOS/eliza Releases.


🏁 Script executed:

cat package.json | grep -A 2 -B 2 "@elizaos/core"

Repository: elizaos-plugins/plugin-knowledge

Length of output: 257


🏁 Script executed:

# Check git log to see if there's context about this change
git log --oneline -n 20 -- package.json

Repository: elizaos-plugins/plugin-knowledge

Length of output: 164


🌐 Web query:

@elizaos/core npm package version history latest

💡 Result:

Latest published version: 1.5.8 (published ~7 hours ago). [1][2]

Sources:

  • npm package page showing v1.5.8 as current (last publish ~7 hours ago). [1]
  • Ecosyste.ms registry summary for @elizaos/core (last synced ~1 hour ago). [2]

@elizaos/core v1.7.0 does not exist in npm—version should be updated.

The specified version ^1.7.0 is not a published release. The latest available version is v1.5.8. This will cause npm install to fail. Update the version to an available release (e.g., ^1.5.8) or confirm if v1.7.0 is a pre-release or internal version that should be used instead.

🤖 Prompt for AI Agents
In package.json around line 33, the dependency "@elizaos/core": "^1.7.0"
references a non-published version; update the version to a published release
(for example "^1.5.8") or the correct available tag, then run npm install to
verify; if v1.7.0 is an internal/pre-release, replace the entry with the proper
registry URL or tag and document the dependency choice in the PR.

Comment thread src/types.ts
.string()
.or(z.number())
.optional()
.transform((val) => (val ? (typeof val === 'string' ? parseInt(val, 10) : val) : 100)),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Schema transform incorrectly handles numeric zero for batch delay

The BATCH_DELAY_MS schema transform uses val ? ... : 100 which treats the number 0 as falsy, incorrectly converting it to 100. The comment on line 82 explicitly states "set to 0 for no delay" and the schema accepts numbers via .or(z.number()), but passing the number 0 directly would return 100 instead of 0. While environment variable usage (string "0") works correctly since non-empty strings are truthy, direct programmatic use with the number 0 would fail silently. The fix would be to use val !== undefined && val !== null && val !== '' instead of the truthy check.

Fix in Cursor Fix in Web

@0xbbjoker 0xbbjoker merged commit 21c25a4 into 1.x Dec 24, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant