Skip to main content

MemPatrol · 记忆巡检、召回与接话闸门

Memory patrol, lexical recall and conversation gates for long-lived agents. 给长期运行 agent 的记忆巡检、召回打分与群聊接话闸门。

Dependency-free kernels extracted from the memory patrol (记忆巡检) and group-chat judge subsystems: orphan-batch gate, real sender labels, config-audit snapshot diff, decay/consolidation planning, intent expiry, finish gate, lexical recall scorer, composable decision gates, metrics, offline eval, untrusted wrapper and an MCP stdio server.

M0–M4 are host-agnostic kernels: no IM framework or host import, no network. File IO lives behind memorix.adapters.files; the CLI/store (M1), the recall scorer (M1.5) and the gatekeep decision kernel (M2) build on the M0 pure policies.

Install

Distribution name is mem-patrol; the import package and CLI names stay memorix for compatibility. 发行包名是 mem-patrol,导入包/原 CLI 仍叫 memorix。

python -m pip install .                 # installs distribution mem-patrol
python -m pip install '.[test]'         # pytest + jieba for the full suite
memorix --version                       # mem-patrol 0.2.3 (import/CLI name stays memorix)
mem-patrol --version                    # distribution alias, same CLI

For a local checkout, PYTHONPATH=src works without installing.

Foreign databases (schema mapping)

Your tables do not need the default/legacy table names:

memorix diagnose --db my.db --schema schema.json   # explicit mapping
memorix diagnose --db my.db --schema auto          # auto-detect
MEMORIX_SCHEMA=schema.json memorix diagnose --db my.db

Only a memories table is required; message-dependent features (status/finish) return a clear SchemaError when raw_messages/bot_messages are not mapped. MCP tools accept a schema argument. A real-world schema example is included at examples/self-learning.schema.json (ms/s units, archived exclusion, private-chat rule). See docs/SCHEMA.md.

Use-case profiles (chat / project / both)

python -m memorix.profiles --list       # chat / project / both
python -m memorix.profiles --name chat
memorix profile --name project          # CLI view

chat = recall + gatekeep; project = patrol/diagnose/eval; both = all, with judge-first interjection enabled and light throttle (30/day, 10s consult, 1min speech interval). MCP accepts --profile chat|project|both and filters the read-only tool list. See docs/USE-CASES.md and the copy-ready README-两用样稿.md.

MCP server

{
  "mcpServers": {
    "memorix": {"command": "memorix-mcp", "args": ["--profile", "both", "--db", "/path/to/messages.db"]}
  }
}

Zero-dependency stdio MCP server (memorix-mcp / alias mem-patrol-mcp) exposing six read-only tools (diagnose / orphan / recall / gate_check / judge_replay / eval), negotiating protocol 2025-06-18 / 2025-03-26 / 2024-11-05. See docs/MCP.md.

Run the tests (no install needed)

python -m pytest -p no:cacheprovider   # any Python >= 3.10 with pytest

pyproject.toml sets pythonpath = ["src"], so the package is importable without pip install. The full 368-test run needs the optional jieba anchor extra (pip install '.[test]'); without it the anchor-dependent tests are skipped (memorix.eval --suite all still passes 24/24).

Layout

src/memorix/policy/            pure policy functions (M0)
src/memorix/adapters/files.py  file IO (fingerprints/snapshots)
src/memorix/store.py, cli.py   SQLite adapter + diagnose/repair CLI (M1)
src/memorix/retrieval/         recall scorer + §10.3 replay bench (M1.5)
src/memorix/gatekeep/          decision kernel + judge replay set (M2)
src/memorix/observability/     metrics + zero-dep SVG/HTML report (M3)
src/memorix/eval/              replay suites + baseline regression (M3)
src/memorix/safety/            unified untrusted wrapper (M3)
src/memorix/mcp/               MCP stdio server + 6 read-only tools (M4)
src/memorix/profiles.py        chat / project / both presets (M4.1)
src/memorix/schema.py          foreign-DB schema mapping / auto-detect (M4.2)
eval/baseline.json             evaluation baseline (M3)
dist/                          built wheel/sdist (M4)
tests/                         pytest-native tests (368)
docs/                          M0–M4 reports + USE-CASES/MCP/README samples
LICENSE, CHANGELOG.md          MIT + release notes

CLI (M1)

PYTHONPATH=src python -m memorix diagnose --db <path/to/messages.db>

All commands are read-only by default; writes require --apply and take a database snapshot first. Paths are explicit (--db/--state/--ledger/...) or MEMORIX_* env vars — nothing points at production by default. See docs/M1.md for the full command table and docs/DECISIONS.md for the approved design decisions.

Recall scorer (M1.5)

PYTHONPATH=src python -m memorix.retrieval.bench
# RESULT 6/6 passed

Zero runtime dependencies; jieba is an optional anchor extra (pip install -e '.[anchor]'). Lexical only for now; the vector provider is a documented seam. recall(query, ..., instruction=...) never matches the instruction text (the guide §10.3 case-6 rule).

Gatekeep (M2)

from memorix.gatekeep import Context, decide

ctx = Context(
    text="这个怎么弄?",
    config={"enable_group_interjection": True, "group_interject_max_daily": 10},
)
outcome = decide(ctx, judge=lambda _ctx: '{"should_reply": true, "text": "我看看"}')
assert outcome.action == "sent"

Host-agnostic: no IM types, no DB, no network. Gates, JSON contract, needs-tools routing (handoff/tool_task), shadow precision bookkeeping and two pure reviewers (bare promise / absence-without-retrieval). See docs/M2.md.

Metrics / eval / safety (M3)

PYTHONPATH=src python -m memorix.eval --suite all --baseline eval/baseline.json
PYTHONPATH=src python -m memorix.observability --input events.jsonl --out report.html
from memorix.safety import wrap_untrusted
wrapped = wrap_untrusted(untrusted_text, source="group:g1")

Real-corpus regression (no stored text): python -m memorix.eval.real_corpus --db <snapshot> --user-id <id> --manifest eval/real_corpus.json. See docs/REAL-CORPUS.md.

See docs/M3.md. The milestones (M0–M4) stay dependency-free (no network, no host imports); IO lives behind adapters/CLI. M4 adds the MCP server and packaging — see docs/M4.md.

License

MIT. See LICENSE (0.2.2+; earlier releases were Apache-2.0).

Safety

M0 was extracted from a running production system read-only; this package never writes the source system. See docs/M0.md for provenance.

Metadata

Release files for mem-patrol 0.2.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 mem-patrol 0.2.3
File Size Uploaded Provenance
mem_patrol-0.2.3.tar.gz 156.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mem-patrol 0.2.3
File Interpreter ABI Platform
mem_patrol-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 250.4 kB

Release files / mem_patrol-0.2.3.tar.gz

Download URL mem_patrol-0.2.3.tar.gz
Size 156.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e1b2e209a2d134ab4fac013ce0de4230f07bc880924f75ee0735eed7f2830f8d
BLAKE2b-256 checksum
How to use checksums
6999f14cdef52b661cd8155c8aca9664ce4dca9ea49e5b41ea046607ec3b65d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / mem_patrol-0.2.3-py3-none-any.whl

Download URL mem_patrol-0.2.3-py3-none-any.whl
Size 94.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
106bf292f3d355f7df6ed6008a9a1d0261e9231dddf6589ac183277c50977751
BLAKE2b-256 checksum
How to use checksums
750b44f967c5961af9c969740bdc78021803852317a5ac4e02bf09facae70c6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for mem-patrol 0.2.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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