Context
Context is information about your application that helps the AI agent provide relevant, personalized responses.
Why Context Matters
Without context, every conversation starts from scratch. The AI has no idea:
- What page the user is on
- What they’re trying to accomplish
- What data they’re looking at
- Their user role or permissions
With context, the AI can:
- Answer questions about specific data on the screen
- Provide personalized recommendations
- Reference the user’s current workflow
- Give relevant help for the current task
Example: With vs Without Context
Without Context
User: "What's my balance?"
AI: "I don't have access to your account information."
With Context
User: "What's my balance?"
AI: *sees user.balance from context*
AI: "Your current balance is $1,247.32"
How to Provide Context
The context prop allows you to pass real-time application state as a read-only snapshot to the AI agent:
Static Context (Object)
When context doesn’t change frequently, pass a plain object:
<InAppAI
agentId="your-agent-id"
context={{
page: 'dashboard',
userName: user.name,
userRole: user.role,
plan: 'professional',
}}
/>
Dynamic Context (Function)
When context changes frequently, use a function to capture fresh state:
<InAppAI
agentId="your-agent-id"
context={() => ({
page: 'dashboard',
url: window.location.pathname,
selectedItems: getSelectedItems(),
timestamp: new Date().toISOString(),
})}
/>
The function is called every time the user sends a message, ensuring the AI gets current information.
Key Point: Context is a read-only state snapshot. The AI can see this data but cannot execute functions or modify state. For actions that change your application, use Tools.
Context vs Tools
Understanding the distinction is important:
| Feature | Context | Tools |
|---|---|---|
| Purpose | Provide read-only state snapshot | Execute actions and modify state |
| Passed via | context prop | tools prop |
| Type | Object or function returning object | Array of tool definitions with handlers |
| AI capability | Can read and reference data | Can call functions to take actions |
| Example | context={{ userName: 'Alice' }} | tools={[{ name: 'addTodo', handler: ... }]} |
Use context when: You want the AI to know about current application state (user info, page data, settings)
Use tools when: You want the AI to take actions (create, update, delete, trigger workflows)
Next Steps
- Tools - Learn how to enable the AI to take actions
- React Context Guide - Detailed implementation examples with code
- Getting Started - Build your first context-aware agent