Skip to main content

Module 31: Elicitation

An agent asks the user for structured input in the middle of a prompt: a form the client renders, and the user accepts, declines, or cancels.

What You’ll Learn

  • Sending an elicitation request from an agent with createElicitation
  • Building a form schema: text, single-select, multi-select, boolean, and integer fields
  • Handling accept, decline, and cancel responses in the agent
  • Advertising elicitation support and answering requests on the client

The Code

Agent: ask for a form mid-prompt

Elicitation is an agent-to-client request, so the prompt handler needs a reference to the agent. The async API makes the request-then-continue flow a flatMap:

Client: advertise support and answer

The client declares elicitation support in its capabilities and registers a handler. A real client shows the form to the user; the demo fills it in automatically:

Form Field Types

Responses

The agent must handle all three. A prompt that depends on the form still has to end its turn when the user declines or cancels.
Elicitation was added in SDK 0.12.0 as an unstable protocol element, marked @UnstableAcpApi. It may change in a minor release.

Source Code

View on GitHub

Running the Example

The demo runs four exchanges against the agent: a simple single-select that the user accepts, the full project form accepted with every field type, a form the user declines, and one the user cancels. No API key required.

Next Module

Module 32: Agent-Client Agent — from chatbot to agent: an ACP agent whose prompt handler runs a tool-using agent loop.