agent-fill.js: let visitors hand any HTML form to their AI agent
agent-fill.js is a script for a page that has a form. It reads the labelled inputs and builds a prompt. The visitor gives the prompt to their AI agent. They paste the answer back. The script sends nothing. The visitor presses your own Submit button.
Add it
Put one script tag on the page that holds the form. Set data-form to a CSS selector for the form.
<form id="my-form" action="/join" method="post">
<label for="name">Full name</label>
<input id="name" name="name" required>
<!-- more fields -->
<button type="submit">Join</button>
</form>
<script src="https://aiformapi.com/agent-fill.js" data-form="#my-form"></script>The script waits until the page has loaded, so it works above or below the form. It adds a button right above the form. The script is about 22 KB minified, has no dependencies and needs no account and no API key.
Options
Set these as attributes on the script tag.
| Attribute | Needed | What it does |
|---|---|---|
data-form | No | A CSS selector for the form, such as #my-form. Without it, the script uses forms that carry a data-agent-fill attribute. If there is none and the page has exactly one form, it uses that form. |
data-title | No | The form name that appears in the prompt. The default is the form's aria-label, then the page title, then Form. |
data-form-id | No | The id that appears in the prompt and in the block the agent replies with. The default is the form's id, then its name, then form. |
data-button | No | The text on the button. The default is Fill this form with my AI agent. |
If you add the form to the page after the script has run, mount it yourself:
<script src="https://aiformapi.com/agent-fill.js"></script>
<script>
window.AgentFill.mount(document.querySelector("#my-form"), {
title: "Join the book club",
formId: "join",
buttonLabel: "Fill this with my AI agent"
});
</script>All 3 options are optional. A form is mounted once, even if you call mount again.
What the visitor sees
- The visitor presses the button above your form. A dialog opens with the prompt.
- They press Copy prompt and give it to Claude, ChatGPT or any other agent. The agent asks for what it does not know, shows the answers and asks "Is this right?".
- The agent replies with one JSON block. The visitor pastes it into Paste your agent's answer and presses Fill the form.
- The script checks the block, fills the inputs and outlines any answer that needs a look. It says "Nothing was sent". A screen reader hears the same note.
- The visitor reads the form and presses your normal Submit button.
This is Path B from Agent fill. Path A, where the agent sends the answers itself, needs an API, so it is not part of this script.
What it reads
The script reads the form again each time the button is pressed, so fields that appear later are included. It finds the label of an input from aria-label, aria-labelledby, a label with a matching for, a wrapping label, the placeholder, and last the name.
| On your form | Question type |
|---|---|
input of type text, search and other plain types | short_text, with max_length when maxlength is 500 or less |
textarea | long_text, with max_length when maxlength is 5,000 or less |
input type="email" | email |
input type="tel" | phone |
input type="url" | url |
input type="date" | date |
input type="number" or range | number, with min and max from the attributes |
select | single_choice, or multi_choice when it has multiple |
Radio buttons with one name | single_choice. The question text is the legend of the fieldset |
Checkboxes with one name | multi_choice |
| One checkbox | checkbox |
The required attribute makes a question required. For a group of radio buttons, one required button is enough. A choice question needs at least 2 options. Disabled inputs are left out.
What it never reads
- Inputs of type
password,hidden,file,color,submit,button,resetandimage. - Inputs with an
autocompletevalue that starts withcc-, or iscurrent-password,new-passwordorone-time-code. - Any input whose label,
nameoridmatches the blocked-field list: passwords, PINs, CVV, card numbers, IBANs, OTP, passport and national ID numbers and the other terms in Forms and fields.
The dialog lists the skipped fields under the prompt as "Not shared with the agent". The agent never learns they exist, and the visitor types them by hand.
The prompt
It has the same wording as the prompt on AI Form API forms, with three differences: it names the page, it says it was sent through agent-fill.js, and it only offers the paste-back path.
You are helping me fill in a form. Please do it carefully.
Form: "Join the book club"
Page: https://example.com/join
Sent through agent-fill.js · form id join
Questions:
1. [fullname] Full name — short text, required
2. [email] Email — email address, required
3. [country] Country — single choice, one of: "Germany", "United Kingdom", optional
Rules:
- Use what you already know about me from this chat only when you are sure. Ask me for anything missing, one short question at a time.
- Never invent personal details. Leave out optional questions I skip.
- Before you finish, show me all answers and ask "Is this right?". Continue only after I say yes.
How to hand the answers back:
Reply with ONLY this block, filled in, so I can paste it back into the form on the page. I will check it and press the form's own submit button myself.
```json
{"form": "join", "answers": {"fullname": "", "email": "", "country": ""}}
```The Page: line holds the address of your page without the query string. The prompt exists only in the visitor's browser until they copy it.
What it does not do
- It does not call AI Form API. After the browser has downloaded the script, the script makes no network request. The labels, the prompt and the answers stay on the page.
- It does not set cookies or write to browser storage.
- It does not submit the form. The visitor does that.
- It does not replace your form's own checks. Your server still validates what arrives.
Good to know
- The dialog sits in a shadow root, so your page styles do not change it and it does not change your page.
- It sets values the way a person would, with
inputandchangeevents, so forms built with React or Vue see the change. - A strict Content-Security-Policy must allow the script from
https://aiformapi.comand inline styles for the dialog. - The same checks run on the pasted answer as on AI Form API forms: a wrong type, a missing required answer or a value that is not one of the options is outlined.
Why it exists
Plenty of forms on the web are not ours: a contact form, a booking form, a school form. Anyone who wants help from an AI agent has to copy the questions by hand. This script gives those forms the same hand-off that AI Form API forms have. Read more on agent-fillable forms.
Status
agent-fill.js ships with version 0, released on 2026-10-30. See the changelog for releases.