#useCoAgent with existing threads

1 messages · Page 1 of 1 (latest)

granite steeple
#

Hello, I'm trying to use a thread between sessions in LangGraph.

useCopilotChat correctly loads the messages from the thread.

However useCoAgent doesn't pick it up initially in the state, and only updates the state after I send a new message and therefore I trigger one run in LangGraph.

How should I go at having useCoAgent load the initial state when my app loads?

worthy bolt
#

Hi @granite steeple , To ensure useCoAgent loads the initial state for your thread, you must provide the correct threadId to CopilotKit before the hook mounts.
Pass your persisted threadId as a prop to <CopilotKit> , or call setThreadId early in your app before rendering components that use useCoAgent. Let me know if you need anything else!