Files

65 lines
2.1 KiB
Python

"""Librarian Mode - Archives and categorizes important discussion."""
import logging
from app.llm.client import LLMClient
from app.llm.prompts import PromptTemplates
logger = logging.getLogger(__name__)
class LibrarianMode:
"""
Librarian - The keeper of knowledge and archives.
Purpose:
- Identifies and catalogs important discussion points
- Creates summaries of key topics
- Builds context for future reference
- Prepares data for blog and clip exports
Policy:
- Runs passively, always monitoring
- Tags messages by topic/sentiment
- Creates discussion threads
- Identifies "clip-worthy" moments
- Feeds data to Scribe for final export
"""
def __init__(self, llm_client: LLMClient):
"""Initialize Librarian mode."""
self.llm_client = llm_client
self.archived_messages: list[dict] = []
self.topics: dict[str, list[str]] = {}
async def archive_message(self, message_id: str, content: str, username: str) -> None:
"""Archive an important message."""
self.archived_messages.append(
{
"id": message_id,
"content": content,
"username": username,
}
)
logger.debug(f"Librarian archived message from {username}")
async def identify_topics(self, messages: list[str]) -> list[str]:
"""Identify key topics from a set of messages."""
# Placeholder: Would use LLM to extract topics
topics = ["general", "technical", "community"]
return topics
async def create_summary(self, topic: str, messages: list[str]) -> str:
"""Create a summary of messages under a topic."""
prompt = PromptTemplates.librarian_summary(messages)
summary = await self.llm_client.generate(prompt, max_tokens=300)
logger.info(f"Librarian created summary for topic: {topic}")
return summary
async def get_archives(self) -> dict:
"""Get the archive status."""
return {
"mode": "librarian",
"archived_messages": len(self.archived_messages),
"topics_tracked": len(self.topics),
}