-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement multi-project support -- engine orchestration (#242) #1153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a585d1f
e720759
a0aedf6
9e1a639
07683dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| BUDGET_DOWNGRADE_APPLIED, | ||
| BUDGET_DOWNGRADE_SKIPPED, | ||
| BUDGET_HARD_STOP_TRIGGERED, | ||
| BUDGET_PROJECT_BUDGET_EXCEEDED, | ||
| BUDGET_TASK_LIMIT_HIT, | ||
| BUDGET_TIER_PRESERVED, | ||
| ) | ||
|
|
@@ -256,6 +257,9 @@ def _build_checker_closure( # noqa: PLR0913 | |
| daily_baseline: float, | ||
| thresholds: _AlertThresholds, | ||
| agent_id: str, | ||
| project_budget: float = 0.0, | ||
| project_baseline: float = 0.0, | ||
| project_id: str | None = None, | ||
| ) -> BudgetChecker: | ||
| """Build the sync budget checker closure. | ||
|
|
||
|
|
@@ -267,6 +271,10 @@ def _build_checker_closure( # noqa: PLR0913 | |
| daily_baseline: Pre-computed daily spend at task start. | ||
| thresholds: Pre-computed alert thresholds. | ||
| agent_id: Agent identifier for logging. | ||
| project_budget: Total project budget (0 = disabled). | ||
| project_baseline: Pre-computed project spend at task start. | ||
| project_id: Project identifier for logging (None when | ||
| project budget is disabled). | ||
|
|
||
| Returns: | ||
| Sync callable returning ``True`` when budget is exhausted. | ||
|
|
@@ -277,6 +285,13 @@ def _check(ctx: AgentContext) -> bool: | |
| running_cost = ctx.accumulated_cost.cost_usd | ||
| return ( | ||
| _check_task_limit(running_cost, task_limit, agent_id) | ||
| or _check_project_limit( | ||
| running_cost, | ||
| project_budget, | ||
| project_baseline, | ||
| agent_id, | ||
| project_id, | ||
| ) | ||
| or _check_monthly_limit( | ||
| running_cost, | ||
| monthly_budget, | ||
|
|
@@ -378,3 +393,29 @@ def _check_daily_limit( | |
| ) | ||
| return True | ||
| return False | ||
|
|
||
|
|
||
| def _check_project_limit( | ||
| running_cost: float, | ||
| project_budget: float, | ||
| project_baseline: float, | ||
| agent_id: str, | ||
| project_id: str | None = None, | ||
| ) -> bool: | ||
| """Return True if project budget is exhausted.""" | ||
| if project_budget <= 0: | ||
| return False | ||
| total_project = round( | ||
| project_baseline + running_cost, | ||
| BUDGET_ROUNDING_PRECISION, | ||
| ) | ||
| if total_project >= project_budget: | ||
| logger.warning( | ||
| BUDGET_PROJECT_BUDGET_EXCEEDED, | ||
| agent_id=agent_id, | ||
| project_id=project_id, | ||
| total_project=total_project, | ||
| project_budget=project_budget, | ||
| ) | ||
| return True | ||
|
Comment on lines
+398
to
+420
|
||
| return False | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Project budget checks miss concurrent spend.
running_costhere is the current execution'sctx.accumulated_cost.cost_usd, so each closure only sees its own in-flight spend. If two agents run in the same project concurrently, both can reuse the sameproject_baselinesnapshot and stay underproject_budgetindividually while the combined project total overshoots it. That makes this a best-effort per-execution stop, not a true project-wide in-flight limit.Please compare against a shared project accumulator/live tracker instead of
project_baseline + local running_cost.Also applies to: 397-420
🤖 Prompt for AI Agents