Planning Your Context Strategy
For a step-by-step guide to deciding what data to send and how to keep it fresh, see Planning Your Context Strategy.
Why context matters
Identifying users tells the AI who they are. Context tells the AI what’s happening for them right now — what they’ve configured, what’s broken, what features they use. Each context entry has:- A key (unique identifier)
- A label (human-readable name shown in the AI prompt)
- An optional type hint (helps the AI understand the data shape)
- A value (any JSON: string, number, boolean, array, or object)
setContext()
clearContext()
Context at init time
You can set initial context when callinginit():
Context types
Thetype field is a semantic hint that helps the AI understand and format the data. See Context Entries for the full reference. Quick summary:
| Type | Purpose | Example |
|---|---|---|
list | Array of items | Events, features, products |
integration | External service connections | Stripe, HubSpot, Facebook Ads |
error | Active issues | Failed syncs, expired tokens |
status | State indicators | Account health, onboarding step |
config | Configuration state | Settings, preferences |
feature | Feature flags | Enabled/disabled features |
metric | Numeric KPIs | MRR, usage counts, limits |
relationship | Entity links | Space ID to company mapping |
custom | Anything else | Any structured data |
Dynamic updates
Context can be updated at any time. Useful for reflecting real-time state changes:How context reaches the AI
Context is sent with every chat message and merged with any context stored on the user/company records:- Stored context is loaded from the user and company records
- Per-request context (from the SDK) is layered on top — same keys overwrite
- The merged context is formatted into structured text in the AI system prompt
Where to go next
Context Entries
Deep reference for every context type with example AI output.
Context Planning
Strategy guide: what to send, how to structure, how to keep fresh.
Examples
Real-world patterns for SaaS, e-commerce, ad attribution.