Skip to main content
MRRA Icon

🗺️ MRRA

Mobility Retrieve-and-Reflect Agent

GraphRAG + Multi-Agent Reflection for Intelligent Mobility Analysis

PyPI version PyPI downloads Python 3.10+ License: MIT CI

🚀 Quick Start • 📖 Documentation • 🌟 Features • 🛠️ Installation


🎯 Overview

MRRA is a cutting-edge Python package that revolutionizes mobility trajectory analysis through the fusion of GraphRAG (Graph-based Retrieval-Augmented Generation) and multi-agent reflection. Simply provide trajectory data with user_id, timestamp, latitude, longitude columns, and unlock intelligent predictions for next locations, future positions, and complete daily routes.

MRRA Framework

✨ Key Features

🧠 Intelligent Architecture

  • GraphRAG Integration: Advanced graph-based retrieval system
  • Multi-Agent Reflection: Sophisticated agent orchestration with confidence weighting
  • Temporal-Spatial Reasoning: Deep understanding of mobility patterns

🔧 Developer Friendly

  • Plug-and-Play: Ready-to-use with minimal configuration
  • LangChain Compatible: Seamless integration with LangChain ecosystem
  • MCP Tools: Built-in support for weather, maps, and geospatial services

📊 Data Processing

  • Flexible Input: Standard trajectory format support
  • Graph Construction: Automatic mobility graph generation
  • Pattern Recognition: Intelligent activity and behavior detection

🎯 Prediction Tasks

  • Next Position: Predict immediate next location
  • Future Position: Forecast location at specific time
  • Full Day Trajectory: Generate complete daily route patterns

🛠️ Installation

Quick Install

pip install mrra

Development Install

git clone https://github.com/AoWangg/mrra.git
cd mrra
pip install -e .

Optional Dependencies

# For MCP tools integration
pip install mrra[mcp]

# For development
pip install mrra[dev]

🚀 Quick Start

Basic Usage

import pandas as pd
from mrra.data.trajectory import TrajectoryBatch
from mrra.retriever.graph_rag import GraphRAGGenerate
from mrra.agents.builder import build_mrra_agent

# 📊 Prepare your trajectory data
df = pd.DataFrame({
    'user_id': ['user_1', 'user_1', 'user_1'],
    'timestamp': ['2023-01-01 09:00:00', '2023-01-01 12:00:00', '2023-01-01 18:00:00'],
    'latitude': [31.2304, 31.2404, 31.2504],
    'longitude': [121.4737, 121.4837, 121.4937],
})

# 🔄 Create trajectory batch and retriever
tb = TrajectoryBatch(df)
retriever = GraphRAGGenerate(tb=tb)

# 🤖 Build MRRA agent
agent = build_mrra_agent(
    llm={
        "provider": "openai-compatible",
        "model": "qwen-plus",
        "base_url": "https://dashscope.aliyuncs.com/compatible-mode/v1",
        "api_key": "YOUR_API_KEY"  # Use environment variables in production
    },
    retriever=retriever,
    reflection={
        "max_round": 3,
        "subAgents": [
            {"name": "temporal", "prompt": "Temporal reasoning specialist", "mcp": {"weather": {}}},
            {"name": "spatial", "prompt": "Spatial analysis expert", "mcp": {"maps": {}}},
            {"name": "pattern", "prompt": "Behavior pattern analyst", "mcp": {}},
        ],
        "aggregator": "confidence_weighted_voting"
    }
)

# 🎯 Make predictions
result = agent.invoke({
    "task": "next_position", 
    "user_id": "user_1", 
    "t": "2023-01-02 09:30:00"
})
print(result)

Advanced MCP Integration

# 🗺️ Configure with real-world services
reflection_config = {
    "subAgents": [
        {
            "name": "spatial", 
            "prompt": "Expert in spatial analysis with real-time map data", 
            "mcp": {
                "gmap": {
                    "url": "https://mcp.amap.com/sse?key=YOUR_AMAP_KEY", 
                    "transport": "sse"
                }
            }
        }
    ]
}

🎯 Supported Tasks

Task Description Input Output
next_position Predict the next location after given time user_id, t Next coordinate prediction
future_position Predict location at specific future time user_id, t Future coordinate prediction
full_day_traj Generate complete daily trajectory user_id, date Full day route sequence

📊 Data Format

Required Columns

  • user_id: Unique identifier for each user
  • timestamp: ISO format timestamp (e.g., "2023-01-01 09:00:00")
  • latitude: Latitude coordinate (float)
  • longitude: Longitude coordinate (float)

🌍 MCP Tools Integration

MRRA supports multiple MCP integration strategies with graceful fallback:

  1. Primary: langchain-mcp-adapters (recommended)
  2. Fallback: langchain-mcp toolkit
  3. Native: Raw MCP SSE discovery

Supported Services

  • 🗺️ Maps: Google Maps, Amap, OpenStreetMap
  • 🌤️ Weather: Real-time weather data
  • 📍 Geocoding: Address to coordinate conversion

📖 Documentation

🧪 Examples & Demos

# 🌟 GeoLife dataset demo
python scripts/verify_geolife.py

# 🔍 Retriever testing
python scripts/check_retriever.py

🤝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Development Setup

# Create environment
conda create -n mrra-dev python=3.10
conda activate mrra-dev

# Install in development mode
pip install -e .[dev]

# Run tests
pytest

# Code formatting
ruff format .
ruff check .

🔒 Security & Best Practices

  • 🔐 Never commit API keys - Use environment variables or secret managers
  • 📁 Large datasets are git-ignored by default
  • 🛡️ Secure MCP connections with proper authentication

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

Built on the shoulders of giants:

📊 Project Stats

GitHub stars GitHub forks GitHub issues GitHub pull requests


🚀 Ready to revolutionize mobility analysis? Get started now!

Metadata

Release files for mrra 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mrra 0.1.3
File Size Uploaded Provenance
mrra-0.1.3.tar.gz 30.3 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mrra 0.1.3
File Interpreter ABI Platform
mrra-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 63.2 kB

Release files / mrra-0.1.3.tar.gz

Download URL mrra-0.1.3.tar.gz
Size 30.3 kB
Tags Source
SHA-256 checksum
How to use checksums
21284c6d979c4650d0fdaec415eee63813ec05109f4e3c4d60fa92715d9cf078
BLAKE2b-256 checksum
How to use checksums
f4017d29e10e23655861c22d05620b0808955feebd8bd249a83a8d48539e5b6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2025.

Transparency log

Release files / mrra-0.1.3-py3-none-any.whl

Download URL mrra-0.1.3-py3-none-any.whl
Size 32.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d51e6a820497d2cdcdf5a9853da21b3ada8ea880d788169ba65cbeac49b140d4
BLAKE2b-256 checksum
How to use checksums
b4faefe8948d9a4c222f9a3dc6d062aae87f9038fbcb6f83cfc266af9f8affd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2025.

Transparency log

Security for mrra 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mrra-0.1.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page