Skip to content

feat: adds ability to optimize for cost#172

Open
andrewklatzke wants to merge 2 commits intoaklatzke/AIC-2263/sdk-dx-improvementsfrom
aklatzke/AIC-2465/cost-optimization
Open

feat: adds ability to optimize for cost#172
andrewklatzke wants to merge 2 commits intoaklatzke/AIC-2263/sdk-dx-improvementsfrom
aklatzke/AIC-2465/cost-optimization

Conversation

@andrewklatzke
Copy link
Copy Markdown
Contributor

@andrewklatzke andrewklatzke commented May 6, 2026

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Describe the solution you've provided

Implements cost optimization in the same manner as latency optimization. Searches the acceptance statement for keywords pertaining to token usage/cost (e.g. costs, pricing, bill) and adds instructions to the variation generation to try to optimize for costs. Additionally has the acceptance statement prompt return instructions for the variation generation (ie, cheaper model, etc).

Describe alternatives you've considered

This is a feature addition.

Additional context

We'll be adding UI options for both latency and cost with adjustable thresholds, but these are still valid once those arrive since a mention of cost/latency means the user is trying to optimize for it.


Note

Medium Risk
Adds new cost estimation and pass/fail gating that can change optimization outcomes and variation generation behavior; relies on model pricing metadata being present/accurate and introduces new tolerance thresholds.

Overview
Adds cost optimization alongside existing latency optimization by detecting cost-related keywords in acceptance statements and injecting cost-focused guidance into judge instructions and variation-generation prompts.

Tracks per-iteration estimated_cost_usd (computed from token usage + model pricing) in OptimizationContext, surfaces it in prompt feedback, and adds a _evaluate_cost gate (default 20% improvement vs baseline) that is applied in normal runs, validation, and ground-truth mode when cost optimization is implied.

Also tightens a few behaviors: treats token_limit=0 as “no limit”, prefetches/stores model configs for pricing lookup, and limits placeholder-restoration to the active variable set while downgrading related logs from warning to debug.

Reviewed by Cursor Bugbot for commit dc82818. Bugbot is set up for automated code reviews on this repo. Configure here.

@andrewklatzke andrewklatzke requested a review from a team as a code owner May 6, 2026 23:10
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 94de596. Configure here.

Comment thread packages/optimization/src/ldai_optimizer/client.py
Comment thread packages/optimization/src/ldai_optimizer/prompts.py
Comment thread packages/optimization/src/ldai_optimizer/prompts.py
@andrewklatzke andrewklatzke requested a review from jsonbailey May 7, 2026 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant