Agent( )





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


Problems solved
- Return structured arrays from ToolLoopAgent with Output.array
- Validate each array element against a Zod object schema
- Combine list-shaped outputs with tool-calling agents
Use cases
- Multi-location aggregation agents
- Checklist generators with typed items
- Batch recommendation responses
- API agents that must return object lists
AI SDK APIs
ToolLoopAgentOutput.arrayagent.generatetool
Tags
aiagentsstructured-outputstool-loop-agentoutput-arrayai-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.choice
Demonstrate structured agent outputs using ToolLoopAgent with Output.choice. Constrain agent outputs to predefined choices 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 β



