Skip to main content

Reference implementation of the MESA specification: a semantic safety and coordination layer for AI-operated smart environments.

Project description

mesa-core

CI PyPI

mesa-core decides whether an AI agent should be allowed to act on a smart-home device, and how cautious it should be about it.

When an assistant tries to turn on a light, unlock the front door, or change the thermostat, mesa-core answers three questions: is this allowed, should the user confirm it first, and why. It ships with safe defaults (a light is fine to control automatically; unlike a lock) that you refine for each home.

It is the reference implementation of the MESA specification. It has no runtime dependencies and never talks to Home Assistant directly: you hand it device state through callback functions, and it hands you decisions.

pip install mesa-core

Quick look

from mesa_core import MesaEnforcer, ProfileStore
from mesa_core.backends import MemoryBackend

enforcer = MesaEnforcer(ProfileStore(backend=MemoryBackend()))

# An AI agent wants to unlock the front door. Should it?
result = enforcer.evaluate("lock.front_door", "lock.unlock")

result.allowed   # False
result.reason    # "Entity is prohibited by policy: lock.front_door"

How decisions work

  • Every device has a control mode: act freely, ask the user first, read-only, or never act.
  • Devices you have not configured fall back to safe defaults: lights act freely, locks and alarm panels are off-limits, everything else asks first.
  • Rules can be set for a single device, an area, or a whole device type, and are combined with a bias toward caution: the more restrictive rule wins, and anything that cannot be checked blocks rather than allows.
  • You can add finer limits (cap the speaker volume after 10pm) and time-based rules (no blinds before sunrise).

Asking the user to confirm

When a device is set to confirm first, evaluate returns a challenge instead of a yes. Show the action to the user, then call again with the token from the approved challenge.

result = enforcer.evaluate("cover.garage", "cover.open_cover")
if result.confirmation_challenge:
    # present result.confirmation_challenge to the user; once approved,
    # build a confirmation_token from it and re-submit the same call:
    result = enforcer.evaluate(
        "cover.garage", "cover.open_cover",
        confirmation_token=approved_token,
    )

Reading a device's profile

ProfileStore resolves the effective profile after inheritance and defaults. Use a file backend to persist profiles under your HA config:

from mesa_core import ProfileStore
from mesa_core.backends import JsonFileBackend

store = ProfileStore(backend=JsonFileBackend("/config/mesa/"))
profile = store.get_effective("light.living_room_ceiling")
profile.operational_boundaries.control_mode   # ControlMode.AUTONOMOUS

Exposing it to an AI agent (MCP)

Register MESA's tools into an MCP server so the agent can look up profiles and caller context for itself.

from mesa_core.mcp import register_mesa_tools

register_mesa_tools(store, adapter="fastmcp", server=app)

Adapters ship for FastMCP and the MCP Python SDK (pip install "mesa-core[fastmcp]" or "mesa-core[mcp]"). Any other framework can implement a small registration protocol.

Loading profiles shipped by integrations

An HA integration can ship a mesa_profile.json describing its own devices. Load it with:

from mesa_core import import_from_integration

profile = import_from_integration("/config/custom_components/my_integration")
if profile is not None:
    store.set_domain_profile(profile.entity_id, profile)

Documentation

Status

mesa-core v1.0 is ready for use: profile storage and inheritance, enforcement with confirmation, the MCP retrieval tools, and privacy controls are all implemented.

git clone https://github.com/sfox38/mesa-core
cd mesa-core
pip install -e ".[dev]"
pytest tests/ -v       # test suite
ruff check . && mypy   # lint and type check

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

mesa_core-1.0.0.tar.gz (148.5 kB view details)

Uploaded Source

Built Distribution

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

mesa_core-1.0.0-py3-none-any.whl (56.9 kB view details)

Uploaded Python 3

File details

Details for the file mesa_core-1.0.0.tar.gz.

File metadata

  • Download URL: mesa_core-1.0.0.tar.gz
  • Upload date:
  • Size: 148.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for mesa_core-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8cdf7a04e645bc5f4b91be59a1ede743fed8192f747a65377c6ac3336eb1307f
MD5 a06179a6c92458f2852f75589f09aa02
BLAKE2b-256 47543e63251d7539fb8fa10f57b66748975fa54d024237542aa2b4036dbcbf81

See more details on using hashes here.

File details

Details for the file mesa_core-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mesa_core-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 56.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for mesa_core-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 291962fb75b21af90f7b0acf8ddc1a778d579caad3cc14950de47bf604d47d93
MD5 cb051b44fd229b7ffc8770bdb87c352c
BLAKE2b-256 7e0e14d1fd4afa57a816fd69e62fb6c15fffbd44abbb5f67528499143c291b4f

See more details on using hashes here.

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