rememberCoAgentState

fun <T> rememberCoAgentState(name: String, initial: T, serializer: KSerializer<T>, reducer: AguiStateReducer, json: Json = defaultCoAgentJson): MutableState<T>

Bidirectionally bind a Compose MutableState to a slot inside an AG-UI AguiStateReducer.

The slot is addressed at RFC 6901 pointer /state/$name inside the reducer's store:

  • Upstream: when the reducer applies a STATE_SNAPSHOT / STATE_DELTA that touches the slot, the new value is decoded via serializer and pushed into the returned state.

  • Downstream: when the caller mutates state.value, the new value is encoded and written back via AguiStateReducer.writeLocal, which emits a replace patch on the reducer's outbound flow for the host to forward to the agent.

If the slot is empty at first read (or decoding fails) the state seeds from initial.

CopilotKit parity for LangGraph-style shared state.