Skip to content

Session Management #41

@nullchimp

Description

@nullchimp

Analyze the existing _agent_sessions structure in agent.py and implement a comprehensive session management system that integrates with the current Database infrastructure, following the project's modular architecture.

Analysis Requirements

First, examine these key components to understand the current architecture:

  1. Review _agent_sessions implementation in agent.py to understand the existing session structure
  2. Analyze rag/schema.py to understand the current Node class structure and database patterns
  3. Identify the Database class implementation and its connection patterns
  4. Review existing API endpoints to understand the current frontend integration approach

Implementation Tasks

Phase 1: Schema Reorganization

  • Move all database schemas from rag/schema.py into a new db/schemas/ folder structure
  • Ensure all Database nodes exclusively inherit from the Node class
  • Implement comprehensive serialization/deserialization methods in the Node class for JSON conversion

Phase 2: Session Management System

  • Create a user-based session management system that builds on _agent_sessions
  • Integrate with the existing Database infrastructure
  • Design for single hardcoded user initially, but structure for future multi-user expansion
  • Implement session creation, retrieval, update, and deletion operations

Phase 3: API Integration

  • Connect session management endpoints to the existing API structure
  • Ensure frontend can create and delete sessions through the API
  • Maintain consistency with existing endpoint patterns

Steps

  1. Code Analysis: Examine agent.py for _agent_sessions, rag/schema.py for Node patterns, and existing Database usage
  2. Schema Migration: Create db/schemas/ structure and move existing schemas while preserving inheritance
  3. Node Enhancement: Add comprehensive JSON serialization/deserialization to the Node base class
  4. Session System: Implement database-backed session management building on existing patterns
  5. API Endpoints: Create or enhance endpoints for session CRUD operations
  6. Frontend Integration: Ensure session management is accessible from the frontend interface
  7. Testing: Validate the session system works with the single hardcoded user approach

Output Format

Provide implementation files with:

  • File paths for new/modified files
  • Complete code implementations following the project's coding standards
  • Clear indication of which existing files need modifications
  • Brief explanation of architectural decisions made during implementation

Examples

Schema Migration Example:

src/db/schemas/
├── __init__.py
├── base.py (Node class with serialization)
├── session.py (Session-related schemas)
└── [other existing schemas from rag/schema.py]

Session Management Integration:

# Example of how session management should integrate with existing Database
class SessionManager:
    def __init__(self, database: Database):
        self.database = database
    
    async def create_user_session(self, user_id: str, session_data: dict) -> SessionNode:
        # Implementation that uses existing Database patterns

API Endpoint Example:

# Example endpoint structure following existing API patterns
@router.post("/sessions")
async def create_session(session_data: SessionCreateRequest) -> SessionResponse:
    # Implementation that connects to session management system

Notes

  • Maintain compatibility with existing Database class and connection patterns
  • Do not use Abstract Base Classes (ABC) or interfaces - follow existing concrete class patterns
  • Preserve existing functionality while adding session management capabilities
  • Structure the implementation to allow future expansion from single-user to multi-user
  • Follow the project's import organization and naming conventions
  • Ensure all new code passes the existing linting and type checking requirements

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions