Skip to content

feat: reflexion loop token cost tracking#87

Open
bronz3beard wants to merge 3 commits into
mainfrom
fix/reflexion-cost-tracking-6043397629124719629
Open

feat: reflexion loop token cost tracking#87
bronz3beard wants to merge 3 commits into
mainfrom
fix/reflexion-cost-tracking-6043397629124719629

Conversation

@bronz3beard

Copy link
Copy Markdown
Owner

Implements genuine cost tracking in the Reflexion loop engine.

Previously, getUsage() falsely stubbed provider costs to zero across the board, bypassing any imposed budget limit. This PR:

  • Introduces src/lib/ai/reflexion/pricing.ts as the central repository for operator-maintained token rates.
  • Refactors the unified buildRunner in providers-env.ts (also utilized by providers-user.ts) to calculate cost accurately per model.
  • Defaults missing models to $0 and issues a targeted warning.
  • Ensures the budget cap correctly asserts based on these updated monetary values.
  • Retains type safety (no any) by safely inferring ambiguously typed LanguageModelUsage metrics.

PR created automatically by Jules for task 6043397629124719629 started by @bronz3beard

- Adds a centralized token pricing module (`PRICE_PER_MTOK`) with safe placeholder rates.
- Updates `buildRunner` (used across both environments) to accurately aggregate tokens into USD costs according to the defined model pricing.
- Gracefully logs warnings and ignores cost tracking for models absent from the pricing configuration.
- Adapts and expands tests to explicitly simulate cost consumption and proper budget triggering via `getUsage()`.
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel

vercel Bot commented Jul 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ai-tech-lead-stack Ready Ready Preview, Comment Jul 16, 2026 3:27pm

- Adds a centralized token pricing module (`PRICE_PER_MTOK`) with safe placeholder rates.
- Updates `buildRunner` (used across both environments) to accurately aggregate tokens into USD costs according to the defined model pricing.
- Gracefully logs warnings and ignores cost tracking for models absent from the pricing configuration.
- Adapts and expands tests to explicitly simulate cost consumption and proper budget triggering via `getUsage()`.
- Fixes evaluator calibration in scripts/reflexion-eval.ts by updating the critic model.
- Adds a centralized token pricing module (`PRICE_PER_MTOK`) with safe placeholder rates.
- Updates `buildRunner` (used across both environments) to accurately aggregate tokens into USD costs according to the defined model pricing.
- Gracefully logs warnings and ignores cost tracking for models absent from the pricing configuration.
- Adapts and expands tests to explicitly simulate cost consumption and proper budget triggering via `getUsage()`.
- Fixes evaluator calibration in scripts/reflexion-eval.ts by updating the critic model.
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