Mobility Retrieve-and-Reflect Agent: GraphRAG + Multi-Agent Reflection for mobility trajectories
Project description
MRRA: Mobility Retrieve-and-Reflect Agent
Overview
- MRRA is a plug-and-play Python package for mobility trajectories with columns
user_id,timestamp,latitude,longitude. - It composes a GraphRAG retriever with multi-agent reflection to support tasks like next point, future time, and full-day trajectory.
Features
- Data normalization (
TrajectoryBatch) and mobility graph construction (MobilityGraph). - Graph-based retriever (
GraphRAGGenerate) returning LangChain Documents. - Multi-agent reflection with strict JSON outputs and configurable aggregator.
- MCP tools integration (adapters-first) with graceful fallback.
Install
- From source (recommended in a virtual env):
pip install -e .
- Optional MCP extras:
pip install -e .[mcp]
Quickstart
import pandas as pd
from mrra.data.trajectory import TrajectoryBatch
from mrra.graph.pattern import PatternGenerate
from mrra.retriever.graph_rag import GraphRAGGenerate
from mrra.agents.builder import build_mrra_agent
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],
})
tb = TrajectoryBatch(df)
pattern = PatternGenerate(tb)
retriever = GraphRAGGenerate(tb=tb)
agent = build_mrra_agent(
llm={
# OpenAI-compatible endpoint
"provider":"openai-compatible",
"model":"qwen-plus",
"base_url":"https://dashscope.aliyuncs.com/compatible-mode/v1",
"api_key":"YOUR_API_KEY" # prefer env var in production
},
retriever=retriever,
reflection={
"max_round": 3,
"subAgents": [
{"name":"temporal", "prompt":"Temporal reasoning subagent.", "mcp": {"weather":{}}},
{"name":"spatial", "prompt":"Spatial reasoning subagent.", "mcp": {"maps":{}}},
{"name":"pattern", "prompt":"Profile/pattern subagent.", "mcp": {}},
],
"aggregator": "confidence_weighted_voting"
}
)
res = agent.invoke({"task":"next_position", "user_id":"user_1", "t":"2023-01-02 09:30:00"})
print(res)
Tasks
next_position: next point after timet.future_position: point at a future timet.full_day_traj: full-day path for a givendate.
MCP Integration (Amap example)
- Configure subagents with MCP:
reflection={
"subAgents": [
{"name":"spatial", "prompt":"...", "mcp": {"gmap": {"url": "https://mcp.amap.com/sse?key=YOUR_AMAP_KEY", "transport":"sse"}}}
]
}
- The package uses
langchain-mcp-adaptersfirst; falls back tolangchain-mcptoolkit; and finally to raw MCP SSE discovery.
Data format
- Required columns:
user_id,timestamp(ISO),latitude,longitude. - Optional tz handling via
TrajectoryBatch(..., tz=...).
Dev and demos
- Create env (example):
conda create -n mrra-py310 python=3.10 - ISP data demo:
python scripts/verify_isp.py(expectsscripts/ispas input; file is git-ignored by default)
Security notes
- Do not commit API keys. Prefer environment variables or secret managers.
- Large data (like
scripts/isp) is git-ignored by default.
License
- Specify your license here.
中文文档
- See
README_zh.mdfor Chinese documentation.
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.1.tar.gz.
File metadata
- Download URL: mrra-0.1.1.tar.gz
- Upload date:
- Size: 27.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18604c2692616fdb97f35360699d892354bd2dae06511214e123904b64e1d79c
|
|
| MD5 |
46368de3f05f38043855f13fcce809b5
|
|
| BLAKE2b-256 |
b80696a1b52ff0d12f5e299f882a335a2321a60bbcdc7bb044c71299b48f4f25
|
Provenance
The following attestation bundles were made for mrra-0.1.1.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.1.tar.gz -
Subject digest:
18604c2692616fdb97f35360699d892354bd2dae06511214e123904b64e1d79c - Sigstore transparency entry: 524857465
- Sigstore integration time:
-
Permalink:
AoWangg/mrra@2175c2aee050f981904b79d044528f4ce2c99fbf -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/AoWangg
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@2175c2aee050f981904b79d044528f4ce2c99fbf -
Trigger Event:
release
-
Statement type:
File details
Details for the file mrra-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mrra-0.1.1-py3-none-any.whl
- Upload date:
- Size: 31.3 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 |
dc25f977c349264e3d57479612e5e57d9fce6d3a70f5597b9afbc6eabc67707d
|
|
| MD5 |
8c1eeaaf06dacd64682478d16b2e83b4
|
|
| BLAKE2b-256 |
e3e155b19b17d61f068e8615b86ab280a5e1120667d77a4a12a090d365609faf
|
Provenance
The following attestation bundles were made for mrra-0.1.1-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.1-py3-none-any.whl -
Subject digest:
dc25f977c349264e3d57479612e5e57d9fce6d3a70f5597b9afbc6eabc67707d - Sigstore transparency entry: 524857492
- Sigstore integration time:
-
Permalink:
AoWangg/mrra@2175c2aee050f981904b79d044528f4ce2c99fbf -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/AoWangg
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@2175c2aee050f981904b79d044528f4ce2c99fbf -
Trigger Event:
release
-
Statement type: