Skip to main content
The Guides System provides a composable hook architecture that integrates directly into the SammyAgentProvider for seamless walkthrough experiences.
Performance Update: Guides now use lazy loading to reduce API calls. User guides are only fetched when components call refreshUserGuides(), not automatically on initialization. This prevents unnecessary API load from users who never interact with guides. Always call refreshUserGuides() in components that display guides.

Architecture Overview

Clean Architecture

The guides system uses a hook-based composition pattern that integrates directly into the main provider:
  • No nested contexts - Integrated directly into main provider
  • Hook composition - Clean separation of concerns
  • Zero overhead - Returns null when disabled
  • Type-safe - Full TypeScript support

Data Flow

Quick Start

Basic Setup

URL-Based Activation

Guides can be automatically triggered via URL parameters, perfect for sharing specific walkthroughs or onboarding flows:
When autoStartFromURL is enabled, the guide will automatically start when the page loads with the appropriate query parameter.

Guide Lifecycle

Manage the complete lifecycle of guides from initialization to completion:

Initialization

Manual Start

URL Detection

Progress Tracking

Data Refresh

Cleanup

Core Components

GuidesService

The service layer handles all API communication and transforms snake_case responses to camelCase.

useGuides Hook

Provides always-on guide data with automatic fetching:

Features

URL-Based Walkthrough Activation

1

User Visits URL

User visits: https://app.com?walkthrough=guide-123
2

Parameter Detection

GuidesProvider detects the parameter
3

Guide Fetching

Guide is fetched automatically
4

Auto-Start

If autoStartFromURL=true, agent starts with guide context
5

URL Cleanup

URL parameter is cleaned up
6

Completion Tracking

Guide marked as completed on conversation start

Guide Discovery & Listing

Manual Walkthrough Triggering

Progress Tracking

Automatic Completion

Guides automatically track completion:
  • Marked complete when conversation starts with guide
  • Optimistic UI updates (immediate visual feedback)
  • Persistent across sessions (backend storage)

Query Parameter Detection

Configuration Options

Usage Examples

Share Walkthrough

Email Campaign

Programmatic Navigation

Manual URL Check

Advanced Features

Implementation Details

Conditional Provider Wrapping

The system uses a clever pattern to conditionally wrap providers without nesting:

Dependency Injection for Agent Start

Optimistic Updates

Immediate UI Feedback

Guide completion is updated optimistically for better UX:

API Reference

Provider Props

Context API

Service Endpoints

Complete Example

Performance & Best Practices

Zero-Cost When Disabled

When guides={false}:
  • No GuidesProvider rendered
  • No API calls made
  • No state management overhead
  • No event listeners attached

Memoization

All expensive operations are memoized:

Automatic Cleanup

Resources are properly cleaned up:

TypeScript Best Practices

Use null checks for type safety:

Security Considerations

Always validate guide IDs on the backend:
  • Check if guide exists
  • Verify user permissions
  • Validate organization access

URL Parameter Sanitization

The system automatically:
  • Sanitizes guide IDs before use
  • Prevents XSS through parameter injection
  • Cleans up parameters after processing

Troubleshooting

Common Issues

Troubleshooting Steps:
  1. Check if guides={true} is set
  2. Verify autoStartFromURL={true} for automatic start
  3. Ensure guide ID exists and user has access
  4. Enable debug mode to see detailed logs

Summary

The Sammy-Three Guides System provides a robust, performant, and developer-friendly solution for implementing guided experiences. Its clean architecture, type safety, and zero-overhead design make it an excellent choice for applications requiring tutorial or walkthrough functionality.
Key takeaways:
  • Clean Architecture: Separated concerns with proper layering
  • Performance First: Zero cost when disabled
  • Developer Experience: Full TypeScript support and simple API
  • User Experience: Seamless URL-based activation and progress tracking
  • Extensible: Easy to add new features without breaking existing functionality