Pattern
INT·Nov 25
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.
View Full Pattern on Desktop

Problems Solved
- Constrain agent outputs to predefined choices
- Ensure type-safe agent responses
- Create predictable agent outputs
- Integrate structured outputs with tool-calling agents
Use Cases
- Clothing recommendation systems with constrained choices
- Form validation and structured data collection
- API responses with guaranteed formats
- Type-safe agent workflows
AI SDK APIs
ToolLoopAgentOutput.choiceagent.generatetool
Tags
aiagentsstructured-outputstool-loop-agentoutput-choiceai-sdkagent-api
Requirements
- Node.js
- 24+
- Memory
- 512MB
- Other
- OpenAI API key
Environment Variables
OPENAI_API_KEYGet key →
External Services
openai
Ready to use?
View the full interactive pattern with live preview and copy the source code.
View Pattern on DesktopRelated Patterns


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.
aiagents+5
View →


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.
aitools+7
View →
End of Pattern



