Skip to content

feat(workflow): cap agent calls per run - #121

Open
Waishnav wants to merge 2 commits into
pr/dw-agent-call-transactionsfrom
pr/dw-agent-call-budget
Open

feat(workflow): cap agent calls per run#121
Waishnav wants to merge 2 commits into
pr/dw-agent-call-transactionsfrom
pr/dw-agent-call-budget

Conversation

@Waishnav

@Waishnav Waishnav commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • enforce a hard budget of 256 agent calls for one workflow run
  • share the budget across nested workflows through the existing shared runtime
  • reject the next call before semaphore acquisition or provider execution
  • surface a typed call_limit workflow error
  • cover concurrent boundary allocation so parallel calls cannot overshoot the cap

Validation

  • npm test
  • npm run build

Summary by CodeRabbit

  • New Features

    • Added a maximum of 256 agent calls per workflow run.
    • Workflow runs now report a clear call-limit error when the maximum is exceeded.
  • Bug Fixes

    • Prevented agent calls beyond the configured per-run limit from executing.
    • Call counts and recorded statuses now accurately reflect the enforced limit.
  • Tests

    • Added coverage for allowed and rejected calls at the workflow limit.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3531282a-a7a1-45c5-b5ee-d21c79a0d65f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pr/dw-agent-call-budget

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 30, 2026

Copy link
Copy Markdown

Greptile Summary

This PR introduces a shared, concurrency-safe cap of 256 agent calls per workflow run.

  • Allocates each call index synchronously before semaphore acquisition and provider execution.
  • Shares the counter across nested workflows through the existing runtime object.
  • Adds call_limit to workflow error contracts and engine error typing.
  • Tests the concurrent boundary to ensure the limit cannot be exceeded.

Confidence Score: 5/5

The PR appears safe to merge with no actionable defects identified.

The shared runtime counter is checked and incremented synchronously, nested workflows reuse that runtime, overflow is rejected before provider execution, and the new typed error is accepted throughout the workflow contract and persistence paths.

Important Files Changed

Filename Overview
src/workflow-api.ts Enforces the shared agent-call limit with synchronous allocation before cache, semaphore, and provider paths.
src/workflow-contracts.ts Adds the new call-limit error kind to the validated public workflow error contract.
src/workflow-errors.ts Extends WorkflowEngineError typing so call-limit failures survive existing normalization and persistence paths.
src/workflow-engine.test.ts Verifies concurrent allocation at the boundary permits the final call and rejects overflow without provider execution.
src/workflow-types.ts Defines the fixed maximum of 256 agent calls per workflow runtime.
src/workflow-types.test.ts Locks the new workflow limit constant to its intended value.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Agent call requested] --> B{Shared call index below 256?}
    B -- No --> C[Throw call_limit]
    B -- Yes --> D[Allocate and increment index]
    D --> E[Check replay decision]
    E -- Cache hit --> F[Return cached response]
    E -- Execute --> G[Acquire shared semaphore]
    G --> H[Run provider]
    H --> I[Release semaphore]
Loading

Reviews (1): Last reviewed commit: "test(workflow): cover agent call budget ..." | Re-trigger Greptile

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