When streaming long responses, the agent fires a re-render for every token. With many messages in the thread, this can cause jank. Two quick fixes:
- Throttle re-renders — add
throttleMsto cap update frequency:
const { agent } = useAgent({ throttleMs: 50 }); // ~20 renders/sec- Memoize message components — wrap your message renderer in
React.memoso only the streaming message re-renders:
const Message = React.memo(({ msg }) => <p>{msg.content}</p>);See the useAgent performance docs for more details.