Putting a dollar cap on one AgentScope run #3097
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.
Multi-agent AgentScope runs can make a lot of model calls for one task, and there's no per-run dollar limit built in. Here's one way to add one without changing your agents.
OpenAIChatModelpassesclient_kwargsto the OpenAI client, so each run's model can carry its id and budget as headers to a small gateway in the same process:Give every agent in the run the same run's model and they share one budget. Each call reserves its worst-case cost before it's sent, so agents working at the same time can't overspend together. A call that doesn't fit gets a 402 before the provider (
openai.APIStatusError,status_code == 402).inferrail work <run id>shows what the run cost.Caveats: Chat Completions only, set
max_tokens, only calls through that model count. Tested withagentscope2.0.9 andinferrail0.4.10 or later (earlier versions conflicted with AgentScope'smcppin).Full setup: guide. I maintain Inferrail (open source, Apache-2.0), so take the recommendation with that in mind. Curious how others bound the cost of a single run here.
All reactions