Skip to content

Boburmirzo/gibsonai-docs-ai-assistant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

GibsonAI Documentation Assistant

A FastAPI-based AI agent that helps users with GibsonAI and Memori documentation using Agno agents and session-based persistent memory.

Features

  • Session-Based Memory: Each browser session gets its own agent instance with isolated conversation memory
  • Persistent Sessions: Maintains conversation context across multiple requests within a session
  • Flexible Knowledge Base: Automatically loads and indexes documentation from multiple GitHub sources
  • Web Search: Uses DuckDuckGo for additional context when documentation isn't sufficient
  • RESTful API: Clean session management with automatic cleanup
  • FastAPI: Fast API with automatic documentation and CORS support

Quick Start

  1. Install dependencies:

    pip install -r requirements.txt
  2. Configure environment variables: Copy .env.example to .env and update the values:

    cp .env .env.local  # or just edit .env directly

    Set your OpenAI API key and GitHub documentation URLs:

    # .env file
    OPENAI_API_KEY=your-openai-api-key-here
    GITHUB_DOCS_URLS=https://raw.githubusercontent.com/GibsonAI/memori/refs/heads/main/docs/llms.txt
  3. Run the server:

    uvicorn main:app --reload
  4. Open your browser:

Session Management

How Sessions Work

  1. Start a Session: Each browser/client starts a new session to get a unique session ID
  2. Separate Agent Instances: Each session gets its own agent instance for true isolation
  3. Shared Memory: Agents for the same user share conversation memory across sessions
  4. Automatic Cleanup: Old sessions are automatically cleaned up to prevent memory leaks
  5. Session Persistence: Conversation context is maintained throughout the session

Memory Architecture

The system implements a hybrid approach that provides both session isolation and memory continuity:

  • Same user_id = Shared conversation memory across all sessions
  • Different session_id = Separate agent instances for isolation
  • Cross-session memory = Users can continue conversations across browser sessions
  • Memory isolation = Different users cannot access each other's memories

API Workflow

// 1. Start a new session
const sessionResponse = await fetch('/session/start', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ user_id: 'optional_user_id' })
});
const { session_id } = await sessionResponse.json();

// 2. Ask questions using the session ID
const askResponse = await fetch('/ask', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        question: 'How do I use GibsonAI?',
        session_id: session_id,
        user_id: 'optional_user_id'
    })
});
const { answer } = await askResponse.json();

API Endpoints

Session Management

  • POST /session/start - Start a new chat session
  • GET /sessions/{session_id}/info - Get session information
  • GET /sessions/{session_id}/memory - View session conversation memory

Chat

  • POST /ask - Ask questions (requires session_id)

System

  • GET / - API overview and health check
  • GET /health - Detailed health check with session count

Configuration

Multiple GitHub Sources

You can configure multiple GitHub documentation sources by separating URLs with commas in the .env file:

GITHUB_DOCS_URLS=https://raw.githubusercontent.com/GibsonAI/memori/refs/heads/main/docs/llms.txt,https://raw.githubusercontent.com/GibsonAI/another-repo/main/docs/api.txt,https://raw.githubusercontent.com/GibsonAI/third-repo/main/README.md

Environment Variables

  • OPENAI_API_KEY: Your OpenAI API key (required)
  • GITHUB_DOCS_URLS: Comma-separated list of GitHub raw file URLs (required)

Example Frontend Integration

See frontend_example.js for a complete JavaScript client example that demonstrates:

  • Session management
  • Conversation flow
  • Error handling
  • User interface integration
// Basic usage
const client = new GibsonAIClient();
await client.startSession('user123');
const answer = await client.askQuestion('What is GibsonAI?');

Architecture

  • Session-Based Agents: Each session gets a unique Agno agent instance
  • Shared Memory: Same user_id enables memory sharing across sessions using Agno's built-in memory system
  • Knowledge Base: Shared LanceDB vector store with GitHub documentation
  • DuckDuckGo Tools: Web search for additional context
  • Automatic Cleanup: Background cleanup of old sessions (1+ hour)

Key Benefits

  1. True Session Isolation: Each browser session gets its own agent instance
  2. Memory Continuity: Conversation history persists across browser sessions for the same user
  3. Memory Efficiency: Automatic cleanup prevents memory leaks
  4. Scalable: Can handle multiple concurrent users with isolated contexts
  5. RESTful Design: Clean API design following REST principles
  6. Frontend Ready: Easy integration with web applications
  7. Best of Both Worlds: Session isolation + memory continuity