Mobility Retrieve-and-Reflect Agent: GraphRAG + Multi-Agent Reflection for mobility trajectories
Project description
๐บ๏ธ MRRA
Mobility Retrieve-and-Reflect Agent
GraphRAG + Multi-Agent Reflection for Intelligent Mobility Analysis
๐ 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.
โจ Key Features
๐ง Intelligent Architecture
|
๐ง Developer Friendly
|
๐ Data Processing
|
๐ฏ Prediction Tasks
|
๐ ๏ธ 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 usertimestamp: 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:
- Primary:
langchain-mcp-adapters(recommended) - Fallback:
langchain-mcptoolkit - Native: Raw MCP SSE discovery
Supported Services
- ๐บ๏ธ Maps: Google Maps, Amap, OpenStreetMap
- ๐ค๏ธ Weather: Real-time weather data
- ๐ Geocoding: Address to coordinate conversion
๐ Documentation
- ๐ Homepage: mrra.tech
- ๐ Documentation: mrra.tech/en/docs
- ๐จ๐ณ ไธญๆๆๆกฃ: mrra.tech/zh/docs
๐งช 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
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 mrra-0.1.3.tar.gz.
File metadata
- Download URL: mrra-0.1.3.tar.gz
- Upload date:
- Size: 30.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21284c6d979c4650d0fdaec415eee63813ec05109f4e3c4d60fa92715d9cf078
|
|
| MD5 |
9df2b6e9fea002324be7375cb09edcf3
|
|
| BLAKE2b-256 |
f4017d29e10e23655861c22d05620b0808955feebd8bd249a83a8d48539e5b6e
|
Provenance
The following attestation bundles were made for mrra-0.1.3.tar.gz:
Publisher:
publish-pypi.yml on AoWangg/mrra
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mrra-0.1.3.tar.gz -
Subject digest:
21284c6d979c4650d0fdaec415eee63813ec05109f4e3c4d60fa92715d9cf078 - Sigstore transparency entry: 528495888
- Sigstore integration time:
-
Permalink:
AoWangg/mrra@05deedc666ef2e05e238a684cfcf04f2d0d14235 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/AoWangg
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@05deedc666ef2e05e238a684cfcf04f2d0d14235 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mrra-0.1.3-py3-none-any.whl.
File metadata
- Download URL: mrra-0.1.3-py3-none-any.whl
- Upload date:
- Size: 32.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d51e6a820497d2cdcdf5a9853da21b3ada8ea880d788169ba65cbeac49b140d4
|
|
| MD5 |
f2e9febfa31566079aa4faac6674ecca
|
|
| BLAKE2b-256 |
b4faefe8948d9a4c222f9a3dc6d062aae87f9038fbcb6f83cfc266af9f8affd4
|
Provenance
The following attestation bundles were made for mrra-0.1.3-py3-none-any.whl:
Publisher:
publish-pypi.yml on AoWangg/mrra
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mrra-0.1.3-py3-none-any.whl -
Subject digest:
d51e6a820497d2cdcdf5a9853da21b3ada8ea880d788169ba65cbeac49b140d4 - Sigstore transparency entry: 528495896
- Sigstore integration time:
-
Permalink:
AoWangg/mrra@05deedc666ef2e05e238a684cfcf04f2d0d14235 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/AoWangg
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@05deedc666ef2e05e238a684cfcf04f2d0d14235 -
Trigger Event:
release
-
Statement type: