Runtime Hooks

MessagePartRuntime

Hook for accessing message part state within parts.

useAui (Message Part Actions)

Access message part actions via useAui:

import { useAui } from "@assistant-ui/react";

const aui = useAui();

// Add a tool result to a tool-call message part
aui.part().addToolResult({ result: "Tool output" });

// Resume an interrupted tool call
aui.part().resumeToolCall({ approved: true });
MessagePartRuntime
addToolResult: (result: any) => void

resumeToolCall: (payload: unknown) => void

path: MessagePartRuntimePath

getState: () => MessagePartState

subscribe: (callback: () => void) => Unsubscribe

useAuiState (Message Part State)

Access the message part state reactively:

import { useAuiState } from "@assistant-ui/react";

const status = useAuiState((s) => s.part.status);
const type = useAuiState((s) => s.part.type);

For imperative access, use useAui:

import { useAui } from "@assistant-ui/react";

const aui = useAui();
const partState = aui.part().getState();
TextMessagePartState
type: "text"

text: string

parentId?: string

status: { readonly type: "running"; } | { readonly type: "complete"; } | { readonly type: "incomplete"; readonly reason: "length" | "cancelled" | "content-filter" | "other" | "error"; readonly error?: unknown; } | { readonly type: "requires-action"; readonly reason: "interrupt"; }