Function to update model context
function ShoppingCart({ items }) {
const updateContext = useUpdateModelContext();
// Keep the model informed about cart state
useEffect(() => {
updateContext({
structuredContent: {
itemCount: items.length,
total: calculateTotal(items),
currency: "USD"
}
});
}, [items, updateContext]);
return <CartUI items={items} />;
}
Hook to update the host's model context
Unlike sendMessage which triggers follow-up actions, context updates inform the model about app state without triggering responses.
Platform implementation details:
On ChatGPT, both setState() and updateModelContext() expose state to the AI model. Use setState() for persistence-focused use cases, and updateModelContext() for context-focused use cases.