Skip to content

Tool call

The row a reply shows when the model calls one of your tools — its name, what it was asked, what it returned, and whether it is running, waiting for a person or done.

  • type: 'tool_call'
On this page
Open

When the model calls a tool, the reply gets a tool_call segment and the bubble draws it as a quiet row: the tool’s name, which shimmers while the call runs, and a word only when it waits for a person or something went wrong. Opening the row shows the input the model chose and the result your handler returned. The row is drawn for you; a tool registered with aparteGlobalConfig.registerTool() produces it during a turn without any code of yours.

Open

This one is an agent’s row (quiet: false), which names every state; the default, quiet row shows a word only for awaiting-approval, rejected, aborted and failed, and leaves “Running” and “Done” to a screen reader. A call is pending while your handler runs, awaiting-approval when the tool is marked needsApproval and a person has to decide (see Tools and approval), then resolved, rejected, aborted or failed. Only the first two are still open. A refused or stopped call also says why, in a note after the state word: You said: “…” when the person wrote something instead of choosing, Refused by policy, Not run: an earlier call was refused, Timed out, Not available here, No one could approve it or Turn limit reached. A plain Stop has no note. The segment keeps refusal ({ by, instruction? }) and abortCause, and its result stays the sentence the model read; the full table is in Tools and approval.

Open

registerToolSummary(match, summary) adds one line after the tool’s name, so read_file reads read_file docs/release.md without opening the row. It returns plain text; the row, its states and its disclosure stay the library’s. registerToolInputFormatter(match, formatter) rewrites the arguments behind the disclosure, and the approval panel shows the same text. match is a tool name, a RegExp or '*' (every tool nothing more specific describes); both write one field of the tool’s display, below.

Open

registerToolDisplay(match, display) gathers everything about how a tool’s calls look. label replaces the identifier web_search with words, drawn in the chat’s own font, not the code font; icon is an icon-provider key (an unknown one falls back to tool; search and globe come from @aparte/core/icons). The identifier stays on the row as data-tool-name. Core never turns an identifier into words on its own: the label is yours to write.

Open

Behind the line, a row shows Input and Output: the arguments and the result, raw. That is a developer’s view. A display’s details changes it. false keeps the line alone, with no disclosure, so the row never puts the person one click from JSON (a call that needs approval still shows its arguments in the approval panel; formatInput writes them in words). A function returns what stands in for Input and Output under the same line: here, the pages a search found. Return an element, and nothing the tool returned goes through innerHTML; a string goes through the HTML sanitizer. Return '' and the row shows no disclosure until there is something to show. The details are in Showing tool calls.

Open

The default row is a person’s line. While the call runs, the label shimmers instead of a spinner and a word. Once it is done, nothing marks success: the label’s tense says it, so write one that reads the status (“Searching the web…”, then “Searched the web”, and a plain “Search the web” for the rest). A wait for approval, a refusal, a failure and a stop still show their word and their note, because the person has to know. The words a quiet row does not show are still read by a screen reader. The target is set in the chat’s font, the chevron moves to the end of the line, and the row carries data-quiet for a stylesheet of your own.

An agent’s chat, where the reader follows the work, asks for the other row with quiet: false: a spinner and “Running”, then ”✓ Done”, as in Every status. On '*' it reaches every tool without an entry of its own; a tool that has one says quiet: false there too, since an entry is used whole.

ts
import { aparteGlobalConfig } from '@aparte/core';

aparteGlobalConfig.registerToolDisplay('*', { quiet: false });
Open

hidden: true draws nothing for the tool’s calls. They stay in the message, in storage and in the history the model reads, and an approval they need is still asked.

Open

A row is closed unless something opens it. It opens in this order: the segment’s collapsed (where a setSegmentDefaults('tool_call', { collapsed: false }) default lands, written onto each segment as it enters a chat), then the display’s open: true, then closed. A bubble drawn by hand, as in this demo, never applies a segment default, so it uses registerToolDisplay('*', { open: true }).

