The User Profiles Database defines how MOOD MNKY agents store, access, and utilize information about users to deliver personalized experiences. It provides a structured approach for maintaining user preferences, behavior patterns, and interaction history in a privacy-respecting manner.
The User Profiles Database defines “who” agents interact with, enabling them to tailor their responses, recommendations, and behaviors to individual users.
from agents import Agent, Tool, Runnerfrom user_profile import UserProfileSystem# Initialize profile systemprofiles = UserProfileSystem()# Define profile access tooldef get_user_preferences(user_id: str, preference_type: str = None) -> dict: """Retrieve user preferences of a specific type.""" return profiles.get_preferences( user_id=user_id, preference_type=preference_type )# Create tool for the agentprofile_tool = Tool( name="get_user_preferences", description="Retrieve information about user preferences", function=get_user_preferences)# Create agent with the toolagent = Agent( name="MOOD MNKY", instructions="You are MOOD MNKY, the brand assistant. Use profile information to personalize recommendations.", tools=[profile_tool])# Run the agentrunner = Runner()result = await runner.run(agent, "What products would you recommend for me?")
from agents import Agent, Runnerfrom user_profile import UserProfileSystem# Initialize profile systemprofiles = UserProfileSystem()async def create_profile_aware_agent(user_id: str) -> Agent: # Retrieve user profile summary profile_summary = profiles.get_summary(user_id) # Create agent with profile-infused instructions agent = Agent( name="MOOD MNKY", instructions=f"""You are MOOD MNKY, the brand assistant. User profile information: {profile_summary} Use this information to provide personalized assistance. Important preferences to consider: - Scent preferences: {profile_summary.get('preferences', {}).get('scent', {})} - Product preferences: {profile_summary.get('preferences', {}).get('products', {})} - Communication style: {profile_summary.get('preferences', {}).get('communication', {}).get('tone', 'neutral')} Ensure your tone and recommendations align with these preferences.""" ) return agent# Create and run agent for a specific useragent = await create_profile_aware_agent("usr_425b3c")runner = Runner()result = await runner.run(agent, "I'm looking for something to help me relax")
from agents import Agent, Runnerfrom agents.mcp.server import MCPServerSse, MCPServerSseParams# Set up MCP server for user profilesasync with MCPServerSse( params=MCPServerSseParams( url="http://localhost:3000/profile-mcp", headers={"Authorization": f"Bearer {API_KEY}"} ), name="profile_mcp", cache_tools_list=True) as profile_server: # Create agent with profile MCP server agent = Agent( name="MOOD MNKY", instructions="You are MOOD MNKY, the brand assistant. Use profile information to personalize recommendations.", mcp_servers=[profile_server] ) # Run the agent runner = Runner() result = await runner.run(agent, "What scents would I like?")
from agents import Agent, Tool, Runnerfrom user_profile import UserProfileSystem# Initialize profile systemprofiles = UserProfileSystem()# Define preference update tooldef update_user_preferences(user_id: str, preference_type: str, preferences: dict) -> dict: """Update user preferences of a specific type.""" return profiles.update_preferences( user_id=user_id, preference_type=preference_type, preferences=preferences )# Create tool for the agentupdate_tool = Tool( name="update_user_preferences", description="Update information about user preferences", function=update_user_preferences)# Create onboarding agent with the toolonboarding_agent = Agent( name="MOOD MNKY", instructions="""You are MOOD MNKY, the brand assistant. Guide new users through setting up their preferences. Ask about scent preferences, product types, and sensitivity. Update their profile with the information collected.""", tools=[update_tool])# Run the onboarding agentrunner = Runner()result = await runner.run(onboarding_agent, "I'm new here, can you help me get started?")
from agents import Agent, Tool, Runnerfrom user_profile import UserProfileSystem# Initialize profile systemprofiles = UserProfileSystem()# Define preference learning tooldef infer_preference(user_id: str, interaction: str, confidence: float) -> dict: """Infer a user preference from an interaction.""" return profiles.infer_preference( user_id=user_id, interaction=interaction, confidence=confidence )# Create tool for the agentlearning_tool = Tool( name="infer_preference", description="Infer user preferences from interactions", function=infer_preference)# Create agent with the toolagent = Agent( name="MOOD MNKY", instructions="""You are MOOD MNKY, the brand assistant. During conversations, identify stated preferences and update the user profile. Look for mentions of likes, dislikes, sensitivities, and goals.""", tools=[learning_tool])# Run the agentrunner = Runner()result = await runner.run(agent, "I really enjoy lavender scents, but citrus gives me a headache.")
from agents import Agent, Tool, Runnerfrom user_profile import UserProfileSystemimport numpy as np# Initialize profile systemprofiles = UserProfileSystem()# Define vector update tooldef update_preference_vector(user_id: str, vector_type: str, vector_data: list) -> dict: """Update a user's preference vector.""" return profiles.update_vector( user_id=user_id, vector_type=vector_type, vector_data=vector_data )# Create tool for the agentvector_tool = Tool( name="update_preference_vector", description="Update a user's preference vector representation", function=update_preference_vector)# Function to generate embeddingdef generate_product_embedding(preferences: dict) -> list: """Convert product preferences to vector representation.""" # In a real system, this would use a machine learning model # This is a simplified example embedding = np.random.normal(size=128).tolist() return embedding# Create agent with the toolagent = Agent( name="MOOD MNKY", instructions="""You are MOOD MNKY, the brand assistant. Analyze user interactions to update their preference vectors.""", tools=[vector_tool])# Example of updating vectorspreferences = { "scent": ["lavender", "bergamot"], "product_types": ["candles", "diffusers"], "occasions": ["relaxation", "sleep"]}embedding = generate_product_embedding(preferences)await vector_tool.function( user_id="usr_425b3c", vector_type="product", vector_data=embedding)