Skip to main content

A Python library for RemGPT

Project description

๐Ÿš€ RemGPT - Advanced Multi-Provider LLM Framework

Python 3.8+ License: MIT OpenAI Claude Gemini

RemGPT is a production-ready, multi-provider LLM framework with breakthrough Intelligent Memory Management. It automatically detects topic shifts, saves conversation context, and maintains long-term memory - all through advanced statistical analysis and self-managing AI agents.

๐ŸŒŸ Revolutionary Features

๐Ÿง  Breakthrough Memory Algorithm

Our Intelligent Memory Management system represents a major advancement in conversational AI:

  • Statistical Topic Drift Detection: Uses semantic embeddings and cosine similarity to detect topic changes with 82.9% accuracy
  • AI-Driven Memory Decisions: The AI agent autonomously decides when to save important topics or evict old conversations
  • Self-Managing Context: Automatically maintains optimal context window (4K tokens) without manual intervention
  • Long-Term Memory Persistence: Conversation topics are saved to vector storage and can be recalled across sessions

Why This Algorithm is Revolutionary: Traditional LLMs forget everything between conversations and struggle with context length limits. RemGPT solves both problems by giving AI the ability to manage its own memory - detecting when topics change, deciding what's important to remember, and automatically maintaining conversation context. This creates truly persistent, intelligent conversations.

๐Ÿ”„ Multi-Provider Excellence

  • Universal LLM Support: OpenAI GPT-4/GPT-4o, Anthropic Claude, Google Gemini
  • Seamless Provider Switching: Change models without code changes
  • Optimized for Each Provider: Handles streaming, tool calling, and rate limits perfectly

๐Ÿ› ๏ธ Advanced Tool Integration

  • Remote Tool Protocols: MCP (Model Context Protocol) and Agent-to-Agent communication
  • Streaming Tool Execution: Tools execute during conversation flow
  • Self-Healing Tool Calls: Automatic retry and error handling

โšก Production-Ready API

  • Clean Streaming API: Server-sent events with Bearer token authentication
  • RESTful Interface: Standard HTTP endpoints for integration
  • Scalable Architecture: Designed for production workloads

๐Ÿš€ Quick Start

Installation

pip install "numpy<2.0"  # Ensure compatibility
pip install remgpt

๐ŸŽฏ Live Demo - See the Magic in Action!

Experience RemGPT's breakthrough memory management with our comprehensive OpenAI demonstration:

cd examples
# Add your OpenAI API key to .env file
echo "OPENAI_API_KEY=your-key-here" > .env
python openai_demo.py

๐ŸŽญ What You'll Witness:

  • ๐Ÿค– Real OpenAI Integration: Live gpt-4o-mini API calls with streaming responses
  • ๐Ÿง  Intelligent Memory Management: Watch the AI detect topic changes and automatically save conversations
  • ๐Ÿ“Š Advanced Analytics: Real-time similarity scores (0.016 for major topic shifts)
  • ๐Ÿ”ง Autonomous Tool Execution: AI independently calls save_current_topic when needed
  • ๐Ÿ’พ Context Evolution: See token usage grow intelligently (372โ†’770+ tokens)
  • ๐Ÿ”„ Multi-Turn Persistence: Conversations that remember and build context

๐Ÿ’ป Live Demo Output:

๐Ÿš€ RemGPT Advanced Multi-Provider LLM Framework Demo
โœจ Showcasing Breakthrough Memory Management System

โœ… API Integration
  โ€ข OpenAI client: gpt-4o-mini (sk-proj-i_6G6ta...)
  โ€ข Context manager: 372 tokens initialized
  โ€ข Memory tools: save_current_topic, evict_oldest_topic

๐Ÿ’ฌ Intelligent Conversation Flow
๐Ÿ‘ค User: "Hello! Can you explain the key principles of microservices architecture?"

๐Ÿค– Assistant: [Comprehensive 1,767 character response about microservices architecture, 
including principles like single responsibility, decentralized governance, 
fault isolation, and technology diversity...]

๐Ÿ‘ค User: "Now let's switch topics completely. I'm having issues with Python async/await patterns..."

๐Ÿง  INTELLIGENT MEMORY DETECTION:
  โ€ข Topic drift detected: similarity=0.016 (major change threshold)
  โ€ข Auto-triggering memory management...
  
๐Ÿ”ง AI AUTONOMOUS TOOL EXECUTION:
  โ€ข Tool: save_current_topic
  โ€ข Args: {
      'topic_summary': 'Discussion about microservices architecture principles...',
      'topic_key_facts': ['Single responsibility principle', 'Decentralized governance', ...]
    }
  โ€ข Topic saved: topic_1749425223_3bb68f03

๐Ÿ“Š FINAL INTELLIGENCE METRICS:
  โ€ข Context tokens: 770 (dynamic growth)
  โ€ข Saved topics: 1 (autonomous decision)
  โ€ข Queue efficiency: 4 messages optimally managed
  โ€ข Memory system: FULLY OPERATIONAL โœ…

๐ŸŽ‰ This demonstrates RemGPT's revolutionary capability: The AI doesn't just respond - it thinks about conversation flow, detects important topic changes, and manages its own memory without any human intervention!

Basic Usage

from remgpt import LLMClientFactory, ToolExecutor, ConversationOrchestrator
from remgpt.tools import BaseTool

