Skip to content

fix(agent): pass through billing attribution to tools#5698

Merged
icecrasher321 merged 4 commits into
stagingfrom
staging-v3
Jul 15, 2026
Merged

fix(agent): pass through billing attribution to tools#5698
icecrasher321 merged 4 commits into
stagingfrom
staging-v3

Conversation

@icecrasher321

Copy link
Copy Markdown
Collaborator

Summary

Pass through billing attribution to agent tools.

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@icecrasher321 icecrasher321 requested a review from a team as a code owner July 15, 2026 23:19
@vercel

vercel Bot commented Jul 15, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 15, 2026 11:35pm

Request Review

@cursor

cursor Bot commented Jul 15, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes billing attribution validation and propagation on internal provider and tool paths; incorrect handling could mis-bill or reject legitimate nested tool calls, but behavior is strict (400) rather than silent drops.

Overview
Fixes agent LLM nested tool calls (e.g. knowledge search) losing the upstream billing decision by threading billingAttribution from execution metadata through the agent handler into executeProviderRequest, and from there into each tool’s _context via prepareToolExecution (including when only attribution is present, without a workflowId).

POST /api/providers now optionally reads x-sim-billing-attribution: it requires workspaceId in the body to validate the header against the authenticated user, returns 400 on mismatch or invalid attribution (never silently ignored), and forwards the parsed snapshot into executeProviderRequest.

Adds billingAttribution on ProviderRequest and coverage in route, agent-handler, and provider utils tests.

Reviewed by Cursor Bugbot for commit a124182. Configure here.

@greptile-apps

greptile-apps Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR passes billing attribution from provider requests into nested agent tools. The main changes are:

  • Validates attribution headers against the authenticated user and workspace.
  • Adds attribution to provider request types and agent execution.
  • Includes attribution in tool execution context.
  • Updates dependency resolutions in the Bun lockfile.

Confidence Score: 4/5

Provider requests without a workflow ID can lose billing attribution before nested tool execution.

  • The route validates and forwards the billing snapshot correctly.
  • Agent execution passes the snapshot into provider requests.
  • Tool context remains gated only by workflowId, so valid attribution can be silently omitted.

apps/sim/providers/utils.ts

Important Files Changed

Filename Overview
apps/sim/app/api/providers/route.ts Validates an incoming billing snapshot and passes it to provider execution.
apps/sim/executor/handlers/agent/agent-handler.ts Copies billing attribution from execution metadata into the provider request.
apps/sim/providers/types.ts Adds an optional billing-attribution snapshot to ProviderRequest.
apps/sim/providers/utils.ts Adds attribution to tool context, but the surrounding workflow-ID gate can omit it.
bun.lock Changes Lucide dependency resolutions across the root and several workspaces.

Reviews (1): Last reviewed commit: "fix(agent): pass through billing attribu..." | Re-trigger Greptile

Comment thread apps/sim/providers/utils.ts
@icecrasher321

Copy link
Copy Markdown
Collaborator Author

bugbot run

Comment thread apps/sim/app/api/providers/route.ts Outdated
Comment thread apps/sim/app/api/providers/route.ts Outdated
@icecrasher321

Copy link
Copy Markdown
Collaborator Author

bugbot run

@icecrasher321 icecrasher321 merged commit 3498b24 into staging Jul 15, 2026
12 checks passed

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit a124182. Configure here.

@waleedlatif1 waleedlatif1 deleted the staging-v3 branch July 16, 2026 02:24
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