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.

Passing lease_manager=LeaseManager(store) also registers the advisory coordination tools (mesa_request_lease, mesa_release_lease), which let cooperating agents signal short-lived intent to each other. They are signals, not locks; see Enrichment Section 21 before relying on them.

With a get_semantic_moments callback, mesa_get_profile can also surface the purpose-specific triggers and conditions an entity participates in (Home Assistant 2026.7+), live from HA, for agent context only.

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_integration_profile(profile.entity_id, profile)

Documentation

Status

mesa-core v1.2 is ready for use: profile storage and inheritance, enforcement with confirmation, temporal constraints including solar conditions, the MCP retrieval tools, privacy controls, the advisory lease protocol, and portable profile export/import are all implemented. Multi-agent lease preemption is planned for v2.

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.2.0.tar.gz (169.2 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.2.0-py3-none-any.whl (71.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mesa_core-1.2.0.tar.gz
Algorithm Hash digest
SHA256 05a64574105b0f9f520609d80d7a9406d8e2f78dbb77612b466f84f31ccd3f5d
MD5 f630b6b310263cc36bc654ef5d6c433e
BLAKE2b-256 e17583f77225f6a1176307cdb7a07384dda54cb13bdfc8c9d295af4b7ec742a3

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for mesa_core-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dfecf28ecd27264ce20c33615aa8cbf0addd9236b3b6a83265b46b388ae072f0
MD5 ec7aae8cab17642467a7f7fc84a37850
BLAKE2b-256 e1cd3261831b2ab43d9a6d4d8e6f15135d4a8af63daf270b92a7aebbbd53d27b

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