This solution has been AI generated
You can stream real-time updates from the agent to the UI and persist them across reloads by using CopilotKit's Generative UI state streaming plus your agent framework's persistence (e.g., LangGraph checkpointers or CrewAI Flows persistence). In short: emit state as it changes, render it reactively on the frontend, and enable a checkpointer with a stable thread/session id.
Realtime updates (Agent ➜ UI)
# Python agent example
from copilotkit import copilotkit_emit_state
async def update_document(content):
await copilotkit_emit_state({
"document_content": content,
"last_modified": "2025-11-13T12:00:00Z"
})
UI rendering (React)
import { CopilotKit, useCoAgentStateRender } from "@copilotkit/react-core";
function DocumentUI() {
const render = useCoAgentStateRender({
name: "document_editor",
render: ({ state }) => (
<div>
<div>{state.document_content}</div>
<small>Last modified: {state.last_modified}</small>
</div>
),
});
return <CopilotKit runtimeUrl="/api/copilotkit">{render}</CopilotKit>;
}