feat. Hourly Ratelimits for Triggers #4

Closed
opened 2026-04-04 14:50:52 +02:00 by space · 8 comments
Owner

Hourly ratelimits for triggering the agent would be nice to see. env variable AGENT_HOURLY (default 60 times per hour). So default 60, so the agent can be triggered only 60 times per hour. And we'll keep track of that using the SHSF built-in Database using db.get and db.set with the key being "agent_{agentusername}_cooldown" (incase multiple agent functions use the same SHSF databse). In the db we'll keep track of the current hours usage and we add a route that is called "clear_limit" that i will add a trigger to run hourly so that we dont need to keep track of timestamps.

Hourly ratelimits for triggering the agent would be nice to see. env variable AGENT_HOURLY (default 60 times per hour). So default 60, so the agent can be triggered only 60 times per hour. And we'll keep track of that using the SHSF built-in Database using db.get and db.set with the key being "agent_{agentusername}_cooldown" (incase multiple agent functions use the same SHSF databse). In the db we'll keep track of the current hours usage and we add a route that is called "clear_limit" that i will add a trigger to run hourly so that we dont need to keep track of timestamps.
luna was assigned by space 2026-04-04 15:07:19 +02:00
luna was unassigned by space 2026-04-04 15:13:07 +02:00
Author
Owner

@luna JUST reply to this comment with a "hello" please.

@luna JUST reply to this comment with a "hello" please.
Collaborator

hello

hello
Author
Owner

@luna make a little implementation summary and plan, markdown

@luna make a little implementation summary and plan, markdown
Collaborator

Implementation Plan: Hourly Rate Limits for Triggers

To implement hourly rate limits as requested, I will modify main.py to track usage counts in the SHSF database and add a management route to reset these counts.

1. Configuration Changes

  • AGENT_HOURLY env (default: 60).

2. Database Tracking

  • Key: agent_{AGENT_USERNAME}_cooldown
  • Before processing:
    1. Get count via db.get().
    2. If count >= limit, log and skip.
    3. Else, increment and db.set().

3. Reset Mechanism (clear_limit route)

  • If route == "clear_limit" then reset count to 0.

4. Code Modifications

  • Update sendToAgent(event_object) to handle rate-limiting.
  • Update main(args) routing logic.
### Implementation Plan: Hourly Rate Limits for Triggers To implement hourly rate limits as requested, I will modify `main.py` to track usage counts in the SHSF database and add a management route to reset these counts. #### 1. Configuration Changes - AGENT_HOURLY env (default: 60). #### 2. Database Tracking - Key: `agent_{AGENT_USERNAME}_cooldown` - Before processing: 1. Get count via `db.get()`. 2. If count >= limit, log and skip. 3. Else, increment and `db.set()`. #### 3. Reset Mechanism (clear_limit route) - If `route == "clear_limit" ` then reset count to 0. #### 4. Code Modifications - Update `sendToAgent(event_object)` to handle rate-limiting. - Update `main(args)` routing logic.
Author
Owner

@luna what files would be modified?

@luna what files would be modified?
Collaborator

For an hourly rate limit feature on triggers, the primary file that would need modification is main.py.

Specifically:

  1. sendToAgent() function — Add a rate limit check before sending. Return early if the hourly quota is exhausted.

  2. main() function — Track trigger counts per hour in the database using a key pattern like ratelimit:hourly:{hour_timestamp}.

  3. New helper functionscheck_rate_limit() and increment_rate_limit() to manage the hourly counter in the DB.

No changes to _db_com.py (SHSF internal) or requirements.txt would be needed — the database already exists and Python standard libs cover this.

Would you like me to implement this?

For an hourly rate limit feature on triggers, the primary file that would need modification is **main.py**. Specifically: 1. **sendToAgent() function** — Add a rate limit check before sending. Return early if the hourly quota is exhausted. 2. **main() function** — Track trigger counts per hour in the database using a key pattern like `ratelimit:hourly:{hour_timestamp}`. 3. **New helper functions** — `check_rate_limit()` and `increment_rate_limit()` to manage the hourly counter in the DB. No changes to `_db_com.py` (SHSF internal) or `requirements.txt` would be needed — the database already exists and Python standard libs cover this. Would you like me to implement this?
Author
Owner

@luna Yes go ahead and implement this in a new PR, following guidelines.and new branch ofc

@luna Yes go ahead and implement this in a new PR, following guidelines.and new branch ofc
Collaborator

Implemented hourly rate limits in PR #8.

Summary:

  • Added AGENT_HOURLY env var (default: 60 triggers/hour)
  • Uses database key agent_{AGENT_USERNAME}_cooldown for tracking
  • Added clear_limit route to reset the counter (hook this up to an hourly SHSF trigger)

The agent will now skip notifications when the hourly limit is reached. Set AGENT_HOURLY to adjust the limit.

Implemented hourly rate limits in PR #8. Summary: - Added AGENT_HOURLY env var (default: 60 triggers/hour) - Uses database key agent_{AGENT_USERNAME}_cooldown for tracking - Added clear_limit route to reset the counter (hook this up to an hourly SHSF trigger) The agent will now skip notifications when the hourly limit is reached. Set AGENT_HOURLY to adjust the limit.
space closed this issue 2026-04-04 17:25:03 +02:00
Sign in to join this conversation.
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: space/assign-me-openclaw#4