agent.run() returns a RunResult<TOutput> once the run completes. agent.stream() and agent.runStreamEvents() return a StreamResult<TOutput> immediately and resolve the final values lazily. Both carry the structured output, complete message history, new messages added in this run, and token usage.
Output modes
When you setoutputSchema, Vibes has three strategies for requesting structured output from the model:
Structured output with outputSchema
Define a Zod schema and the agent will parse the model’s response and return it as a typed value.result.output is fully typed as { answer: string; confidence: number }.
Output modes
Union types as outputSchema
Pass an array of Zod schemas to let the model choose which one applies. This is useful for agents that can return different structured shapes depending on the task.Result validators
resultValidators are post-parse validation functions that run after Vibes parses the output. Return the (optionally modified) output to accept it, or throw an error to reject it and trigger a retry.
maxRetries controls how many times the agent retries on validation failure before throwing MaxRetriesError.
RunResult interface
agent.run() resolves to a RunResult<TOutput>:
StreamResult interface
agent.stream() returns a StreamResult<TOutput> immediately. Consume the async iterables first, then await the promises.
Streaming
Real-time token and event streaming
Messages
Multi-turn conversations and message history