Skip to main content

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 time t.
  • future_position: point at a future time t.
  • full_day_traj: full-day path for a given date.

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-adapters first; falls back to langchain-mcp toolkit; 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 (expects scripts/isp as 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.md for Chinese documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mrra-0.1.1.tar.gz (27.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mrra-0.1.1-py3-none-any.whl (31.3 kB view details)

Uploaded Python 3

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

Hashes for mrra-0.1.1.tar.gz
Algorithm Hash digest
SHA256 18604c2692616fdb97f35360699d892354bd2dae06511214e123904b64e1d79c
MD5 46368de3f05f38043855f13fcce809b5
BLAKE2b-256 b80696a1b52ff0d12f5e299f882a335a2321a60bbcdc7bb044c71299b48f4f25

See more details on using hashes here.

Provenance

The following attestation bundles were made for mrra-0.1.1.tar.gz:

Publisher: publish-pypi.yml on AoWangg/mrra

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for mrra-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dc25f977c349264e3d57479612e5e57d9fce6d3a70f5597b9afbc6eabc67707d
MD5 8c1eeaaf06dacd64682478d16b2e83b4
BLAKE2b-256 e3e155b19b17d61f068e8615b86ab280a5e1120667d77a4a12a090d365609faf

See more details on using hashes here.

Provenance

The following attestation bundles were made for mrra-0.1.1-py3-none-any.whl:

Publisher: publish-pypi.yml on AoWangg/mrra

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page