useChatContext Hook
Deprecated
The useChatContext hook has been replaced by the useCyborg hook, which provides a more powerful and flexible API.
Please see the useCyborg Hook documentation for the current API.
Migration Guide
The useCyborg hook replaces useChatContext with an improved API:
Before (useChatContext)
tsx
import { useChatContext } from '@cyborg-sdk/react'
function ProductPage() {
useChatContext({
pageData: {
currentPage: '/products/123',
description: 'Product detail page',
productId: '123'
},
sessionData: {
userId: 'user123',
subscriptionTier: 'premium'
}
})
return <YourComponent />
}After (useCyborg)
tsx
import { useCyborg } from '@cyborg-sdk/react'
function ProductPage() {
useCyborg({
// Context replaces pageData and sessionData
context: {
page: 'product',
productId: '123',
userId: 'user123',
subscriptionTier: 'premium'
},
// NEW: AI behavior instructions
instructions: 'Help users understand this product.',
// NEW: Register tools
tools: [{
name: 'addToCart',
description: 'Add product to cart',
parameters: { type: 'object', properties: { quantity: { type: 'number' } } },
handler: async ({ quantity }) => {
// Your implementation
return { success: true }
}
}],
// NEW: Suggested prompts
suggestedPrompts: ['What are the features?', 'How does pricing work?']
})
return <YourComponent />
}Key Changes
| useChatContext | useCyborg |
|---|---|
pageData | context |
sessionData | context (merged) |
| - | instructions (NEW) |
| - | tools (NEW) |
| - | suggestedPrompts (NEW) |
Benefits of useCyborg
- Unified Context: No longer need to separate page and session data
- AI Instructions: Guide the AI's behavior per-component
- Tool Registration: Enable AI to execute functions in your app
- Suggested Prompts: Show context-aware prompts to users
- Dynamic Updates: Update context, tools, and prompts at runtime