Repository navigation
Agent TARS: a hard dollar limit per headless run with model.headers #2041
domondi1
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
A single Agent TARS task can run for many steps, and in browser mode every step sends the page or a screenshot back to the model. If you run it headless from scripts or CI (
agent-tars --headless --input ...), a task that loops or wanders keeps spending until it hits a step limit, and you only see the cost on the provider dashboard.The
modelconfig already has everything needed to cap that per run:baseURLandheaders, which go straight to the OpenAI client asdefaultHeaders. Point it at an OpenAI-compatible gateway that enforces a per-run budget, and since the config is TypeScript, give every invocation its own run id.Run the gateway (it uses your provider key):
agent-tars.config.ts:Each model call reserves its worst-case cost (input plus
maxTokens) before it's sent. When the run's budget can't cover the next step, the call is refused with HTTP 402 before it reaches OpenAI, and the run ends withError: 402 budget ... would be exceededinstead of continuing. The OpenAI client doesn't retry a 402, and the headers aren't forwarded upstream. Screenshot (image_url) content is accepted, with a fixed per-image allowance in the reservation.What I tested: @agent-tars/cli 0.3.0, inferrail 0.4.12, headless mode, with a local stub upstream standing in for OpenAI. With a $1 budget the run completed and
inferrail workshowed its 2 calls. With a budget smaller than one step, the first call was refused before reaching the upstream and the CLI printed the 402 and stopped. I didn't exercise a long browser session against the real API, so reports are welcome.Caveats:
--configneeds to point at the file (it isn't picked up by that name automatically); the OpenAI provider uses chat completions, which is what the gateway serves; the model needs a price in Inferrail (gpt-4o-mini,gpt-4.1-mini,gpt-4.1built in,inferrail modelslists others, and you can add your own prices). Inserve/web UI mode the config is read once, so all sessions share the run id. That makes it a cap for the whole server process rather than per session.Setup details: guide. I maintain Inferrail (open source, Apache-2.0), so take the suggestion with that in mind.
All reactions