Structured Agent Output: Output.array
Demonstrate structured agent outputs using ToolLoopAgent with Output.array. Returns structured array output with element schema for predictable, type-safe responses.
View Full Pattern on Desktop

Problems Solved
- Generate structured array outputs with element schemas
- Ensure type-safe agent responses
- Create predictable agent outputs
- Integrate structured outputs with tool-calling agents
Use Cases
- Multi-location data aggregation with structured arrays
- Form validation and structured data collection
- API responses with guaranteed formats
- Type-safe agent workflows
AI SDK APIs
Tags
Requirements
- Node.js
- 18+
- Memory
- 512MB
- Other
- OpenAI API key
Environment Variables
OPENAI_API_KEYGet key →
External Services
Ready to use?
View the full interactive pattern with live preview and copy the source code.
View PatternView Pattern on DesktopRelated Patterns


Structured Agent Output: Output.choice
Demonstrate structured agent outputs using ToolLoopAgent with Output.choice. Constrain agent outputs to predefined choices for predictable, type-safe responses.


Tool Input Lifecycle Hooks
Explore tool input lifecycle hooks: onInputStart, onInputDelta, and onInputAvailable. See how to track tool input generation in real-time during streaming.


Preliminary Tool Results
Return preliminary tool results using async iterables. Stream status updates during tool execution before the final result is available.


Tool API Context
Pass arbitrary context from generateText/streamText to tool execution via experimental_context. Access context in tool execute functions for dynamic behavior.