Skip to content

One-click answers

<ag-ui-answer> puts an "Explain" button beside one thing in your page: an event, an invoice, a failed job. A click asks a django-ag-ui answers mount for the answer about that subject, and draws it. It needs django-ag-ui 0.95.0 or later, the release that serves answers/<skill>/events/, the route the element follows a running answer through. The user never types a prompt: the server owns the prompt, the tools and the context, and the element only names a skill and a subject id.

<ag-ui-answer src="/answers/" skill="explain-event" subject="42" version="2026-11-30T10:00Z">
  Explain
</ag-ui-answer>
<script type="module">
  import { defineAnswer } from "@artooi/agents-web-components/answer";
  defineAnswer();
</script>

The server half is django-ag-ui's AnswersServer, mounted at the path src names; see Answers in its documentation. On a 0.93.0 or 0.94.0 mount a stored or new answer still draws, but a running one shows the failure, since those releases have no answers/<skill>/events/.

Attributes

Attribute What it is
src The answers mount, such as /answers/. The element asks <src>answers/<skill>/ and follows <src>answers/<skill>/events/ (django-ag-ui 0.95.0+).
skill The answer skill's name, as the server's AnswerSkill names it.
subject The subject's id. The server resolves it, and answers 404 for one the caller may not see.
version Your subject's version. Never sent: a change discards the answer shown, and the next open asks again.

A change to src, skill or subject discards the answer the same way, and cancels any request in flight.

What a click does

It opens on a click or a keyboard activation of its button (Enter or Space), never on hover: a miss starts a run the server pays for, so a stray mouseover must not.

  1. GET answers/<skill>/?subject=<id>. A stored answer (200, status: "done") is drawn at once, with no POST.
  2. A 404 POSTs {"subject": "<id>"} and draws the run's AG-UI stream as it arrives. Exactly one POST goes, however often the button is pressed while it runs.
  3. A running answer (200, status: "running", or a POST's 409) is followed through its run log, answers/<skill>/events/?subject=<id>&after=0, and its final text drawn. The route serves both a per-principal answer and a shared one, under the same gate as the GET; the element never asks threads/<id>/events/, which never serves a shared answer.
  4. Regenerate POSTs {"subject": "<id>", "regenerate": true}, which the server answers by deleting the stored answer and running it again.

Shared answers and Regenerate

A skill the server shares (AnswerSkill(shared_subject=...)) keeps one answer per subject and version for every reader subject admits, and the element reads it like any other. Every JSON body carries can_regenerate: when it is false the Regenerate button is hidden, and when it is true or absent (a 409 carries none) it shows. A shared skill without a can_regenerate predicate says false to everyone.

A reader whose own click writes a fresh shared answer reads no body before the stream, so Regenerate shows; the server answers it with 403, the element shows the failed state, and the next open reads can_regenerate: false. The bodies' degraded flag (a shared run whose tool call failed) is not drawn; a page that wants a note can ask the mount itself.

The element sends no tools, messages, state or context, and no RunAgentInput: the mount serves no free-form endpoint, and the server builds every run itself. A stream that ends before its run finished, or a run that errors, shows the failure rather than half an answer; closing and opening again asks once more.

The answer is markdown drawn by the chat's own renderer, which sanitises it: scripts, event handlers and images never reach the page.

Authenticating

An answers mount requires an authenticated user, and checks CSRF on its POST unless it is csrf_exempt. The element authenticates as the chat does:

Property What it is
headers Static headers sent with every request.
getHeaders Read per request and laid over headers, for a CSRF token or a rotating credential. May return a promise.
credentials The cookie policy, as fetch's own credentials; unset keeps the browser default.
trustedOrigins Origins besides the page's that may receive the headers without a console notice.
const answer = document.querySelector("ag-ui-answer");
answer.getHeaders = () => ({ "X-CSRFToken": readCookie("csrftoken") });

See Authenticating requests for the cross-origin case.

Text and styling

strings overrides the English text (open, loading, generating, regenerate, failed); anything slotted into the element replaces the button's label. It reads the same --ag-ui-* tokens as the other elements, and exposes the parts trigger, panel, body, status and regenerate. state reads idle, loading, generating, done or failed, and open whether the panel shows.

Installing

@artooi/agents-web-components/answer is its own entry, and @artooi/agents-web-components/answer/bundle the same as a vendored file. The main bundle does not carry it, so nothing changes for a host that does not import it. The vendored file inlines the protocol packages it reads the stream with, and none of the chat.