PatternsAgent Patterns

HIL Inquire Multiple Choice

Loading pattern preview

Loading preview…

Problems solved

Technical challenges this implementation handles out of the box.
  • Pause the agent to ask structured multiple-choice questions
  • Resume ToolLoopAgent after the user selects an answer
  • Collect brand or preference context through guided choices
  • Stop the loop on the inquire tool with hasToolCall

Use cases

Products and workflows this pattern is designed to support.
  • Brand intake questionnaires
  • Onboarding surveys inside an agent
  • Preference gathering for recommendations
  • Customer research chats with constrained answers

Setup

Requirements, wiring steps, and what this pattern adds to your project.

Getting started

Pick how you want to pull this pattern in — then wire env vars and routes the same way.

  1. 1

    Install from the preview toolbar

    Shadcn Icon

    Copy the install command above and run it in your project — Pro patterns include a short-lived token.

  2. 2

    Add environment variables to .env.local

    OPENAI_API_KEY

  3. 3

    Point client fetches at your API routes

    Replace preview `/view/.../api/...` paths with `/api/...` in the installed files.

  4. 4

    Customize the agent and tool files

    Adapt prompts, tools, and stop conditions for your product — Copy for AI in the toolbar helps seed that work.

  5. 5

    Run your dev server and open the pattern route

    Install dependencies if needed, then start the app and verify responses.

Environment variables

Capabilities

AI SDK APIs

AgenttoolstepCountIsvalidateUIMessagesuseChatInferAgentUIMessage

Providers

OpenAI

External services

Upstash

Files added

7 files
  • app/page.tsx
  • app/layout.tsx
  • app/api/inquire-multiple-choice/route.ts
  • lib/ai/multiple-choice-inquire-agent.ts
  • lib/ai/tools/ask-multiple-choice-tool.ts
  • lib/tool-approval-types.ts
  • README.md

Dependencies

13 total

npm packages

6
AISDKlucide-reactNext.jsReactsonnerZod

Shadcn IconRegistry components

7
buttoncheckboxemptyinputlabeltextareatooltip

Critical files

  • ai/multiple-choice-inquire-agent.ts

    Agent implementation using ToolLoopAgent with hasToolCall stop condition. Contains processMultipleChoiceToolCalls for handling user answers and respondWithProcessing for the message pipeline.

  • tools/ask-multiple-choice-tool.ts

    Tool that dynamically generates multiple-choice questions using generateObject with a structured schema. Core tool for the inquire pattern.

Requirements

Complexity
Intermediate
Setup time
~15 minutes
Node
24+
Memory
512MB
Upstash Redis