Automatically add state to the agent input context
subscribeInputContext
function allows you to automatically make any part of your application state available to AI agents as context. This enables agents to understand your app’s current state and provide more relevant, contextual responses.
subscribeInputContext
function subscribes to local state changes and automatically updates the agent’s input context whenever the state changes. This means your AI agent always has access to the most up-to-date information from your application.
localState: T
- The local state to subscribe to (any type)mapFn: (state: T) => Record<string, any>
- Function that maps your state to context entriesoptions
(optional) - Configuration for visual representation:
icon?: ReactNode
- Icon to display for this contextcolor?: string
- Hex color for visual stylingsubscribeInputContext
, here’s what happens automatically:
useEffect
to monitor changes to your localState
mapFn
transforms the state into context entriessubscribeInputContext
, entries are automatically marked with source: 'subscription'
.
options
parameter allows you to customize how the context appears in the UI: