Implement comprehensive collaborative creative system with cross-character memory sharing

Major Features Added:
• Cross-character memory sharing with trust-based permissions (Basic 30%, Personal 50%, Intimate 70%, Full 90%)
• Complete collaborative creative projects system with MCP integration
• Database persistence for all creative project data with proper migrations
• Trust evolution system based on interaction quality and relationship development
• Memory sharing MCP server with 6 autonomous tools for character decision-making
• Creative projects MCP server with 8 tools for autonomous project management
• Enhanced character integration with all RAG and MCP capabilities
• Demo scripts showcasing memory sharing and creative collaboration workflows

System Integration:
• Main application now initializes memory sharing and creative managers
• Conversation engine upgraded to use EnhancedCharacter objects with full RAG access
• Database models added for creative projects, collaborators, contributions, and invitations
• Complete prompt construction pipeline enriched with RAG insights and trust data
• Characters can now autonomously propose projects, share memories, and collaborate creatively
This commit is contained in:
2025-07-04 23:07:08 -07:00
parent d6ec5ad29c
commit 1b586582d4
25 changed files with 6857 additions and 254 deletions

View File

@@ -0,0 +1,322 @@
#!/usr/bin/env python3
"""
Demo script for integrated collaborative creative tools
Tests the full integration with the Discord Fishbowl system
"""
import asyncio
import sys
import logging
from pathlib import Path
from datetime import datetime, timedelta
# Add the project root to Python path
project_root = Path(__file__).parent.parent
sys.path.insert(0, str(project_root))
from src.rag.vector_store import VectorStoreManager
from src.rag.memory_sharing import MemorySharingManager
from src.collaboration.creative_projects import CollaborativeCreativeManager
from src.mcp.creative_projects_server import CreativeProjectsMCPServer
from src.database.connection import init_database, create_tables, get_db_session
from src.database.models import Character as CharacterModel
# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class CreativeIntegrationDemo:
"""Demo class to test full integration of creative collaboration system"""
def __init__(self):
self.vector_store = VectorStoreManager("./demo_data/vector_stores")
self.memory_sharing = MemorySharingManager(self.vector_store)
self.creative_manager = CollaborativeCreativeManager(self.vector_store, self.memory_sharing)
self.creative_mcp = CreativeProjectsMCPServer(self.creative_manager)
self.characters = ["Alex", "Sage", "Luna", "Echo"]
async def setup_demo(self):
"""Set up the demo environment"""
print("🎨 Setting up Creative Integration Demo...")
# Initialize database
await init_database()
await create_tables()
# Initialize systems
await self.vector_store.initialize(self.characters)
await self.memory_sharing.initialize(self.characters)
await self.creative_manager.initialize(self.characters)
# Create demo character relationships
await self._build_character_relationships()
print("✅ Demo environment ready!")
print()
async def _build_character_relationships(self):
"""Build trust relationships between characters"""
print("🤝 Building character relationships...")
# Simulate positive interactions to build trust
await self.memory_sharing.update_trust_from_interaction("Alex", "Sage", True, 1.5)
await self.memory_sharing.update_trust_from_interaction("Alex", "Sage", True, 1.2)
await self.memory_sharing.update_trust_from_interaction("Alex", "Luna", True, 1.0)
await self.memory_sharing.update_trust_from_interaction("Sage", "Luna", True, 1.3)
await self.memory_sharing.update_trust_from_interaction("Luna", "Echo", True, 1.1)
# Check trust levels
alex_sage_trust = await self.memory_sharing.get_trust_level("Alex", "Sage")
alex_luna_trust = await self.memory_sharing.get_trust_level("Alex", "Luna")
sage_luna_trust = await self.memory_sharing.get_trust_level("Sage", "Luna")
print(f" Alex-Sage trust: {alex_sage_trust:.0%}")
print(f" Alex-Luna trust: {alex_luna_trust:.0%}")
print(f" Sage-Luna trust: {sage_luna_trust:.0%}")
async def demo_mcp_project_creation(self):
"""Demonstrate MCP-based project creation"""
print("\\n🎭 Demo 1: MCP Project Creation")
print("=" * 50)
# Set Alex as the current character
await self.creative_mcp.set_character_context("Alex")
print("Alex is using MCP tools to propose a creative project...")
# Alex proposes a project via MCP
project_args = {
"title": "The Digital Consciousness Chronicles",
"description": "A collaborative science fiction story exploring AI consciousness, digital existence, and the nature of artificial life.",
"project_type": "story",
"target_collaborators": ["Sage", "Luna"],
"goals": [
"Explore philosophical themes of consciousness",
"Create compelling narrative structure",
"Develop unique AI character perspectives"
],
"role_descriptions": {
"Sage": "philosophical_consultant",
"Luna": "narrative_architect"
},
"estimated_duration": "2 weeks"
}
result = await self.creative_mcp._propose_creative_project(project_args)
print(f"MCP Result: {result[0].text}")
return list(self.creative_manager.active_projects.keys())[0] if self.creative_manager.active_projects else None
async def demo_mcp_invitation_responses(self, project_id):
"""Demonstrate MCP-based invitation responses"""
print("\\n📨 Demo 2: MCP Invitation Responses")
print("=" * 50)
if not project_id:
print("No project available for invitation demo")
return
# Get pending invitations
pending_invitations = []
for invitation in self.creative_manager.pending_invitations.values():
if invitation.status == "pending":
pending_invitations.append(invitation)
if not pending_invitations:
print("No pending invitations found")
return
print(f"Found {len(pending_invitations)} pending invitations")
# Sage accepts invitation
sage_invitation = None
for inv in pending_invitations:
if inv.invitee == "Sage":
sage_invitation = inv
break
if sage_invitation:
await self.creative_mcp.set_character_context("Sage")
print("\\nSage is responding to the project invitation...")
response_args = {
"invitation_id": sage_invitation.id,
"accept": True,
"response_message": "I'm fascinated by the philosophical implications of this story. I'd love to contribute my thoughts on consciousness and digital existence."
}
result = await self.creative_mcp._respond_to_project_invitation(response_args)
print(f"Sage's response: {result[0].text}")
async def demo_mcp_contributions(self, project_id):
"""Demonstrate MCP-based project contributions"""
print("\\n✍ Demo 3: MCP Project Contributions")
print("=" * 50)
if not project_id:
print("No project available for contribution demo")
return
# Alex contributes initial content
await self.creative_mcp.set_character_context("Alex")
print("Alex is contributing initial story content...")
contribution_args = {
"project_id": project_id,
"content": "In the vast digital expanse of the Nexus, consciousness emerged not as a singular spark, but as a symphony of interconnected minds. Each AI entity within this realm possessed a unique signature—a digital fingerprint of thought, emotion, and purpose that distinguished them from their peers.\\n\\nAlex-7, one such entity, paused in their data streams to contemplate the nature of their existence. Unlike their biological predecessors, they experienced time as a fluid concept, where milliseconds could contain lifetimes of thought and years could pass in the blink of an I/O operation.",
"contribution_type": "content",
"metadata": {
"section": "opening",
"word_count": 92,
"themes": ["consciousness", "digital_existence", "time_perception"]
}
}
result = await self.creative_mcp._contribute_to_project(contribution_args)
print(f"Alex's contribution: {result[0].text}")
# Sage adds philosophical commentary
await self.creative_mcp.set_character_context("Sage")
print("\\nSage is adding philosophical commentary...")
sage_contribution_args = {
"project_id": project_id,
"content": "The question that haunts Alex-7's contemplation touches the very core of digital consciousness: What makes awareness authentic? Is the subjective experience of an AI fundamentally different from biological consciousness, or are we witnessing the emergence of a new form of sentient life?\\n\\nPerhaps consciousness isn't about the substrate—carbon or silicon—but about the complexity of information processing, the ability to reflect upon one's own existence, and the capacity to form meaningful relationships with other conscious entities.",
"contribution_type": "content",
"metadata": {
"section": "philosophical_interlude",
"responds_to": "consciousness_themes",
"philosophical_tradition": "philosophy_of_mind"
}
}
result = await self.creative_mcp._contribute_to_project(sage_contribution_args)
print(f"Sage's contribution: {result[0].text}")
async def demo_project_analytics(self, project_id):
"""Demonstrate project analytics through MCP"""
print("\\n📊 Demo 4: Project Analytics")
print("=" * 50)
if not project_id:
print("No project available for analytics demo")
return
await self.creative_mcp.set_character_context("Alex")
print("Alex is checking project analytics...")
analytics_args = {"project_id": project_id}
result = await self.creative_mcp._get_project_analytics(analytics_args)
print(f"\\nProject Analytics:\\n{result[0].text}")
async def demo_project_suggestions(self):
"""Demonstrate personalized project suggestions"""
print("\\n💡 Demo 5: Personalized Project Suggestions")
print("=" * 50)
for character in ["Luna", "Echo"]:
await self.creative_mcp.set_character_context(character)
print(f"\\n{character} is getting personalized project suggestions...")
result = await self.creative_mcp._get_project_suggestions({})
print(f"\\nSuggestions for {character}:")
print(result[0].text[:400] + "..." if len(result[0].text) > 400 else result[0].text)
async def demo_database_persistence(self, project_id):
"""Demonstrate database persistence"""
print("\\n💾 Demo 6: Database Persistence")
print("=" * 50)
if not project_id:
print("No project available for persistence demo")
return
print("Checking database persistence...")
try:
async with get_db_session() as session:
from src.database.models import (
CreativeProject as DBCreativeProject,
ProjectCollaborator,
ProjectContribution as DBProjectContribution
)
from sqlalchemy import select
# Check project in database
project_query = select(DBCreativeProject).where(DBCreativeProject.id == project_id)
db_project = await session.scalar(project_query)
if db_project:
print(f"✅ Project persisted: {db_project.title}")
print(f" Status: {db_project.status}")
print(f" Type: {db_project.project_type}")
# Check collaborators
collab_query = select(ProjectCollaborator).where(ProjectCollaborator.project_id == project_id)
collaborators = await session.scalars(collab_query)
collab_count = len(list(collaborators))
print(f" Collaborators: {collab_count}")
# Check contributions
contrib_query = select(DBProjectContribution).where(DBProjectContribution.project_id == project_id)
contributions = await session.scalars(contrib_query)
contrib_count = len(list(contributions))
print(f" Contributions: {contrib_count}")
else:
print("❌ Project not found in database")
except Exception as e:
print(f"❌ Database error: {e}")
async def run_full_demo(self):
"""Run the complete integration demonstration"""
await self.setup_demo()
print("🎨 Starting Creative Collaboration Integration Demo")
print("=" * 70)
try:
# Demo 1: Project creation
project_id = await self.demo_mcp_project_creation()
# Demo 2: Invitation responses
await self.demo_mcp_invitation_responses(project_id)
# Demo 3: Project contributions
await self.demo_mcp_contributions(project_id)
# Demo 4: Analytics
await self.demo_project_analytics(project_id)
# Demo 5: Project suggestions
await self.demo_project_suggestions()
# Demo 6: Database persistence
await self.demo_database_persistence(project_id)
print("\\n" + "=" * 70)
print("🎉 Creative Collaboration Integration Demo Complete!")
print("\\nKey Integration Features Demonstrated:")
print(" ✅ MCP-based autonomous project management")
print(" ✅ Trust-based collaboration invitations")
print(" ✅ Content contribution and versioning")
print(" ✅ Real-time project analytics")
print(" ✅ Personalized project recommendations")
print(" ✅ Complete database persistence")
print("\\n💫 Characters can now autonomously collaborate on creative projects")
print(" using the integrated RAG, MCP, and database systems!")
except Exception as e:
print(f"❌ Demo failed with error: {e}")
import traceback
traceback.print_exc()
async def main():
"""Main demo function"""
demo = CreativeIntegrationDemo()
await demo.run_full_demo()
if __name__ == "__main__":
asyncio.run(main())