Agent class is the primary way you build an AI agent in Vibes. It wraps the Vercel AI SDK’s generateText / streamText loop, manages multi-turn tool execution, injects dependencies, and validates structured output - all in a single cohesive interface.
An agent is typed over its dependencies (TDeps) and output (TOutput), making it fully type-safe end to end.
Agent loop
Every call toagent.run(), agent.stream(), or agent.runStreamEvents() goes through the same loop:
Basic usage
Type parameters
Agent<TDeps, TOutput> accepts two type parameters:
TDeps- the shape of the dependencies object injected at run time. Defaults toundefined(no deps).TOutput- the output type. Defaults tostring. Specify this when usingoutputSchemafor structured output.
systemPrompt is a function, it receives the full RunContext<TDeps> on every turn, giving it access to the injected deps, current usage, run ID, and more.
Constructor options
All options are passed tonew Agent(opts: AgentOptions<TDeps, TOutput>).
| Field | Type | Default | Description |
|---|---|---|---|
model | LanguageModel | required | Vercel AI SDK model instance (e.g. anthropic("claude-sonnet-4-6")) |
name | string? | - | Human-readable agent name |
systemPrompt | string | (ctx) => string | - | Base system prompt, static or dynamic |
instructions | string | (ctx) => string | - | Per-run additions appended after systemPrompt. Not recorded in result.messages |
tools | ToolDefinition<TDeps>[] | [] | Static tools always available to the model |
toolsets | Toolset<TDeps>[] | [] | Dynamic per-turn tool groups |
outputSchema | ZodType | ZodType[] | - | Zod schema for structured output |
outputMode | 'tool' | 'native' | 'prompted' | 'tool' | How structured output is requested |
outputTemplate | boolean | true | Whether to inject the schema into the system prompt |
resultValidators | ResultValidator<TDeps, TOutput>[] | [] | Post-parse validators - throw to reject and retry |
maxRetries | number | 3 | Max validation retries before MaxRetriesError |
maxTurns | number | 10 | Max tool-call round trips before MaxTurnsError |
usageLimits | UsageLimits? | - | Cap cumulative token or request usage |
historyProcessors | HistoryProcessor<TDeps>[] | [] | Per-turn message transforms (trim, summarize, filter) |
modelSettings | ModelSettings? | - | Temperature, maxTokens, topP, and other model parameters |
endStrategy | 'early' | 'exhaustive' | 'early' | When to stop after receiving final_result |
maxConcurrency | number? | unlimited | Max concurrent tool executions per turn |
telemetry | TelemetrySettings? | - | OpenTelemetry settings passed to the AI SDK |
Running an agent
Vibes provides three run methods depending on how you want to consume the output:StreamResult interface and event kinds, and Results for the RunResult API.
agent.override()
agent.override(overrides) returns a scoped runner that substitutes specific options for a single run(), stream(), or runStreamEvents() call. The original agent is never mutated.
AgentOptions: model, systemPrompt, instructions, tools, toolsets, resultValidators, maxRetries, maxTurns, usageLimits, historyProcessors, modelSettings, endStrategy, telemetry.
Tip: Use
agent.override() in tests to swap in a TestModel without modifying your production agent. Override runs also bypass the setAllowModelRequests(false) guard, so they work in any test environment.