Skip to content

feat(wasm): opt-in retry with Retry-After and USD budget via llm-wasm - #52

Open
Mattbusel wants to merge 1 commit into
raphaelmansuy:mainfrom
tensorust-ai:use-llm-wasm
Open

Mattbusel wants to merge 1 commit into
raphaelmansuy:mainfrom
tensorust-ai:use-llm-wasm

Conversation

@Mattbusel

Copy link
Copy Markdown

In the WASM SDK, call_llm_once in sdks/wasm/src/agent.rs gives up with LLM request failed with status 429 on the first rate limit, and nothing tracks spend, because the native retry and pricing code in edgecrab-core needs tokio. This PR adds two opt-in AgentOptions: maxRetries (same name as the Node SDK) retries 429 and 5xx with jittered backoff and waits for Retry-After when the server sends it, and budgetUsd stops the agent before the next LLM call once priced spend reaches the limit, with an agent.costUsd getter to read it. Both are off by default so current behaviour does not change, and models missing from the price table (Ollama, for example) are never counted or blocked. The pricing and backoff math come from llm-wasm, which has no async runtime; the wasm32 build is clean and I tested it in Node against a mock server (Retry-After honoured, 400 not retried, exhausted retries return the original error, budget blocks the next call). I maintain llm-wasm (MIT) and will keep it current.

This branch has not been deployed

No deployments
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