feat. Hourly Ratelimits for Triggers #4
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 JUST reply to this comment with a "hello" please.
hello
@luna make a little implementation summary and plan, markdown
Implementation Plan: Hourly Rate Limits for Triggers
To implement hourly rate limits as requested, I will modify
main.pyto track usage counts in the SHSF database and add a management route to reset these counts.1. Configuration Changes
2. Database Tracking
agent_{AGENT_USERNAME}_cooldowndb.get().db.set().3. Reset Mechanism (clear_limit route)
route == "clear_limit"then reset count to 0.4. Code Modifications
sendToAgent(event_object)to handle rate-limiting.main(args)routing logic.@luna what files would be modified?
For an hourly rate limit feature on triggers, the primary file that would need modification is main.py.
Specifically:
sendToAgent() function — Add a rate limit check before sending. Return early if the hourly quota is exhausted.
main() function — Track trigger counts per hour in the database using a key pattern like
ratelimit:hourly:{hour_timestamp}.New helper functions —
check_rate_limit()andincrement_rate_limit()to manage the hourly counter in the DB.No changes to
_db_com.py(SHSF internal) orrequirements.txtwould be needed — the database already exists and Python standard libs cover this.Would you like me to implement this?
@luna Yes go ahead and implement this in a new PR, following guidelines.and new branch ofc
Implemented hourly rate limits in PR #8.
Summary:
The agent will now skip notifications when the hourly limit is reached. Set AGENT_HOURLY to adjust the limit.