Mobility Retrieve-and-Reflect Agent
GraphRAG + Multi-Agent Reflection for Intelligent Mobility Analysis
π Quick Start β’ π Documentation β’ π Features β’ π οΈ Installation
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.
|
|
|
|
pip install mrragit clone https://github.com/AoWangg/mrra.git
cd mrra
pip install -e .# For MCP tools integration
pip install mrra[mcp]
# For development
pip install mrra[dev]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)# πΊοΈ 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"
}
}
}
]
}| 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 |
user_id: Unique identifier for each usertimestamp: ISO format timestamp (e.g., "2023-01-01 09:00:00")latitude: Latitude coordinate (float)longitude: Longitude coordinate (float)
MRRA supports multiple MCP integration strategies with graceful fallback:
- Primary:
langchain-mcp-adapters(recommended) - Fallback:
langchain-mcptoolkit - Native: Raw MCP SSE discovery
- πΊοΈ Maps: Google Maps, Amap, OpenStreetMap
- π€οΈ Weather: Real-time weather data
- π Geocoding: Address to coordinate conversion
- π Homepage: mrra.tech
- π Documentation: mrra.tech/en/docs
- π¨π³ δΈζζζ‘£: mrra.tech/zh/docs
# π GeoLife dataset demo
python scripts/verify_geolife.py
# π Retriever testing
python scripts/check_retriever.pyWe welcome contributions! Please see our Contributing Guidelines for details.
# 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 .- π Never commit API keys - Use environment variables or secret managers
- π Large datasets are git-ignored by default
- π‘οΈ Secure MCP connections with proper authentication
This project is licensed under the MIT License - see the LICENSE file for details.
Built on the shoulders of giants:
