Package: @hexos/react-core

Hook that registers a frontend tool the agent can call for browser-side execution.

Frontend tools execute in the browser rather than on the server, providing access to browser APIs (clipboard, geolocation, DOM, etc.). When the LLM invokes a tool whose name matches a registered frontend tool, useAgent detects the match in frontendToolsAtom and executes it locally.

The tool is automatically unregistered when the component unmounts.

Related: FrontendToolDefinition defines the tool structure, frontendToolsAtom stores the registry, useAgent orchestrates execution.

Example

useAgentTool({
  name: 'get_clipboard',
  description: 'Read the current clipboard contents',
  inputSchema: z.object({}),
  execute: async () => {
    return await navigator.clipboard.readText();
  },
  render: ({ output }) => <code>{output}</code>,
});
function useAgentTool<TInput, TOutput>(definition: FrontendToolDefinition<TInput, TOutput>): void

Parameters

definition