When LangGrpah agent call Generative UI tool, frontend (nextjs+copilotkit) will pick up and render the component using useCopilotAction.
As the component l involve API calling, when I continue conversation and agent stream response,** I see repeated API calls, like 20 times, as response streaming**.
export const DisplayTransactionHistoryUI = ({ status, handler, args }: any) => {
...
// Only fetch data after the agent has finished streaming (status is complete)
useEffect(() => {
// If the agent is still streaming data, don't fetch yet
if (status === 'inProgress' || status === 'executing') {
return;
}
// Once the streaming is complete, fetch transactions
const fetchTransactions = async () => {
// API call
}, [status, customer_id, date_from, date_to]);
Is this because dev mode? Does the component get mount and re-mount repetitively as response streaming in?
How can I prevent this to happen?
What is the best practice when useCopilotAction component contain API fetch?