+ {/* Render before the message */}
+ {renderCustomMessage({ message, position: "before" })}
+
+
{message.content}
+
+ {/* Render after the message */}
+ {renderCustomMessage({ message, position: "after" })}
+
+ );
+}
+```
+
+## Return Value
+
+- Returns a function `(params) => ReactNode | null` that accepts `{ message, position }`.
+- Returns `null` if no custom message renderers are registered or if the current chat configuration is unavailable.
+
+### `position`
+
+`"before" | "after"`
+
+Indicates whether you’re rendering content before or after the message bubble. Custom renderers can choose to render on
+one or both positions.
+
+## Renderer Selection
+
+The hook filters the registered custom message renderers by:
+
+1. Agent ID – renderers tied to the active agent take priority.
+2. Global renderers – renderers without an `agentId` act as fallbacks.
+
+The first renderer that returns a truthy React element wins.
+
+## Additional Data Provided to Renderers
+
+When you register a custom message renderer (via `copilotkit.addCustomMessageRenderer`) the render component receives a
+rich set of props, including:
+
+- `runId` and run-scoped `stateSnapshot`
+- `messageIndex` and `messageIndexInRun`
+- `numberOfMessagesInRun`
+- `agentId`
+
+`useRenderCustomMessages` passes these values through so your renderer can understand the surrounding context.
+
+## Example: Inline Tool Output
+
+```tsx
+function ToolCallInspector({ message }: { message: Message }) {
+ const render = useRenderCustomMessages();
+ if (!render) return null;
+
+ return (
+