A question that offers real choices, and says how many you may take

Three things about `ask_user`, all of them about the card being answerable
rather than about the tool being callable.

Options are required now, and they are objects: a label, and a line of
description where the label alone does not say what choosing it would mean.
"Rewrite it" and "Patch it" are two words that do not tell you which one loses
your uncommitted work. They stack one per line, because a row of chips has
nowhere to put the second line and no room to read the first.

The model says whether they are exclusive. Only it knows whether its options are
alternatives or a set, and the card has to show which -- a radio group offered
where checkboxes were meant loses every answer but one. Exclusive is the
default, being the cheaper mistake. A `multiple` question posts the same field
name once per ticked box, so the endpoint gathers choices into a list; the
`setdefault` it did before kept the first and dropped the rest, which is an
answer that says something the reader did not.

And "Something else" is added here, on every question, with the box behind it
revealed by `:has()` and no JavaScript at all. The model is told never to write
an "other" option of its own, because its version would be a choice with no box
behind it -- a word submitted that means nothing. It carries a sentinel rather
than an answer, and the endpoint swaps in what was typed beside it, or drops it
when the box was left empty rather than telling the model the answer is
"__other__".

Typing no longer beats picking. That rule belonged to a box that was always
visible next to the options; this one only exists once its own option is chosen,
so picking is the answer and the box is one of the things you can pick.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jaroslav Beneš
2026-08-04 19:34:47 +02:00
parent 74a3c0f9d3
commit 3065878bd0
9 changed files with 524 additions and 44 deletions
+39 -2
View File
@@ -1377,7 +1377,6 @@ def _ask_items(context, calls: list[dict], arguments: list[dict]) -> list[intera
args = arguments[index]
for asked in _questions_in(args):
options = [str(o).strip() for o in (asked.get("options") or []) if str(o).strip()]
items.append(
interaction.Item(
index=index,
@@ -1385,12 +1384,50 @@ def _ask_items(context, calls: list[dict], arguments: list[dict]) -> list[intera
kind=interaction.KIND_QUESTION,
tool_name=call["name"],
title=str(asked.get("question") or "").strip() or "A question for you",
options=tuple(options[: interaction.MAX_OPTIONS]),
options=_options_in(asked),
multiple=bool(asked.get("multiple")),
)
)
return items
def _options_in(asked: dict) -> tuple[interaction.Option, ...]:
"""The choices offered for one question, however they were spelled.
The schema asks for objects with a `label` and an optional `description`,
and a capable model sends that. A small one sends a list of bare strings --
which is what the schema asked for until recently and is what most examples
of this pattern look like -- so that is read as a label with no description
rather than refused. Anything else in the list is dropped rather than
stringified, because `{'a': 1}` rendered as a choice is worse than one
choice fewer.
An option meaning "something else" is **not** added here. It belongs to the
template, which adds it to every question and owns the box behind it; adding
it to the data would make it indistinguishable from one the model wrote.
"""
out: list[interaction.Option] = []
for raw in asked.get("options") or []:
if isinstance(raw, str):
label, description = raw.strip(), ""
elif isinstance(raw, dict):
label = str(raw.get("label") or raw.get("name") or raw.get("value") or "").strip()
description = str(raw.get("description") or "").strip()
else:
continue
if not label:
continue
out.append(
interaction.Option(
label=label[: interaction.MAX_OPTION_CHARS],
description=description[: interaction.MAX_OPTION_CHARS],
)
)
if len(out) >= interaction.MAX_OPTIONS:
break
return tuple(out)
def _questions_in(args: dict) -> list[dict]:
"""The questions in one `ask_user` call, however it was spelled.