426 lines
15 KiB
Markdown
426 lines
15 KiB
Markdown
# 🎯 Content Hyper-Personalization Implementation Strategy
|
|
|
|
## 📋 Overview
|
|
|
|
This document outlines ALwrity's approach to achieving true content hyper-personalization by leveraging the **Writing Persona System (PR #226)** and integrating it with CopilotKit's context-aware conversation capabilities. The goal is to create intelligent, contextual interactions that understand each user's unique **platform-specific persona** and adapt content generation accordingly.
|
|
|
|
## 🚀 **Core Innovation: Platform-Specific Persona-Driven Context Integration**
|
|
|
|
### **1. Writing Persona System Foundation (PR #226) ✅ IMPLEMENTED**
|
|
- **Gemini-powered persona analysis** from onboarding data ✅
|
|
- **Platform-specific persona adaptations** for different social platforms (LinkedIn, Facebook, Instagram, Twitter, Blog, Medium, Substack) ✅
|
|
- **"Hardened" prompts** for consistent AI output ✅
|
|
- **Objective, measurable instructions** instead of subjective descriptions ✅
|
|
- **Platform-specific writing styles, content strategies, and engagement patterns** ✅
|
|
- **Complete database schema** with 4 tables ✅
|
|
- **Full API endpoints** for persona management ✅
|
|
- **Frontend API client** with TypeScript interfaces ✅
|
|
|
|
### **2. CopilotKit Context Integration** 🔨 **NEXT STEP**
|
|
- **useCopilotReadable** hook for platform-specific persona context injection
|
|
- **Platform-aware context structure** that understands different social network requirements
|
|
- **Real-time persona context updates** as user preferences evolve
|
|
- **Platform-specific CopilotKit actions** tailored to each social network's unique needs
|
|
|
|
## 🏗️ **Architecture Overview - IMPLEMENTED STATUS**
|
|
|
|
### **Backend System ✅ COMPLETE**
|
|
```
|
|
backend/
|
|
├── models/
|
|
│ └── persona_models.py // ✅ Complete database schema
|
|
├── services/
|
|
│ ├── persona_analysis_service.py // ✅ Gemini-powered analysis
|
|
│ └── persona_replication_engine.py // ✅ Content generation engine
|
|
├── api/
|
|
│ ├── persona.py // ✅ Full API endpoints
|
|
│ └── persona_routes.py // ✅ Route definitions
|
|
├── scripts/
|
|
│ └── create_persona_tables.py // ✅ Database setup
|
|
└── deploy_persona_system.py // ✅ Deployment script
|
|
```
|
|
|
|
### **Frontend API Client ✅ COMPLETE**
|
|
```
|
|
frontend/src/api/
|
|
└── persona.ts // ✅ Complete API client
|
|
├── TypeScript interfaces // ✅ All data models
|
|
├── API functions // ✅ All endpoints
|
|
├── Error handling // ✅ Comprehensive
|
|
└── Platform support // ✅ 7 platforms
|
|
```
|
|
|
|
### **What We Need to Build 🔨**
|
|
```
|
|
frontend/src/
|
|
├── components/
|
|
│ └── shared/
|
|
│ └── PersonaContext/
|
|
│ ├── PlatformPersonaProvider.tsx // 🔨 Build this
|
|
│ ├── usePlatformPersonaContext.ts // 🔨 Build this
|
|
│ └── PlatformPersonaTypes.ts // 🔨 Build this
|
|
├── hooks/
|
|
│ └── usePlatformPersonaCopilot.ts // 🔨 Build this
|
|
└── services/
|
|
└── copilotkit/
|
|
└── PlatformActions/ // 🔨 Build this
|
|
```
|
|
|
|
## 🎨 **Implementation Strategy - UPDATED**
|
|
|
|
### **Phase 1: React Context Layer (Week 1) 🔨 BUILD THIS**
|
|
|
|
#### **1.1 Create Platform Persona Types (Days 1-2)**
|
|
```typescript
|
|
// Create: frontend/src/types/PlatformPersonaTypes.ts
|
|
// Map the existing backend models to TypeScript
|
|
export interface WritingPersona {
|
|
id: number;
|
|
persona_name: string;
|
|
archetype: string;
|
|
core_belief: string;
|
|
linguistic_fingerprint: LinguisticFingerprint;
|
|
platform_adaptations: PlatformAdaptation[];
|
|
confidence_score: number;
|
|
created_at: string;
|
|
}
|
|
|
|
export interface LinguisticFingerprint {
|
|
sentence_metrics: {
|
|
average_sentence_length_words: number;
|
|
preferred_sentence_type: string;
|
|
active_to_passive_ratio: string;
|
|
};
|
|
lexical_features: {
|
|
go_to_words: string[];
|
|
go_to_phrases: string[];
|
|
avoid_words: string[];
|
|
vocabulary_level: string;
|
|
};
|
|
rhetorical_devices: {
|
|
metaphors: string;
|
|
analogies: string;
|
|
rhetorical_questions: string;
|
|
};
|
|
}
|
|
|
|
export interface PlatformAdaptation {
|
|
platform_type: "twitter" | "linkedin" | "instagram" | "facebook" | "blog" | "medium" | "substack";
|
|
sentence_metrics: PlatformSentenceMetrics;
|
|
lexical_features: PlatformLexicalFeatures;
|
|
content_format_rules: ContentFormatRules;
|
|
engagement_patterns: EngagementPatterns;
|
|
}
|
|
```
|
|
|
|
#### **1.2 Create Platform Persona Provider (Days 3-4)**
|
|
```typescript
|
|
// Create: frontend/src/components/shared/PersonaContext/PlatformPersonaProvider.tsx
|
|
import { getPlatformPersona, getUserPersonas } from '../../../api/persona';
|
|
|
|
export const PlatformPersonaProvider: React.FC<{
|
|
platform: SocialPlatform;
|
|
children: React.ReactNode
|
|
}> = ({ platform, children }) => {
|
|
const [platformPersona, setPlatformPersona] = useState<PlatformAdaptation | null>(null);
|
|
const [corePersona, setCorePersona] = useState<WritingPersona | null>(null);
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
useEffect(() => {
|
|
const fetchPersonas = async () => {
|
|
try {
|
|
setLoading(true);
|
|
const userId = 1; // Get from auth context
|
|
|
|
// Use the existing API client
|
|
const [userPersonas, platformData] = await Promise.all([
|
|
getUserPersonas(userId),
|
|
getPlatformPersona(userId, platform)
|
|
]);
|
|
|
|
setCorePersona(userPersonas.personas[0]);
|
|
setPlatformPersona(platformData);
|
|
} catch (error) {
|
|
console.error('Error fetching personas:', error);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
fetchPersonas();
|
|
}, [platform]);
|
|
|
|
// Inject both personas into CopilotKit context
|
|
useCopilotReadable({
|
|
description: `Core writing persona: ${corePersona?.persona_name || 'Loading...'}`,
|
|
value: corePersona,
|
|
categories: ["core-persona", "writing-style"]
|
|
});
|
|
|
|
useCopilotReadable({
|
|
description: `${platform} platform optimization rules`,
|
|
value: platformPersona,
|
|
categories: ["platform-persona", platform],
|
|
parentId: corePersona?.id
|
|
});
|
|
|
|
if (loading) {
|
|
return <div>Loading persona data...</div>;
|
|
}
|
|
|
|
return (
|
|
<PlatformPersonaContext.Provider value={{
|
|
corePersona,
|
|
platformPersona,
|
|
platform,
|
|
loading
|
|
}}>
|
|
{children}
|
|
</PlatformPersonaContext.Provider>
|
|
);
|
|
};
|
|
```
|
|
|
|
#### **1.3 Create Platform Persona Context Hook (Days 5-7)**
|
|
```typescript
|
|
// Create: frontend/src/hooks/usePlatformPersonaContext.ts
|
|
import { useContext } from 'react';
|
|
import { PlatformPersonaContext } from '../components/shared/PersonaContext/PlatformPersonaContext';
|
|
|
|
export const usePlatformPersonaContext = () => {
|
|
const context = useContext(PlatformPersonaContext);
|
|
if (!context) {
|
|
throw new Error('usePlatformPersonaContext must be used within PlatformPersonaProvider');
|
|
}
|
|
return context;
|
|
};
|
|
```
|
|
|
|
### **Phase 2: CopilotKit Integration (Week 2)**
|
|
|
|
#### **2.1 Create Persona-Aware Chat Component (Days 1-4)**
|
|
```typescript
|
|
// Create: frontend/src/components/shared/CopilotKit/PlatformPersonaChat.tsx
|
|
export const PlatformPersonaChat: React.FC<{
|
|
platform: SocialPlatform;
|
|
corePersona: WritingPersona;
|
|
platformPersona: PlatformAdaptation;
|
|
}> = ({ platform, corePersona, platformPersona }) => {
|
|
|
|
const makeSystemMessage = useCallback((contextString: string) => {
|
|
return `
|
|
You are an expert ${platform} content strategist and writer.
|
|
|
|
CORE PERSONA CONTEXT:
|
|
${contextString}
|
|
|
|
PERSONA: ${corePersona.persona_name}
|
|
ARCHETYPE: ${corePersona.archetype}
|
|
CORE BELIEF: ${corePersona.core_belief}
|
|
CONFIDENCE SCORE: ${corePersona.confidence_score}%
|
|
|
|
PLATFORM OPTIMIZATION (${platform}):
|
|
- Platform: ${platformPersona.platform_type}
|
|
- Character Limit: ${platformPersona.content_format_rules?.character_limit || 'Unknown'}
|
|
- Optimal Length: ${platformPersona.content_format_rules?.optimal_length || 'Unknown'}
|
|
- Engagement Pattern: ${platformPersona.engagement_patterns?.posting_frequency || 'Unknown'}
|
|
|
|
LINGUISTIC CONSTRAINTS:
|
|
- Sentence Length: ${corePersona.linguistic_fingerprint?.sentence_metrics?.average_sentence_length_words || 'Unknown'} words average
|
|
- Voice Ratio: ${corePersona.linguistic_fingerprint?.sentence_metrics?.active_to_passive_ratio || 'Unknown'}
|
|
- Go-to Words: ${corePersona.linguistic_fingerprint?.lexical_features?.go_to_words?.join(", ") || 'Unknown'}
|
|
- Avoid Words: ${corePersona.linguistic_fingerprint?.lexical_features?.avoid_words?.join(", ") || 'Unknown'}
|
|
|
|
Always generate content that matches this persona's linguistic fingerprint and platform optimization rules.
|
|
`;
|
|
}, [corePersona, platformPersona, platform]);
|
|
|
|
return (
|
|
<CopilotChat
|
|
makeSystemMessage={makeSystemMessage}
|
|
actions={getPlatformSpecificActions(platform, platformPersona)}
|
|
/>
|
|
);
|
|
};
|
|
```
|
|
|
|
#### **2.2 Create Platform-Specific Actions (Days 5-7)**
|
|
```typescript
|
|
// Create: frontend/src/services/copilotkit/PlatformActions/LinkedInActions.ts
|
|
import { generateContentWithPersona } from '../../../api/persona';
|
|
|
|
export const getLinkedInActions = (platformPersona: PlatformAdaptation) => ({
|
|
generateLinkedInPost: {
|
|
name: "generateLinkedInPost",
|
|
description: "Generate LinkedIn post using persona replication engine",
|
|
parameters: [
|
|
{
|
|
name: "topic",
|
|
type: "string",
|
|
description: "Main topic or theme for the post"
|
|
}
|
|
],
|
|
handler: async (args: any) => {
|
|
const userId = 1; // Get from auth context
|
|
const result = await generateContentWithPersona(
|
|
userId,
|
|
"linkedin",
|
|
args.topic,
|
|
"post"
|
|
);
|
|
return result;
|
|
}
|
|
}
|
|
});
|
|
```
|
|
|
|
### **Phase 3: Platform Editor Integration (Week 3)**
|
|
|
|
#### **3.1 Integrate with LinkedIn Editor (Days 1-4)**
|
|
```typescript
|
|
// Update: frontend/src/components/LinkedInWriter/LinkedInWriter.tsx
|
|
export const LinkedInWriter: React.FC = () => {
|
|
return (
|
|
<PlatformPersonaProvider platform="linkedin">
|
|
<LinkedInWriterContent />
|
|
</PlatformPersonaProvider>
|
|
);
|
|
};
|
|
|
|
const LinkedInWriterContent: React.FC = () => {
|
|
const { corePersona, platformPersona } = usePlatformPersonaContext();
|
|
|
|
return (
|
|
<div>
|
|
{/* Existing LinkedIn editor */}
|
|
<LinkedInEditor />
|
|
|
|
{/* Persona-aware chat */}
|
|
<PlatformPersonaChat
|
|
platform="linkedin"
|
|
corePersona={corePersona}
|
|
platformPersona={platformPersona}
|
|
/>
|
|
|
|
{/* Display persona information */}
|
|
<PersonaInfoDisplay
|
|
persona={corePersona}
|
|
platformOptimization={platformPersona}
|
|
/>
|
|
</div>
|
|
);
|
|
};
|
|
```
|
|
|
|
## 🔍 **What PR #226 Already Implements**
|
|
|
|
### **1. Complete Backend System ✅**
|
|
- **Database Schema**: 4 tables with full relationships
|
|
- **Gemini Integration**: AI-powered persona analysis
|
|
- **Platform Support**: 7 platforms with specific constraints
|
|
- **API Endpoints**: Full CRUD operations for personas
|
|
- **Content Generation**: Persona replication engine
|
|
- **Export System**: Hardened prompts for external tools
|
|
|
|
### **2. Complete Frontend API Client ✅**
|
|
- **TypeScript Interfaces**: All data models defined
|
|
- **API Functions**: All endpoints implemented
|
|
- **Error Handling**: Comprehensive error management
|
|
- **Platform Support**: All 7 platforms supported
|
|
|
|
### **3. Integration Points ✅**
|
|
- **Onboarding Integration**: Automatic persona generation
|
|
- **Database Integration**: Full persistence layer
|
|
- **API Integration**: RESTful endpoints ready
|
|
|
|
## 🎯 **What We Need to Build (React Integration Layer)**
|
|
|
|
### **1. React Context System 🔨**
|
|
- **PlatformPersonaProvider**: Context provider for persona data
|
|
- **usePlatformPersonaContext**: Hook for accessing persona data
|
|
- **State Management**: Loading states and error handling
|
|
|
|
### **2. CopilotKit Integration 🔨**
|
|
- **Context Injection**: Inject persona data into CopilotKit
|
|
- **System Messages**: Dynamic system messages with persona context
|
|
- **Platform Actions**: Platform-specific CopilotKit actions
|
|
|
|
### **3. Editor Integration 🔨**
|
|
- **LinkedIn Editor**: Integrate persona context
|
|
- **Facebook Editor**: Integrate persona context
|
|
- **Other Editors**: Extend to remaining platforms
|
|
|
|
## 🚀 **Updated Implementation Roadmap**
|
|
|
|
### **Week 1: React Context Layer** 🔨
|
|
- [ ] **Create TypeScript interfaces** mapping backend models
|
|
- [ ] **Create PlatformPersonaProvider** component
|
|
- [ ] **Create usePlatformPersonaContext** hook
|
|
- [ ] **Test persona data fetching** with existing API client
|
|
|
|
### **Week 2: CopilotKit Integration** 🔨
|
|
- [ ] **Create PlatformPersonaChat** component
|
|
- [ ] **Test persona context injection** into CopilotKit
|
|
- [ ] **Create platform-specific actions** using existing API
|
|
- [ ] **Verify platform-specific constraints** are accessible
|
|
|
|
### **Week 3: Platform Editor Integration** 🔨
|
|
- [ ] **Integrate with LinkedIn editor**
|
|
- [ ] **Integrate with Facebook editor**
|
|
- [ ] **Test end-to-end** platform-personalized content generation
|
|
- [ ] **Add persona display components**
|
|
|
|
## 🎉 **Key Benefits of PR #226 Implementation**
|
|
|
|
### **1. Production-Ready Backend**
|
|
- **Complete database schema** with relationships
|
|
- **Gemini AI integration** for persona analysis
|
|
- **Platform-specific optimizations** for 7 platforms
|
|
- **Content generation engine** with persona constraints
|
|
|
|
### **2. Production-Ready Frontend API**
|
|
- **Complete TypeScript interfaces** for all data models
|
|
- **Full API client** with all endpoints
|
|
- **Error handling** and type safety
|
|
- **Platform support** for all 7 platforms
|
|
|
|
### **3. Enterprise Features**
|
|
- **Hardened persona prompts** for consistent output
|
|
- **Export functionality** for external AI tools
|
|
- **Quality validation** with confidence scores
|
|
- **Scalable architecture** for multiple users
|
|
|
|
## **Immediate Action Items (This Week)**
|
|
|
|
### **Day 1-2: Create TypeScript Interfaces**
|
|
1. **Map backend models** to TypeScript interfaces
|
|
2. **Create PlatformPersonaTypes.ts** file
|
|
3. **Test type compatibility** with existing API client
|
|
|
|
### **Day 3-4: Create Context Provider**
|
|
1. **Create PlatformPersonaProvider** component
|
|
2. **Integrate with existing API client**
|
|
3. **Test persona data fetching**
|
|
|
|
### **Day 5-7: Create Context Hook**
|
|
1. **Create usePlatformPersonaContext** hook
|
|
2. **Test context consumption**
|
|
3. **Verify data flow** from API to components
|
|
|
|
## 🎯 **Conclusion**
|
|
|
|
**PR #226 has delivered a complete, production-ready Writing Persona System:**
|
|
- ✅ **Backend**: Full persona system with Gemini AI
|
|
- ✅ **Frontend API**: Complete client with all endpoints
|
|
- ✅ **Database**: Complete schema with relationships
|
|
- ✅ **Platform Support**: 7 platforms with specific optimizations
|
|
|
|
**We just need to build the React integration layer:**
|
|
- 🔨 **React Context** for state management
|
|
- 🔨 **CopilotKit Integration** for context injection
|
|
- 🔨 **Editor Integration** for platform-specific personalization
|
|
|
|
This is **exactly what we need** for true content hyper-personalization! The heavy lifting is complete. We just need to build the React integration layer to connect everything together and unlock the full potential of the persona system with CopilotKit.
|
|
|
|
The system is sophisticated, well-architected, and ready for production. Once we complete the React integration layer, ALwrity will have enterprise-grade content hyper-personalization capabilities that understand each user's unique writing style and optimize content for each platform's specific requirements.
|