Agent( )





Pattern
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.
IntermediateNov 2025View the full pattern on desktop


Problems solved
- Constrain ToolLoopAgent output to Output.choice options
- Return predictable enum-like agent answers
- Combine constrained outputs with tool-calling agents
Use cases
- Recommendation agents with fixed option sets
- Triage bots that must pick from known labels
- Form-like agent decisions
- Guaranteed-format agent API responses
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 the 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 pattern β


Loop Control: stopWhen
Demonstrate ToolLoopAgent loop control with stopWhen. Covers stepCountIs, hasToolCall, combined conditions, and a custom StopCondition with step timeline visualization.
aiagents+7
View pattern β



