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'
<aparte-chat-bubble message-id="a1" data-role="assistant" name="Assistant"></aparte-chat-bubble>
<script>
// A reply is a list of segments: here a finished tool call, then the answer it led to.
// Open the row to see what the model sent and what the tool returned.
document.querySelector('aparte-chat-bubble').setSegments([
{
id: 's1',
type: 'tool_call',
status: 'resolved',
toolCall: { id: 't1', name: 'get_weather', input: { city: 'Lille' } },
result: 'Cloudy, 14 °C, wind from the west at 20 km/h.',
},
{ id: 's2', type: 'text', content: 'It is **14 °C and cloudy** in Lille, with a westerly wind. Bring a jacket.' },
]);
</script>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.
Variants
Section titled “Variants”Every status
Section titled “Every status”<!-- In your app: import { aparteGlobalConfig } from '@aparte/core'. -->
<aparte-chat-bubble message-id="a1" data-role="assistant" name="Assistant"></aparte-chat-bubble>
<script>
const { aparteGlobalConfig } = window.aparte;
// An agent's row, which names every state; the default, quiet row shows a word only for
// awaiting-approval, rejected, aborted and failed.
aparteGlobalConfig.registerToolDisplay('*', { quiet: false });
const call = (id, name, input) => ({ id, name, input });
document.querySelector('aparte-chat-bubble').setSegments([
// Running: the model asked, the handler has not answered yet.
{ id: 's1', type: 'tool_call', status: 'pending', toolCall: call('t1', 'search_docs', { query: 'release checklist' }) },
// Paused for a person (a tool marked needsApproval): the decision is asked at the composer.
{ id: 's2', type: 'tool_call', status: 'awaiting-approval', toolCall: call('t2', 'run_command', { cmd: 'pnpm publish' }) },
{ id: 's3', type: 'tool_call', status: 'resolved', toolCall: call('t3', 'read_file', { path: 'CHANGELOG.md' }), result: '## 0.19.2' },
// Refused, and the row says by whom: a person who wrote something instead of choosing
// (refusal.instruction), a policy (the note says so; the reason went to the model), or the loop, which
// did not run a call because an earlier one of the same step was refused.
{ id: 's4', type: 'tool_call', status: 'rejected', toolCall: call('t4', 'delete_file', { path: 'src/legacy.ts' }),
result: 'The user rejected this tool call and said: archive it instead',
refusal: { by: 'person', instruction: 'archive it instead' } },
{ id: 's5', type: 'tool_call', status: 'rejected', toolCall: call('t5', 'run_command', { cmd: 'rm -rf build' }),
result: 'Deleting is off in this workspace.',
refusal: { by: 'policy' } },
{ id: 's6', type: 'tool_call', status: 'rejected', toolCall: call('t6', 'write_file', { path: 'notes.md' }),
result: 'Tool execution was rejected by the user.',
refusal: { by: 'earlier-refusal' } },
// Stopped, and why. A plain Stop (abortCause 'stopped') has no note.
{ id: 's7', type: 'tool_call', status: 'aborted', toolCall: call('t7', 'fetch_page', { url: 'https://example.com' }), abortCause: 'stopped' },
{ id: 's8', type: 'tool_call', status: 'aborted', toolCall: call('t8', 'crawl_site', { url: 'https://example.com' }), abortCause: 'timeout' },
{ id: 's9', type: 'tool_call', status: 'aborted', toolCall: call('t9', 'send_email', { to: 'a@example.com' }), abortCause: 'no-handler' },
{ id: 's10', type: 'tool_call', status: 'failed', toolCall: call('t10', 'write_file', { path: '/etc/hosts' }), result: 'EACCES: permission denied' },
]);
</script>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.
A summary of what it ran on
Section titled “A summary of what it ran on”<!-- In your app: import { aparteGlobalConfig } from '@aparte/core'. -->
<aparte-chat-bubble message-id="a1" data-role="assistant" name="Assistant"></aparte-chat-bubble>
<script>
const { aparteGlobalConfig } = window.aparte;
// One line after the tool's name: what it targeted. Plain text, never HTML; the row,
// its states and its disclosure stay the library's.
aparteGlobalConfig.registerToolSummary('read_file', (segment) => String(segment.toolCall.input.path ?? ''));
aparteGlobalConfig.registerToolSummary('search_docs', (segment) => `“${segment.toolCall.input.query}”`);
document.querySelector('aparte-chat-bubble').setSegments([
{ id: 's1', type: 'tool_call', status: 'resolved', toolCall: { id: 't1', name: 'search_docs', input: { query: 'release checklist' } }, result: '3 pages' },
{ id: 's2', type: 'tool_call', status: 'resolved', toolCall: { id: 't2', name: 'read_file', input: { path: 'docs/release.md' } }, result: '## Release' },
]);
</script>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.
A name and an icon of its own
Section titled “A name and an icon of its own”<!-- In your app: import { aparteGlobalConfig } from '@aparte/core'. -->
<aparte-chat-bubble message-id="a1" data-role="assistant" name="Assistant"></aparte-chat-bubble>
<script>
const { aparteGlobalConfig } = window.aparte;
// An icon is a key of the icon provider. 'search' ships in '@aparte/core/icons'; here a
// glyph of our own stands in for it.
aparteGlobalConfig.registerIcons({
search: () => '<svg class="aparte-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><circle cx="10.5" cy="10.5" r="7"/><path d="m16 16 5.5 5.5"/></svg>',
});
// A label replaces the identifier; the identifier stays on the row as data-tool-name.
aparteGlobalConfig.registerToolDisplay('web_search', {
label: (segment) => (segment.status === 'resolved' ? 'Searched the web' : 'Search the web'),
icon: 'search',
summary: (segment) => `“${segment.toolCall.input.query}”`,
});
aparteGlobalConfig.registerToolDisplay('read_file', {
label: (segment) => (segment.status === 'resolved' ? 'Read a file' : 'Read a file…'),
icon: 'file',
summary: (segment) => String(segment.toolCall.input.path ?? ''),
});
// A label can read the call: the same tool, said differently once it is done.
aparteGlobalConfig.registerToolDisplay('delete_file', {
label: (segment) => (segment.status === 'resolved' ? 'Deleted a file' : 'Delete a file'),
icon: 'trash',
summary: (segment) => String(segment.toolCall.input.path ?? ''),
});
document.querySelector('aparte-chat-bubble').setSegments([
{ id: 's1', type: 'tool_call', status: 'resolved', toolCall: { id: 't1', name: 'web_search', input: { query: 'release checklist' } }, result: '3 pages' },
{ id: 's2', type: 'tool_call', status: 'resolved', toolCall: { id: 't2', name: 'read_file', input: { path: 'docs/release.md' } }, result: '## Release' },
{ id: 's3', type: 'tool_call', status: 'resolved', toolCall: { id: 't3', name: 'delete_file', input: { path: 'docs/draft.md' } }, result: 'Deleted' },
]);
</script>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.
What is behind the line
Section titled “What is behind the line”<!-- In your app: import { aparteGlobalConfig } from '@aparte/core'. -->
<aparte-chat-bubble message-id="a1" data-role="assistant" name="Assistant"></aparte-chat-bubble>
<script>
const { aparteGlobalConfig } = window.aparte;
// details: false, the line alone: no disclosure, so no raw JSON one click away.
aparteGlobalConfig.registerToolDisplay('read_file', {
label: 'Read a file',
icon: 'file',
summary: (segment) => String(segment.toolCall.input.path ?? ''),
details: false,
});
// A function: what it returns stands in for Input and Output, under the same line. An
// element, so nothing the tool returned goes through innerHTML.
aparteGlobalConfig.registerToolDisplay('web_search', {
label: 'Searched the web',
summary: (segment) => '“' + segment.toolCall.input.query + '”',
details: (segment) => {
const list = document.createElement('ul');
for (const page of JSON.parse(segment.result)) {
const item = document.createElement('li');
item.textContent = page.title + ' · ' + page.site;
list.append(item);
}
return list;
},
open: true,
});
document.querySelector('aparte-chat-bubble').setSegments([
{ id: 's1', type: 'tool_call', status: 'resolved', toolCall: { id: 't1', name: 'read_file', input: { path: 'docs/release.md' } }, result: '## Release' },
{ id: 's2', type: 'tool_call', status: 'resolved', toolCall: { id: 't2', name: 'web_search', input: { query: 'release checklist' } },
result: JSON.stringify([
{ title: 'Shipping a library release', site: 'example.org' },
{ title: 'Changesets, step by step', site: 'example.com' },
{ title: 'Tagging and publishing', site: 'example.net' },
]) },
]);
</script>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.
A line for a person
Section titled “A line for a person”<!-- In your app: import { aparteGlobalConfig } from '@aparte/core'. -->
<aparte-chat-bubble message-id="a1" data-role="assistant" name="Assistant"></aparte-chat-bubble>
<script>
const { aparteGlobalConfig } = window.aparte;
// Quiet, the default: a shimmer instead of a spinner and "Running", and nothing once it is
// done — the label's tense says it. A refusal, a failure or a stop still says so.
aparteGlobalConfig.registerToolDisplay('web_search', {
label: (segment) => segment.status === 'pending' ? 'Searching the web…' : segment.status === 'resolved' ? 'Searched the web' : 'Search the web',
summary: (segment) => '“' + segment.toolCall.input.query + '”',
details: false,
});
document.querySelector('aparte-chat-bubble').setSegments([
{ id: 's1', type: 'tool_call', status: 'pending', toolCall: { id: 't1', name: 'web_search', input: { query: 'quiet weekend near a lake' } } },
{ id: 's2', type: 'tool_call', status: 'resolved', toolCall: { id: 't2', name: 'web_search', input: { query: 'release checklist' } }, result: '3 pages' },
{ id: 's3', type: 'tool_call', status: 'failed', toolCall: { id: 't3', name: 'web_search', input: { query: 'ferry timetable' } }, result: 'The search service did not answer.' },
]);
</script>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.
import { aparteGlobalConfig } from '@aparte/core';
aparteGlobalConfig.registerToolDisplay('*', { quiet: false });Hidden calls
Section titled “Hidden calls”<!-- In your app: import { aparteGlobalConfig } from '@aparte/core'. -->
<aparte-chat-bubble message-id="a1" data-role="assistant" name="Assistant"></aparte-chat-bubble>
<script>
const { aparteGlobalConfig } = window.aparte;
// Every tool nothing more specific describes: no row. The calls stay in the message, in
// storage and in the history the model reads; an approval they need is still asked.
aparteGlobalConfig.registerToolDisplay('*', { hidden: true });
document.querySelector('aparte-chat-bubble').setSegments([
{ id: 's1', type: 'tool_call', status: 'resolved', toolCall: { id: 't1', name: 'search_docs', input: { query: 'release checklist' } }, result: '3 pages' },
{ id: 's2', type: 'tool_call', status: 'resolved', toolCall: { id: 't2', name: 'read_file', input: { path: 'docs/release.md' } }, result: '## Release' },
{ id: 's3', type: 'text', content: 'The release needs three steps: bump the version, run the gate, then tag it.' },
]);
</script>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.
Rows opened by default
Section titled “Rows opened by default”<!-- In your app: import { aparteGlobalConfig } from '@aparte/core'. -->
<aparte-chat-bubble message-id="a1" data-role="assistant" name="Assistant"></aparte-chat-bubble>
<script>
const { aparteGlobalConfig } = window.aparte;
// Every tool row arrives open: Input and Output on screen, each with a copy button. A display's
// open is read when the row is drawn; in a chat, setSegmentDefaults('tool_call', { collapsed: false })
// does the same for every row (a bare bubble like this one never applies a segment default).
aparteGlobalConfig.registerToolDisplay('*', { open: true, quiet: false });
document.querySelector('aparte-chat-bubble').setSegments([
{ id: 's1', type: 'tool_call', status: 'resolved', toolCall: { id: 't1', name: 'search_docs', input: { query: 'release checklist', limit: 3 } }, result: JSON.stringify({ hits: [{ title: 'Release', score: 0.92 }, { title: 'Changelog', score: 0.71 }] }) },
{ id: 's2', type: 'tool_call', status: 'resolved', toolCall: { id: 't2', name: 'run_command', input: { cmd: 'git status' } }, result: 'On branch main\nnothing to commit, working tree clean' },
]);
</script>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 }).
Your own rendering
Section titled “Your own rendering”<!-- In your app: import { aparteGlobalConfig } from '@aparte/core'. -->
<aparte-chat-bubble message-id="a1" data-role="assistant" name="Assistant"></aparte-chat-bubble>
<script>
const { aparteGlobalConfig } = window.aparte;
// Every get_weather call is drawn by this instead of the default row. Returning an
// element (not a string) means the model's data never goes through innerHTML.
aparteGlobalConfig.registerToolRenderer('get_weather', {
render(segment) {
const card = document.createElement('div');
card.className = 'aparte-card';
const body = document.createElement('div');
body.className = 'aparte-card__body';
body.textContent = segment.status === 'resolved'
? `${segment.toolCall.input.city}: ${segment.result}`
: `Checking the weather in ${segment.toolCall.input.city}…`;
card.append(body);
return card;
},
});
document.querySelector('aparte-chat-bubble').setSegments([
{ id: 's1', type: 'tool_call', status: 'resolved', toolCall: { id: 't1', name: 'get_weather', input: { city: 'Lille' } }, result: 'cloudy, 14 °C' },
]);
</script>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.
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.
Fields
Section titled “Fields”AparteToolCallSegment, discriminated by type: 'tool_call'.
| Field | Type | Required | Description |
|---|---|---|---|
toolCall | AparteToolCall | yes | |
status | 'pending' | 'resolved' | 'aborted' | 'awaiting-approval' | 'rejected' | 'failed' | yes | 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. More |
result | string | — | |
structuredResult | unknown | — | 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 |
abortCause | StreamAbortCause | '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. |
collapsed | boolean | — | 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.
Accessibility
Section titled “Accessibility”- When there is something behind the line (an input or a result, or the detail your
detailsfunction 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: falseincluded), 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.
Related
Section titled “Related”- Tools and approval — registering tools, what the row shows, and asking a person first.
- Showing tool calls to a person, or to a developer — labels, icons, hiding and opening rows.