v9.1.1
Menu

Timeout Budget Split Across Sequential Steps

mediumPROReliability & Failure HandlingAI AgentsAI Agents 1

Problem Statement

An agent plan runs steps sequentially under one overall timeout. Assign each step a per-step timeout proportional to its expected cost, but never below a floor, and report whether the plan fits.

Background

Given a total budget and per-step expected costs costs, the naive split gives step i a share budget * costs[i] / sum(costs). To avoid starving cheap steps, each allocation is raised to at least floor seconds. Because flooring can push the sum over budget, the plan is feasible only if sum(max(share_i, floor)) <= budget. Report each allocation (rounded to 4 decimals) and feasibility.

Your Task

def split_timeout(costs, budget, floor):

Return a dict {"allocations": [...], "feasible": bool}, allocations rounded to 4 decimals.

Input Format

  • costs (list of positive floats), budget (float), floor (float).

Output Format

  • A dict with "allocations" (list of floats) and "feasible" (bool).

Sample

print(split_timeout([1.0, 3.0], 8.0, 0.5))

Output:

{'allocations': [2.0, 6.0], 'feasible': True}

Example

Input
print(split_timeout([1.0, 3.0], 8.0, 0.5))
Output
{'allocations': [2.0, 6.0], 'feasible': True}
Reasoning
  • Calculate the total expected cost to determine proportional weights: total=1.0+3.0=4.0\text{total} = 1.0 + 3.0 = 4.0.
  • Compute the raw proportional share for each step using the formula sharei=budget×costitotal\text{share}_i = \text{budget} \times \frac{\text{cost}_i}{\text{total}}:
    • Step 1: 8.0×1.04.0=2.08.0 \times \frac{1.0}{4.0} = 2.0
    • Step 2: 8.0×3.04.0=6.08.0 \times \frac{3.0}{4.0} = 6.0
  • Apply the minimum floor constraint by taking the maximum of the raw share and the floor value (0.50.5):
    • Step 1: max⁡(2.0,0.5)=2.0\max(2.0, 0.5) = 2.0
    • Step 2: max⁡(6.0,0.5)=6.0\max(6.0, 0.5) = 6.0
  • Check feasibility by summing the final allocations and comparing to the budget: 2.0+6.0=8.02.0 + 6.0 = 8.0, which is ≤8.0\le 8.0, so the plan is feasible.
  • The final output is {'allocations': [2.0, 6.0], 'feasible': True}

Constraints

  • Share is budget * costs[i] / sum(costs), then raised to floor.
  • feasible is sum(allocations) <= budget (use a small tolerance).
  • Round allocations to 4 decimals; costs is non-empty with positive sum.

Learn this in

More from AI Agents 1

PRO

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test results

Sign in to run your code against the test cases.