PAIPAI

Tool

Render a tool part. Custom cards receive ToolRenderProps.

Assistant.Tool renders one tool call from message.parts. The default card is enough for “the model searched docs.” Pass toolRenderers when you need a chart, citations, or an approval.

import { isPaiToolPart } from "@pai/react";

if (isPaiToolPart(part)) {
  return (
    <Assistant.Tool
      key={part.toolCallId}
      message={message}
      part={part}
    />
  );
}

Import

import { isPaiToolPart } from "@pai/react";
// Assistant.Tool comes from Pai.agent("main")

Signature

function Tool(props: ToolProps<TContract>): ReactElement | null;

Parameters

props: ToolProps<TContract>

message: PaiMessage<TContract>

Owning transcript message.

part: PaiStaticToolPart | PaiDynamicToolPart

The tool part to render. Narrow with isPaiToolPart(part).

fallback?: ReactNode | ToolRenderFn<TContract>

Rendered when no matching toolRenderers entry exists.

Returns

A ReactElement | null.

Default card, or the matching toolRenderers entry.

Register cards on the binding or on ThreadProvider:

Pai.agent("main", {
  toolRenderers: {
    searchDocs: (tool) => <SearchDocsCard tool={tool} />,
  },
});
function useToolRenderer<TName extends ToolRendererName<TContract>>(
  toolName: TName,
  render: ToolRenderFn<TContract, TName>,
): void;

ToolRenderProps

What a custom card receives:

part: ToolRenderPart<TContract, TName>

Native tool part. part.state is input-streaming | input-available | output-available | output-error | …

runStatus: RunLifecycleStatus | null

action: PendingActionView<TContract> | null

Set only while the tool is waiting on a person or a client tool.

Package-root <Tool /> follows the nearest ThreadProvider. Assistant.Tool keeps that agent's contract types.

Learn more

On this page