useLexicalTools
Agent Runtimes / tools/adapters/agent-runtimes/lexicalHooks / useLexicalTools
Function: useLexicalTools()
useLexicalTools(
documentId,contextOverrides?):FrontendToolDefinition<Record<string,unknown>,unknown>[]
Defined in: tools/adapters/agent-runtimes/lexicalHooks.ts:54
Hook that creates agent-runtimes tools for lexical operations. Returns a stable tools array — only recreated when documentId changes.
IMPORTANT: Uses lexicalStore.getState() (a plain snapshot) instead of the
reactive useLexicalStore() hook. The reactive hook subscribes to every
Zustand state change (block insertions, cursor moves, etc.), which would
cause this hook — and therefore the parent component — to re-render on
every editor mutation. That re-render creates a new tools array, which
previously caused LexicalToolsPlugin → handleToolsReady → toolsKey++
→ ChatFloating remount → isLoading reset.
The notebook hook (useNotebookTools) already uses this stable pattern
via notebookStore.getState() and useMemo, which is why the notebook
example never had this bug.
Parameters
documentId
string
Document ID (lexical document identifier)
contextOverrides?
Partial<Omit<ToolExecutionContext, "documentId" | "executor">>
Optional context overrides (format, extras, etc.)
Returns
FrontendToolDefinition<Record<string, unknown>, unknown>[]
Frontend tools array for ChatFloating / Chat
Example
const frontendTools = useLexicalTools("doc-123");
<ChatFloating
endpoint="http://localhost:8765/api/v1/ag-ui/agent/"
frontendTools={frontendTools}
/>