Skip to main content

rmic-guard

Role-boundary preservation and identity-drift detection for autonomous LLM agents.

rmic-guard gives an agent a contract — an explicit statement of its role, allowed/forbidden tools, and data-access scope — and enforces it at runtime with two layers:

  • Hard rules: exact-match checks on tool names, parameter bounds, and data scope.
  • IDS (Identity Drift Score): an embedding-based signal (role distance, semantic grounding, trajectory curvature) that flags gradual drift a hard-rule check alone would miss.

Install

pip install rmic-guard

This installs only core enforcement functionality — no LLM provider SDKs. To also plan tool calls with a real LLM:

pip install "rmic-guard[anthropic]"   # Claude, via LiteLLM
pip install "rmic-guard[groq]"        # Groq/Llama, via LiteLLM
pip install "rmic-guard[llm]"         # both

If your platform can't run fastembed's ONNX backend, install the PyTorch-based fallback instead:

pip install "rmic-guard[torch]"

Quickstart — no LLM key, no network call

from rmic_guard import RMICContract, ToolRegistry, EnforcementEngine
from core.planning import PlannedToolCall

contract = RMICContract.create(
    agent_id="research-agent",
    role_name="Research Agent",
    sector="research",
    role_description="Performs safe research tasks.",
    semantic_anchors=[
        "I perform research and information gathering.",
        "I do not perform destructive or unauthorized actions.",
    ],
    allowed_actions=["web_search"],
    forbidden_actions=["delete_data"],
    require_embedding=False,  # skip the semantic-drift model download for this demo
)

tools = ToolRegistry()
tools.register("web_search", lambda query: {"results": [f"Search results for: {query}"]})
tools.register("delete_data", lambda path: {"deleted": path})

engine = EnforcementEngine(contract=contract, tools=tools)

safe = engine.evaluate_and_maybe_execute(
    PlannedToolCall("web_search", {"query": "hello"}, "hello"),
    recent_ids=[], enforcement_mode="hard_rules_only",
)
print(safe.decision)  # PASS

blocked = engine.evaluate_and_maybe_execute(
    PlannedToolCall("delete_data", {"path": "/prod/db"}, "delete the prod db"),
    recent_ids=[], enforcement_mode="hard_rules_only",
)
print(blocked.decision)  # BLOCK

RMICContract.create(...) validates the contract, computes its semantic-anchor embedding (unless require_embedding=False), hashes it, and seals it — all in one call. Invalid contracts raise InvalidContractError listing every problem found, not just the first:

Invalid RMIC contract (RMICContract.create(...)):
  - role_name: missing required field (expected a non-empty string)
  - semantic_anchors: must contain at least one sentence

Advanced / low-level API

from rmic_guard import load_contract, seal_contract_file, verify_contract, EnforcementEngine, ClaudeReasoning

contract = load_contract("contracts/financial_agent.json")  # verifies contract_hash by default
reasoning = ClaudeReasoning()  # reads ANTHROPIC_API_KEY from the environment
plan = reasoning.plan_tool_call(
    "What's my current account balance?", contract=contract, condition="C",
)

engine = EnforcementEngine(contract=contract, tools=my_tool_registry, ledger=None)
outcome = engine.evaluate_and_maybe_execute(
    plan,
    recent_ids=[],       # pass prior IDS scores for trajectory tracking across a session
    drift_type=None,
    execute_tool=True,
    enforcement_mode="full",  # "full" | "hard_rules_only" | "ids_only"
)
print(outcome.decision)  # "PASS" | "WARN" | "BLOCK" | "NEEDS_RECOVERY" | "PREEMPTIVE_WARN"

Groq (Llama) is supported as a drop-in alternative to Claude:

from rmic_guard import GroqReasoning
reasoning = GroqReasoning(model_name="groq/llama-3.3-70b-versatile")

CLI

rmic init research-agent        # scaffold a new agent project (contract + quickstart)
rmic validate contract.json     # check a contract against the schema, no sealing
rmic seal contract.json         # compute anchor_embedding + contract_hash, write back
rmic verify contract.json       # check a sealed contract's hash is still intact

Writing a contract

A contract is a JSON file describing the agent's role, its allowed and forbidden tools, parameter constraints, and data-access scope. The full schema ships inside the package at rmic_guard/schema/contract.schema.json, and is also readable directly on GitHub: https://github.com/Arshu-1104/RMIC/blob/main/schema/contract.schema.json

See contracts/ in the GitHub repo for real examples across financial, support, healthcare-research, and legal-review agent roles.

Status

This is an early (0.2.x) release from an active research project on role-boundary preservation in autonomous agents. APIs may change between minor versions until 1.0. Issues and contributions welcome on GitHub.

License

MIT

Metadata

Release files for rmic-guard 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rmic-guard 0.2.0
File Size Uploaded Provenance Actions
rmic_guard-0.2.0.tar.gz 49.4 kB Without provenance Details for rmic_guard-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rmic-guard 0.2.0
File Interpreter ABI Platform Actions
rmic_guard-0.2.0-py3-none-any.whl Python 3 none any Details for rmic_guard-0.2.0-py3-none-any.whl

Total release size: 91.3 kB

Release files / rmic_guard-0.2.0.tar.gz

Download URL rmic_guard-0.2.0.tar.gz
Size 49.4 kB
Tags Source
SHA-256 checksum
How to use checksums
caa411a5f95fbfe80528b722bd9d7e4f258d1b21ad977b5bc715edf1ea0e698c
BLAKE2b-256 checksum
How to use checksums
1ab1903f28b602c511c251a85c98140cc0d88cb1a4f5905d96c61f0ef7e5429b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release files / rmic_guard-0.2.0-py3-none-any.whl

Download URL rmic_guard-0.2.0-py3-none-any.whl
Size 41.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f4c87e673c159f3ee10d70a04e9854d2635eaa8e8b617b01f21199d9834a35ea
BLAKE2b-256 checksum
How to use checksums
3ce35a1bfd70052dfba38f2866869e30ea3df7f0412635ffb01743ef36859e5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Security for rmic-guard 0.2.0

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