Skip to main content
Both agent.run() and agent.stream() throw typed errors when the agent loop cannot complete normally. Wrap every agent call in a try/catch and switch on the error type to apply targeted recovery. A single generic catch (err) is a code smell - different errors require completely different responses.

Error taxonomy


MaxTurnsError

Thrown when the agent loop exceeds the maxTurns limit set in AgentOptions. Each tool call–response pair counts as a turn. When it happens: Complex tasks that require many tool calls, or tasks where the model is not converging (e.g., calling tools in a loop without making progress). Recovery: Increase maxTurns, simplify the task, or add instructions to the system prompt guiding the model to finish sooner.

MaxRetriesError

Thrown when the model fails to produce a valid response for structured output after the maximum number of retries. This most commonly occurs when outputSchema is complex and the model’s output repeatedly fails Zod validation. When it happens: The model produces JSON that is syntactically valid but fails schema validation, and after maxRetries attempts it still cannot produce a conforming response. Recovery: Simplify the outputSchema, add field descriptions to guide the model, or increase maxRetries in AgentOptions.

UsageLimitError

Thrown when a UsageLimits budget defined in AgentOptions is exceeded mid-run. This is a cost-control mechanism - the agent stops before the model can incur more spend. Fields:
The correct class name is UsageLimitError - not UsageLimitExceededError. Always import from @vibesjs/sdk and rely on TypeScript autocomplete to confirm the name.
Recovery: Increase the budget in UsageLimits, break the task into smaller subtasks, or optimize the prompt to reduce token consumption. See Results and Usage Limits for how to configure limits.

ApprovalRequiredError

Thrown when the agent encounters a tool call that has been marked as requiring human approval, and no approval has been granted yet. The error object carries the deferred tool calls so you can inspect them, prompt a human, and resume the agent. When it happens: You configured a tool with requiresApproval: true (or equivalent), the model called it, and the agent cannot proceed without explicit permission. Recovery: Inspect err.deferred.requests, display the pending calls to a human reviewer, then call agent.resume(err.deferred) to continue. For the full human-in-the-loop pattern including UI integration, see Human in the Loop.

ModelRequestsDisabledError

Thrown only in test environments when setAllowModelRequests(false) has been called to prevent accidental real API calls during tests. You will never see this in production. When it happens: A test file calls setAllowModelRequests(false) at the top, and some code path triggers a real model request instead of using TestModel. Recovery: Replace the real model with a TestModel in the affected test, or call setAllowModelRequests(true) before the code under test runs. For the full testing guide and TestModel usage, see Testing.

Provider and network errors

All other errors during a model call come from the Vercel AI SDK and pass through the agent loop unmodified. The most common are APICallError (4xx/5xx from the provider) and rate-limit errors.
Refer to the Vercel AI SDK error documentation for the full list of SDK error types.

Complete error handler

A production-ready pattern that handles all five Vibes error types plus provider errors:

ApprovalRequiredError recovery sequence

This is the most complex recovery flow because it spans two separate agent invocations. The err.deferred object carries all state needed to resume - the agent does not need to restart the conversation from scratch.