diff --git a/site/src/pages/AgentsPage/AgentDetail.tsx b/site/src/pages/AgentsPage/AgentDetail.tsx index f66461b7d2..0d59555cfc 100644 --- a/site/src/pages/AgentsPage/AgentDetail.tsx +++ b/site/src/pages/AgentsPage/AgentDetail.tsx @@ -385,6 +385,17 @@ const AgentDetail: FC = () => { outletContext?.requestArchiveAgent ?? noopRequestArchiveAgent; const scrollContainerRef = useRef(null); + // When switching between chats, reset the scroll container to the + // bottom (scrollTop 0 in a flex-col-reverse container) so the user + // always sees the most recent messages instead of a stale scroll + // position from the previous chat. + useEffect(() => { + void agentId; + if (scrollContainerRef.current) { + scrollContainerRef.current.scrollTop = 0; + } + }, [agentId]); + const chatQuery = useQuery({ ...chat(agentId ?? ""), enabled: Boolean(agentId),