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

A workflow script could issue an unbounded number of agent calls, including through nested workflows, allowing a runaway run to consume provider capacity indefinitely.

Workflow runs now share a hard budget of 256 agent calls across the entire nested runtime. Each call reserves a slot atomically before semaphore acquisition or provider execution, so concurrent branches cannot overshoot the limit. The next call fails with a typed call_limit error, and recorded call counts remain consistent with executed work.

Stack

Based on #120 and final in the active refinement chain above #94.

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
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: capping agent calls per workflow run.
✨ 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