Files
baserow/docs/development/agent-tool-presentations.md
alamin-br 2686fb21a9 fix(agent): show held calls in full, name option renames, stop replies on trash (#6909)
* fix(agent): show held calls in full, name option renames, stop replies on trash

Approvers saw cut previews of what was sent, option renames hid the rows they
change, and trashing an agent left its running reply going.

* fix(agent): let a removed member's running reply finish

Removal now only blocks the member's next send or approval, so an accidental
removal doesn't leave a partial result that won't resume.
2026-11-30 14:24:03 +00:00

11 KiB

Agent tool presentations

Agent replies show each tool call as a card above the reply, live and after reload. Core's toolPresentation registry and its ChatStepGroup card render them. The Agent module registers its database presenters in modules/agent/plugin.js.

See Background chat runs for the streaming lifecycle.

The step contract

The backend emits step events and saves the same steps on the assistant message:

{
    "id": "unique-call-id",
    "tool": "create_rows",
    "status": "done",
    "changes_data": true,
    "input": {
        "requested_count": 2,
        "values": {
            "database": "Work",
            "table": "Tasks",
            "rows": [{ "Name": "Acme" }, { "Name": "Beta" }]
        }
    },
    "facts": { "count": 2 }
}
  • tool is the callable tool's name. Configured actions also set presentation_type to their stable service type, such as smtp_email, because their callable names are editable. Frontend presenters resolve presentation_type || tool. They only describe calls and never select what runs or what is allowed.
  • status is running, waiting, done, failed, rejected, stopped or skipped, see STEP_STATUS in modules/core/chatRuns/constants.js. Calls held for approval are waiting from their call event, including changes that follow a held call in the same response. Other valid calls are running until their result arrives. rejected means the owner denied the call, so it did not run. A held call the reply ends without resuming is rejected if the owner rejected it, stopped if they approved it and the resume started, since it may have run, and otherwise failed with not_run. Copies end held calls the same way, as approvals aren't copied. stopped means the reply ended before the call's result: a change may already have completed, and the card says so. skipped means the call changed nothing and failed nothing; it has no card. A held call is never skipped, as the owner already saw it. A held call gets its readable request when it is held, so the owner decides on names, not IDs.
  • input is what the call asked for. requested_count is known when the call starts. values, the request with names instead of IDs, follows while it runs, before the tool changes anything; see Readable requests.
  • facts are confirmed after an authorized success: a count, and the names of created or read tables. Successful table creation also records the database ID and each created table's ID and name so the card can link to the table. A requested count doesn't prove how many items changed. A batch that partly fails is done with the count the tool reports.
  • error_code is set on failed steps: not_found, permission_denied, invalid_input, invalid_formula, conflict, failed or not_run, for a held call that ended without running. For an exception the tool raises, it comes from classify_tool_error in baserow/core/tools/errors.py. Arguments that fail validation are invalid_input. not_found covers missing and inaccessible resources alike.
  • error_message is the tool error's message, written for people and at most 1,000 characters. The card shows it instead of the code's generic label.
  • item_errors lists up to 20 failed items, each with item, code and message. On a done step they make the call partial: some items changed, these didn't. An error's hint is advice for the model and is never stored.

Every call has its own step, so a retry after a failure is a new step.

Calls to tools the reply doesn't offer get no step.

Readable requests

AgentToolType.get_step_preview(ctx, arguments) names a database tool's request as the Agent identity, before the tool runs. The tool sends it to its running step as a ToolCallInputEvent, so input.values stays on running, stopped and failed steps too.

  • What the identity can't name keeps its ID, such as {"table_id": 7}, {"field_id": 4} or {"row_id": 12}. The tool, not the preview, decides whether the call succeeds; a preview that can't be built is left out.
  • Only values of known, readable fields are shown; everything else, such as a password, a misspelled field or any field of a table that can't be named, is masked as "••••".
  • Every list keeps 10 items and every object 10 keys, at any depth; requested_count keeps the requested number.
  • Strings keep 1,000 characters.
  • Over 16 KiB of JSON, trailing items are left out until it fits; when none fits, the list is left out, never shown empty.
  • input.truncated marks any of these cuts; the card says the preview is shortened.
  • A held call is the exception, from when it waits until it ends: the person deciding reads every value the call writes, so every item is named and nothing is cut (get_step_preview_input(ctx, arguments, held=True)). StepPreview.cut_items and to_input read this from held_previews. See Held calls.
  • Each ID is resolved on its own: two fields named "Name" stay two entries.
  • A table, field or view is named with its database, as a duplicated database keeps every name. The tables of a schema read or a creation are too.
  • Rows are named by their primary field value, or unnamed row <id>, when the identity may list them. When two rows of one call read the same, every named row of the call gets its ID too.
  • Field IDs in views and filters become names when the identity may list the table's fields; others stay as written.
  • An integer linked_table in create_fields the identity can't see stays as written.
  • Reads of one table name only the table and its database, so a held read shows what it reads.

Held calls

What a held call stores is bounded only by MAX_HELD_INPUT_SIZE, 256 KiB of JSON, in core/chat_runs/tool_input.py (held_tool_input). Larger, the longest texts are cut first, to no fewer than 100 characters, and then the values after the first one that doesn't fit are left out. The input then has truncated, omitted_characters (cut from texts) and omitted_values (left out), and the card says how much is missing. It is never stored empty.

Nothing else bounds a step: AgentMessage.steps is a JSON field, the websocket only says a run changed, and the API returns the stored steps. A run whose unflushed live events pass 1 MiB stops streaming them; its stored steps are unaffected.

The same applies to held calls of connected apps' (MCP) tools, whose step shows every argument, credentials masked. An argument is masked when a word of its name, split on anything but letters and digits and on camelCase, is pass, passwd, password, passphrase, secret(s), token, apikey, authorization, credential(s), cookie(s) or privatekey, when two words read api key or private key, or when a word ends with password, passphrase, secret, token, apikey, privatekey or credential(s), like accesstoken. So password, access_token and X-Api-Key are masked, and passenger, tokenizer_mode and max_tokens aren't.

Tool details start collapsed. Objects with keys are shown as a two-column table. Nested objects, arrays and other JSON values retain their JSON formatting.

Configured actions

An action type resolves the action's formulas once with the call's arguments and sends their readable projection through the same ToolCallInputEvent. The preview includes fixed configuration as well as model-supplied values: email recipients, sender, subject, body, and body format, for example. Action types explicitly allow readable fields; integration credentials never enter the preview. Service export redaction is a separate policy: an email body is sensitive in an external export but must be visible to the person approving its delivery.

An action's preview isn't bounded as above: its action type decides how to limit what a call may send and what its preview shows. The values are stored as JSON, which doesn't keep their order, so the action's presenter orders and labels them. See One call for how the shown values are the ones sent.

The provider runs web search itself, so it has no AgentToolType. Its step uses web_search as tool, starts when the provider reports the call and gets its input once the call is complete. Unlike other tools, its input keeps the queries (queries) and any page the provider opened (url), bounded in count and length, because the step is the only record of what the Agent sent out. A reply that was meant to search but couldn't, because the provider refused the tool, gets one failed step whose input is {"unavailable": true}. A search is never held for approval, even next to a held call. A resumed reply offers search only if its paused run did, so a provider that refused it isn't asked again.

Opening web pages

When "Open web pages" is on, Baserow downloads pages itself, so every model can use it. It is a function tool named web_fetch with no AgentToolType, and its step looks like a page web search opened: input holds only the url. The tool refuses a URL the step can't record in full, so the step always names the page that was requested. It downloads through the same outbound HTTP stack as the HTTP request integration (address checks on every redirect, the response size ceiling and one deadline), opens only text pages, and stops after a few pages per reply. Internal addresses are refused even where integrations may reach them, because the model picks the URL. A failure comes back as a tool error with a message instead of a retry, so broken links don't use up the reply's retries. Opening a page is never held for approval. A resumed reply offers it only if its paused run did and the setting is still on.

Adding a tool

Backend. An AgentToolType describes its calls with get_step_input(arguments), get_step_preview(ctx, arguments) and get_step_facts(ctx, arguments, result). get_step_input and get_step_facts default to {}; a failure in either is logged without values and doesn't change the tool's result. get_step_preview defaults to None; build it with the helpers in contrib/agent/previews.py. When it raises, the step has no values and the call still runs.

Frontend. Extend ToolPresentationType from modules/core/toolPresentationTypes.js and implement getLabel(t), getDescription(t) and getActivity(step, t). Register it in the toolPresentation namespace from the owning module's plugin. Return WORKSPACE_TOOL_GROUP from group only for workspace reads: consecutive reads share one card, and each change gets its own. A step that isn't running or done is titled by what it asked for. Unknown tools, missing translations and presenter errors fall back to generic labels that keep the step's status.

Translations. Put labels in the owning module's English locale file. Use plural forms such as "Creating {count} row | Creating {count} rows", called with t(key, { count }, count).

Coverage. Add each tool to tests/cases/agent_tools.json with valid arguments, the expected input, the preview a call on the test table produces, and representative facts. Backend tests check the examples against the tool registry and argument schemas. Frontend tests check that every tool has a registered presenter with translated titles for each status. The fixture's step_error_codes keeps the backend and frontend codes in sync.