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
Structured Agent Output: Output.choice preview

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

External services

openai

Ready to use?

View the full interactive pattern with live preview and copy the source code.

View the pattern on desktop

Related patterns