mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
Added serious RAG capabilties
This commit is contained in:
@@ -10,8 +10,9 @@ Comprehensive service for managing communication:
|
||||
Implements the communication model.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from datetime import UTC, datetime
|
||||
from typing import ClassVar, cast
|
||||
from typing import Any, ClassVar, cast
|
||||
from uuid import UUID
|
||||
|
||||
from sqlalchemy import select
|
||||
@@ -72,6 +73,7 @@ class MessagingService(BaseService):
|
||||
"""
|
||||
|
||||
service_name: ClassVar[str] = "messaging"
|
||||
_background_tasks: ClassVar[set[asyncio.Task[Any]]] = set()
|
||||
|
||||
# =========================================================================
|
||||
# CHANNEL OPERATIONS (TASK-013)
|
||||
@@ -817,6 +819,31 @@ class MessagingService(BaseService):
|
||||
message_id=str(message.id),
|
||||
)
|
||||
|
||||
async def _index_message_async(self, message: MessageTable) -> None:
|
||||
"""Index message in RAG system (fire-and-forget)."""
|
||||
from roboco.models.optimal import IndexConversationParams
|
||||
from roboco.services.optimal import get_optimal_service
|
||||
|
||||
try:
|
||||
optimal = await get_optimal_service()
|
||||
await optimal.index_conversation(
|
||||
IndexConversationParams(
|
||||
content=message.content,
|
||||
channel_id=message.channel_id,
|
||||
session_id=message.session_id,
|
||||
agent_id=message.agent_id,
|
||||
task_id=message.task_id,
|
||||
message_type=message.type.value if message.type else None,
|
||||
)
|
||||
)
|
||||
self.log.debug("Message indexed", message_id=str(message.id))
|
||||
except Exception as e:
|
||||
self.log.warning(
|
||||
"Failed to index message",
|
||||
message_id=str(message.id),
|
||||
error=str(e),
|
||||
)
|
||||
|
||||
async def send_message(
|
||||
self,
|
||||
req: MessageCreateRequest,
|
||||
@@ -865,6 +892,11 @@ class MessagingService(BaseService):
|
||||
# Notify mentioned agents via Redis Streams
|
||||
await self._notify_mentions(message, req.agent_id, channel.slug)
|
||||
|
||||
# Index message in RAG (fire-and-forget)
|
||||
bg_task = asyncio.create_task(self._index_message_async(message))
|
||||
self._background_tasks.add(bg_task)
|
||||
bg_task.add_done_callback(self._background_tasks.discard)
|
||||
|
||||
if self._check_session_boundaries(session):
|
||||
await self.close_session(cast("UUID", session.id), "Boundary exceeded")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user