I create agent state in frontend NextJS and Langgraph Agent backend
export interface AgentManagedState {
selectedClient: Client | null;
salesID?: string;
}
So, when user select Client in frontend, I update state using
const handleClientIDChange = useCallback(
(client: ClientType) => {
// Normalize incoming client fields from API into our Client shape
const numericId = (client as any).customerId ?? (client as any).customer_id;
const normalized: ClientType = {
...client,
customerId: typeof numericId === "number" ? numericId : (numericId ? Number(numericId) : undefined as unknown as number),
} as ClientType;
preservedDataRef.current = {};
setAgentState((prevState: any) => {
if (!prevState) {
return {
selectedClient: normalized,
};
}
return {
...prevState,
selectedClient: normalized,
};
});
}, [setAgentState]);
but when I log state in frontend, I see selectedClient return to null.
By the way, in Langgraph backend, I have code
await copilotkit_emit_state(config, state)
that I don't see in new tutorial.