Deadline Remaining Before a Tool Call
Problem Statement
An agent has an overall deadline. Before each tool call, compute how much time is left, and whether there is enough to attempt a call that needs cost seconds.
Background
Given a deadline (absolute seconds), the current time now, and an estimated cost, the remaining budget is max(deadline - now, 0). A call should proceed only if remaining >= cost.
Your Task
Implement:
def deadline_check(deadline, now, cost):
Return a dict with "remaining" (float, clamped at 0) and "proceed" (bool).
Input Format
- deadline (float), now (float), cost (float).
Output Format
- A dict {"remaining": float, "proceed": bool}.
Sample
print(deadline_check(100.0, 90.0, 5.0))
Output:
{'remaining': 10.0, 'proceed': True}
Example
print(deadline_check(100.0, 90.0, 5.0))
{'remaining': 10.0, 'proceed': True}- Calculate the raw time difference between the absolute deadline and the current time to determine the theoretical budget: .
- Clamp this value at zero to ensure the remaining time is non-negative, which is necessary because negative time is not a valid budget: .
- Compare the calculated remaining time against the estimated cost of the tool call to decide if it is safe to proceed: evaluates to
True. - Combine these results into the required dictionary structure with the keys
"remaining"and"proceed". - The final output is
{'remaining': 10.0, 'proceed': True}
Constraints
remaining = max(deadline - now, 0).proceed = remaining >= cost.- Return remaining as a float.