A Python library for RemGPT
Project description
๐ RemGPT - Advanced Multi-Provider LLM Framework
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_topicwhen 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75557bdf57330bb2bd5ade428cf3b5af9bfc3200634b3e0f19ad317c241d843a
|
|
| MD5 |
66c5fa888ecbd0dcdcbc55df919cf074
|
|
| BLAKE2b-256 |
34bc493ad4e59b9b7e949cb73d9b9b435dc14c32fefa9147c1dc418a12c21214
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ea32c8ab5addebcfc687a5c25a6e1ef04c176eb4a1c12c5017801b066b76551
|
|
| MD5 |
770759945c6a92eeb2c4bbc6eecd12c7
|
|
| BLAKE2b-256 |
0cc189fbfb47bb973e593bd61542e11da310f0dc03cc82475e7a96a8b63d39e1
|