Enhance your AI agent’s awareness with automatic contextual information
Context injection is a powerful system that automatically provides relevant information to your AI agent during conversations. This includes page metadata, user preferences, memories from previous interactions, and user click events—all injected seamlessly into the conversation flow.
Context injection is enabled by default to provide the best user experience. You can configure or disable specific features based on your needs.
Context injection works out of the box with sensible defaults:
Copy
import { SammyAgentProvider } from '@sammy-labs/sammy-three';// Context injection is enabled by default<SammyAgentProvider config={config}> {children}</SammyAgentProvider>
Formatted as a navigation event similar to click events
Tracked in observability events
Navigation events are now injected as [NAVIGATION_EVENT] messages when the URL changes, providing a more consistent experience with click events. The agent receives contextual information about the new page to provide appropriate assistance.
Advanced Click Detection Configuration:You can pass additional configuration to fine-tune click detection behavior:
Copy
const config = { auth: { /* ... */ }, contextInjection: true, // Uses default click detection settings clickDetection: { interactableOnly: true, // Only track truly interactive elements (default: true) debugLogs: false, // Enable debug logging (default: false) clickDebounceMs: 250, // Minimum time between clicks (default: 250ms) aggregationWindowMs: 500, // Time window to group clicks (default: 500ms) maxClicksPerWindow: 3, // Max clicks per aggregation window (default: 3) significantClicksOnly: false // Only track significant clicks (default: false) }};
The interactableOnly setting ensures only meaningful clicks are tracked. It filters clicks to elements like buttons, links, inputs, and elements with click handlers or ARIA roles. This reduces noise and improves the quality of context provided to the AI.
What Elements Are Considered Interactable?When interactableOnly is true (default), the system tracks clicks on:
HTML Elements
<a>, <button>, <input>
<select>, <textarea>, <label>
<details>, <summary>, <menu>
<embed>, <object>, <menuitem>
ARIA Roles
button, link, checkbox, radio
tab, menuitem, option, switch
slider, textbox, combobox
progressbar, scrollbar, tree
Additional criteria for interactable elements:
Elements with tabindex (except -1)
Elements with click handlers (onclick, @click, ng-click, etc.)
Elements with ARIA properties (aria-expanded, aria-pressed, etc.)
Draggable elements (draggable="true")
Content-editable elements (contenteditable)
The system also traverses up the DOM tree to find interactable parent elements, so clicks on button text or icons are properly captured.
Symptoms: No memories being found or injectedCheck:
Ensure memorySearch is enabled
Verify input meets minimum length (20 chars)
Check API connection to memory service
Look for duplicate memory filtering logs
Solution:
Copy
contextInjection: { enabled: true, memorySearch: true // Must be enabled}
Symptoms: Slow response times or high latencyCheck:
Consider disabling unused features
Monitor injection event frequency
Check memory search result counts
Solution:
Copy
// Optimize for performancecontextInjection: { enabled: true, memorySearch: false, // Disable if not needed pageTracking: true, clickTracking: false // Disable if not needed}
Context injection provides intelligent, automatic context management that enhances your AI agent’s responses. With flexible configuration options, you can optimize for your specific use case—whether you need full contextual awareness for complex interactions or a lightweight setup for simple queries.
Remember: Context injection is enabled by default because it significantly improves the quality of AI responses. Only disable features that you’re certain you don’t need.