Why is rate limiting important in managing AI agent requests?
Think about what happens if too many requests come at once.
Rate limiting helps avoid system crashes by limiting how many requests can be processed in a given time.
You want to limit the total compute cost of AI agent calls over a month. Which budget control method is best?
Think about how to keep costs predictable.
Setting a fixed maximum number of calls directly controls usage and cost.
What is the output of this Python code simulating a simple rate limiter?
import time class RateLimiter: def __init__(self, max_calls, period): self.max_calls = max_calls self.period = period self.calls = [] def allow(self): current = time.time() self.calls = [call for call in self.calls if call > current - self.period] if len(self.calls) < self.max_calls: self.calls.append(current) return True return False limiter = RateLimiter(3, 5) results = [] for _ in range(5): results.append(limiter.allow()) time.sleep(1) print(results)
Consider how many calls are allowed within the 5-second window.
The limiter allows 3 calls in 5 seconds. The first 3 calls return True, the next 2 return False.
You have a budget control system that tracks 'calls_used' and 'calls_remaining'. If calls_used = 750 and calls_remaining = 250, what is the total budget and percentage used?
Add used and remaining calls to find total, then calculate percentage.
Total budget = calls_used + calls_remaining = 1000. Percentage used = (750/1000)*100 = 75%.
Given this budget control snippet, what error will occur when running it?
class BudgetControl: def __init__(self, max_calls): self.max_calls = max_calls self.calls_made = 0 def make_call(self): if self.calls_made < self.max_calls: self.calls_made += 1 return True else: return False budget = BudgetControl(3) results = [budget.make_call() for _ in range(5)] print(results) print(budget.calls_remaining)
Check if all attributes used are defined in the class.
The class does not define 'calls_remaining', so accessing it causes AttributeError.