# Create LLM client
factory = LLMClientFactory()
client = factory.create_client(
    provider="openai",
    model_name="gpt-4",
    api_key="your-api-key"
)

# Set up tools
class CalculatorTool(BaseTool):
    def __init__(self):
        super().__init__("calculator", "Perform arithmetic calculations")
    
    async def execute(self, operation: str, a: float, b: float) -> dict:
        return {"result": a + b if operation == "add" else a * b}
    
    def get_schema(self) -> dict:
        return {
            "type": "function",
            "function": {
                "name": "calculator",
                "description": "Perform arithmetic calculations",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "operation": {"type": "string", "enum": ["add", "multiply"]},
                        "a": {"type": "number"},
                        "b": {"type": "number"}
                    },
                    "required": ["operation", "a", "b"]
                }
            }
        }

executor = ToolExecutor()
executor.register_tool(CalculatorTool())

# Process messages with streaming
messages = [{"role": "user", "content": "Calculate 2 + 3"}]

async for event in client.generate_stream(messages, tools=executor.get_tool_schemas()):
    if event.type == "TEXT_MESSAGE_CONTENT":
        print(event.content)

Full Orchestrator with Remote Tools

from remgpt import create_orchestrator, create_context_manager

# Create context manager
context_manager = create_context_manager(
    max_tokens=4000,
    system_instructions="You are a helpful assistant."
)

# Create orchestrator with remote tools
orchestrator = await create_orchestrator(
    context_manager=context_manager,
    mcp_servers=["uvx weather-mcp@latest stdio"],
    a2a_agents=["http://localhost:8000"]
)

# Process messages
async for event in orchestrator.process_message({"role": "user", "content": "Hello!"}):
    if event.type == "TEXT_MESSAGE_CONTENT":
        print(event.content)

๐ŸŒ API Server

Start Server

uvicorn remgpt.api:app --host 0.0.0.0 --port 8000

REST API

curl -X POST "http://localhost:8000/messages/stream" \
  -H "Authorization: Bearer your_token_here" \
  -H "Content-Type: application/json" \
  -d '{"content": "Hello, how are you?"}'

๐Ÿ—๏ธ Architecture

Core Modules

remgpt/
โ”œโ”€โ”€ api.py              # FastAPI web interface
โ”œโ”€โ”€ context/            # Context management system
โ”œโ”€โ”€ llm/                # LLM client abstractions (OpenAI, Claude, Gemini)
โ”œโ”€โ”€ tools/              # Tool execution system
โ”‚   โ””โ”€โ”€ remote/         # Remote tool protocols (MCP, A2A)
โ”œโ”€โ”€ orchestration/      # Conversation orchestration
โ”œโ”€โ”€ detection/          # Topic drift detection
โ”œโ”€โ”€ summarization/      # Topic summarization
โ””โ”€โ”€ storage/            # Vector database abstractions

Design Principles

  • Single Responsibility: Each class has its own file
  • Protocol Abstraction: Unified interfaces for different providers
  • Graceful Degradation: Works without optional dependencies
  • Factory Patterns: Easy configuration and instantiation

๐Ÿงช Testing

# Run all tests
pytest tests/

# Run specific test categories
pytest tests/test_llm_client.py          # LLM client tests
pytest tests/test_tools/                 # Tool system tests
pytest tests/test_context/               # Context management tests

๐Ÿ“ฆ Remote Tools

MCP (Model Context Protocol)

from remgpt.tools.remote import MCPProtocol

# Connect to MCP server
protocol = MCPProtocol()
await protocol.connect("uvx weather-mcp@latest stdio")

Agent-to-Agent (A2A)

from remgpt.tools.remote import A2AProtocol

# Connect to A2A agent
protocol = A2AProtocol("http://localhost:8000")
await protocol.call_tool("send_task", {"text": "Hello, agent!"})

๐Ÿ”ง Development

Setup

git clone https://github.com/yourusername/remgpt.git
cd remgpt
pip install -e .
pip install -r requirements-test.txt

Key Development Features

  • 40+ Tests: Unit and integration tests with real models
  • Performance Validated: <1 second embedding generation
  • Modular Architecture: Easy to extend and maintain
  • Clean Imports: Conditional exports based on availability

๐Ÿ“„ License

MIT License - see LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

remgpt-0.2.0.tar.gz (88.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

remgpt-0.2.0-py3-none-any.whl (87.3 kB view details)

Uploaded Python 3

File details

Details for the file remgpt-0.2.0.tar.gz.

File metadata

  • Download URL: remgpt-0.2.0.tar.gz
  • Upload date:
  • Size: 88.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for remgpt-0.2.0.tar.gz
Algorithm Hash digest
SHA256 75557bdf57330bb2bd5ade428cf3b5af9bfc3200634b3e0f19ad317c241d843a
MD5 66c5fa888ecbd0dcdcbc55df919cf074
BLAKE2b-256 34bc493ad4e59b9b7e949cb73d9b9b435dc14c32fefa9147c1dc418a12c21214

See more details on using hashes here.

File details

Details for the file remgpt-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: remgpt-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 87.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for remgpt-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ea32c8ab5addebcfc687a5c25a6e1ef04c176eb4a1c12c5017801b066b76551
MD5 770759945c6a92eeb2c4bbc6eecd12c7
BLAKE2b-256 0cc189fbfb47bb973e593bd61542e11da310f0dc03cc82475e7a96a8b63d39e1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page