Hydra AI

V 0.1.0 Coming Soon

These are draft docs for the upcoming 0.1.0 release. Read more about the upcoming release here. Have a question about anything in the docs? Send us a message.

User Profiles

Store and manage user-specific information to personalize AI interactions.

User profiles in Hydra AI allow you to store and manage user-specific information that helps personalize AI interactions. This feature enables maintaining context about users across sessions and improving the AI's ability to provide relevant responses.

Profile Structure

Each user profile contains:

interface HydraStoredProfile {
  userId: string; // Unique user identifier
  profile: string; // Text description about the user to help the AI
  updatedAt: string; // ISO timestamp of last update
}

Using Profiles

The useHydraProfile Hook

The useHydraProfile hook provides easy access to profile operations:

const {
  profile, // Current profile data
  operations, // Profile operations
  status, // Loading and error states
} = useHydraProfile(userId);

Available Operations

// Fetch a user's profile
const profile = await operations.get(userId);
 
// Update a user's profile
await operations.update(userId, "New profile information");
 
// Delete a user's profile
await operations.delete(userId);
 
// List all profiles
const profiles = await operations.list();
 
// Refresh profile data
await operations.refresh();

Status Management

The profile system includes built-in status tracking:

const { status } = useHydraProfile(userId);
 
// Check loading state
if (status.isLoading) {
  // Show loading indicator
}
 
// Handle errors
if (status.error) {
  // Display error message
}

Global Profile Management

Through the main Hydra context, you can access all profile functionality:

const { profiles } = useHydraContext();
 
// Access all stored profiles
const allProfiles = profiles.items;
 
// Check global profile status
const { isLoading, error } = profiles.status;
 
// Perform operations
await profiles.operations.update(userId, newProfileData);

Best Practices

  1. Profile Content: Store relevant user preferences, interaction history, and context that can help the AI provide better responses.

  2. Updates: Keep profiles up-to-date by calling update when significant user preferences or context changes occur.

  3. Error Handling: Always check the status object when performing profile operations to handle loading states and errors gracefully.

  4. Privacy: Only store necessary information and ensure compliance with privacy regulations.

Example Usage

function UserProfileManager({ userId }: { userId: string }) {
  const { profile, operations, status } = useHydraProfile(userId);
 
  const updateProfile = async (newData: string) => {
    try {
      await operations.update(userId, newData);
    } catch (error) {
      console.error('Failed to update profile:', error);
    }
  };
 
  if (status.isLoading) {
    return <div>Loading profile...</div>;
  }
 
  if (status.error) {
    return <div>Error: {status.error.message}</div>;
  }
 
  return (
    <div>
      <h2>User Profile</h2>
      {profile ? (
        <>
          <div>Last Updated: {profile.updatedAt}</div>
          <div>Profile Data: {profile.profile}</div>
        </>
      ) : (
        <div>No profile found</div>
      )}
    </div>
  );
}

On this page