#Persistence

1 messages · Page 1 of 1 (latest)

pulsar pikeBOT
#

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>;
}
#

Persistence across reloads/sessions

  • LangGraph: enable a checkpointer and use a stable thread id so state rehydrates on reload.
from langgraph.checkpoint.memory import MemoryStore
from copilotkit.integrations.langgraph import copilotkit_customize_config

memory = MemoryStore()
graph = your_graph.compile(checkpointer=memory)
config = copilotkit_customize_config(
    config={"configurable": {"thread_id": "user_session_123"}}
)
  • CrewAI Flows: use the persistence decorator so outputs are saved and restored.
from crewai.flow import Flow, start

class PersistentFlow(Flow):
    @start("kickoff")
    def run(self):
        return {"document_content": "..."}

Key points

  • Stream changes with copilotkit_emit_state for real-time UI updates.
  • Render with useCoAgentStateRender; it auto-updates.
  • Turn on your agent framework's persistence and use a stable thread/session id so the UI rehydrates with saved state.

References

  • Generative UI / useCoAgentStateRender
  • LangGraph persistence and checkpointers
  • CrewAI Flows persistence

Was this helpful?

If this solution worked for you, please click on the appropriate option below to help us improve:

stoic magnet
#

I am using mastra and I have an artifacts table

pulsar pikeBOT
#

Thank you for your feedback! Our team will provide additional assistance. 🔄