User Context

Adding User Context to doable.sh operators

The UserContext component from the Doable AI SDK allows you to programmatically send user details to the operator. By providing user-specific information, you enable advanced personalization and enhance the relevance of AI-driven tasks.

Why Use UserContext?

Integrating user data through UserContext significantly improves the operator's ability to respond with personalized and context-aware answers. This is especially important when the operator's actions depend on who the user is or their role within the system.

Key Benefits:

  • Enables personalized interactions.
  • Enhances relevancy when completing tasks.
  • Supports advanced use cases where user identity affects responses.

Installation and Setup

Make sure you have the Doable AI SDK installed:

npm install @doable.sh/sdk  
pnpm i @doable.sh/sdk  
yarn add @doable.sh/sdk  

Next, import the component in your React app:

import { UserContext } from '@doable.sh/sdk'  

Basic Usage of UserContext

The UserContext component is designed to wrap user information that can be programmatically passed to the operator.

Example:

<UserContext  
    id={session?.user?.id}  
    email={session?.user?.email}  
    name={session?.user?.name}  
/>  

Explanation:

  • id: The unique identifier of the user (usually from your authentication system).
  • email: The user's email address for direct identification.
  • name: The display name of the user, which the operator can use to personalize responses.

Use Cases for UserContext

1. Personalized Greetings

Imagine an AI assistant that greets users by name:

  • Without UserContext: "Welcome back!"
  • With UserContext: "Welcome back, Cameron!"

By using the UserContext component, the operator knows the user's name and can tailor the greeting accordingly.

2. Role-Based Access

If your application has roles like "Admin" or "Viewer," you can customize the AI’s responses based on the user's role.
Example:

  • Admins receive configuration options, while viewers only see reports.

3. Task Customization

Some tasks might vary based on who is performing them.
Example:

  • An AI that fills out a form with user-specific details, like their name or department.
  • An operator that fetches a user’s recent activities or personalized dashboard.

Implementing UserContext with TaskDefinition

You can combine UserContext and TaskDefinition to make tasks more relevant.
Example:

<UserContext  
    id={session?.user?.id}  
    email={session?.user?.email}  
    name={session?.user?.name}  
/>  
 
<TaskDefinition  
    id="personalized-welcome"  
    name="Welcome User"  
    description="Greet the user with their name and recent activity"  
    steps={[  
        "Display a personalized welcome message using the user's name",  
        "List the recent tasks completed by the user",  
        "Show recommended next steps based on the user's role"  
    ]}  
/>  

Best Practices

  1. Ensure Data Accuracy: Always pass up-to-date user information to avoid irrelevant responses.
  2. Secure User Data: Handle sensitive information responsibly and never expose user credentials.
  3. Personalize Responsibly: Be mindful of the context where personal information is used to avoid unnecessary exposure.
  4. Combine with TaskDefinition: Use UserContext with TaskDefinition to create context-rich, user-specific workflows.

Summary

The UserContext component is an essential tool for adding user-specific context to your AI operator. By integrating user data, you unlock advanced personalization and relevancy, making tasks more meaningful and accurate.

By combining UserContext with TaskDefinition and startTask, you create a highly interactive and customized experience that adapts to each user. Leverage this capability to build smarter and more user-friendly applications with doable.sh.