Open

registerToolRenderer(match, renderer) replaces the row for one tool, for every tool a pattern names, or, with '*', for every tool without a renderer of its own. An empty render hides the call (it stays in the history). Return an element rather than an HTML string: the input and the result come from the model and your tool, so a string would have to escape every value it interpolates. Add an update() to patch the element when the result lands, instead of rebuilding it.

ts
import { aparteGlobalConfig } from '@aparte/core';

aparteGlobalConfig.registerTool(
  {
    name: 'get_weather',
    description: 'Current weather for a city.',
    inputSchema: { type: 'object', properties: { city: { type: 'string' } }, required: ['city'] },
  },
  async (call) => ({ toolCallId: call.id, content: `Cloudy, 14 °C in ${call.input.city}.` }),
);

The client offers the tool to the model, runs the handler when it is called and draws the row for each call. Building a segment by hand, as these demos do, is for a reply your own code assembles.

To choose labels, icons and what is shown, read Showing tool calls to a person, or to a developer: it covers how a display is matched, hiding every call, and opening the rows.

AparteToolCallSegment, discriminated by type: 'tool_call'.

FieldTypeRequiredDescription
toolCallAparteToolCallyes
status'pending' | 'resolved' | 'aborted' | 'awaiting-approval' | 'rejected' | 'failed'yesawaiting-approval — paused for a human decision; rejected — the human (or a policy) declined to run it; aborted — stopped, timed out, or nothing could run it; failed — the handler threw, and result carries the crash’s one line. More
resultstring—
structuredResultunknown—The handler’s structuredContent, when it returned one — the value behind result’s prose.
deferred{ reason: 'approval' | 'external' | 'queued'; ticket?: string }—Set when a server loop (createAparteAgentHandler) suspended its run on this call: why it waits — a person’s decision (approval), a tool the page runs (external), or nothing but its turn (`queued More
refusal{ by: StreamRefusalOrigin; instruction?: string }—On a rejected call, who refused it — a person, a policy, or the loop because an earlier call of the same step was refused — and what the person typed instead. More
abortCauseStreamAbortCause | 'turn-limit'—On an aborted call, why: a Stop, its handler’s timeout, no handler here, a gate with nobody to ask, or its own turn limit. Absent when the run ended before it.
collapsedboolean—Whether the row’s disclosure starts closed. More

status — awaiting-approval — paused for a human decision; rejected — the human (or a policy) declined to run it; aborted — stopped, timed out, or nothing could run it; failed — the handler threw, and result carries the crash’s one line.

deferred — Set when a server loop (createAparteAgentHandler) suspended its run on this call: why it waits — a person’s decision (approval), a tool the page runs (external), or nothing but its turn (queued) — and the server’s signed continuation. Saved with the conversation, so a reload can still answer it (AparteClient.resumeDeferred).

refusal — On a rejected call, who refused it — a person, a policy, or the loop because an earlier call of the same step was refused — and what the person typed instead. result is the sentence the MODEL read; this is what a row tells a person, in their language. Absent on a call refused by a runner that does not say.

collapsed — Whether the row’s disclosure starts closed. Absent: closed, unless the tool’s display says open. setSegmentDefaults('tool_call', { collapsed: false }) opens every row; like reasoning’s, it is read when the row is drawn and never forced on an update.

  • When there is something behind the line (an input or a result, or the detail your details function draws), the row is a native <details>: its summary opens with Enter or Space and announces whether it is expanded. With nothing behind it (details: false included), it is a plain row and takes no tab stop.
  • The status is written in words (locale keys such as toolRunning, toolCompleted, toolFailed), not only shown as a colour or an icon. A quiet row keeps “Running” and “Done” for a screen reader only; its label’s tense says them on screen.
  • Input and Output are focusable regions named by their label, so a long part that scrolls past --aparte-tool-part-max-height (300px) can be read with the keyboard; each has a copy button.