Skip to main content

mastyf-ai

Mastyf's free checks for your AI agent's tools. Every tool call is checked before it runs, and every tool result before your model reads it. It all runs on your own machine: nothing is sent to Mastyf.

pip install "mastyf-ai[langchain]"      # or [langgraph], [openai-agents]

The first check starts Mastyf's free check program on this machine (downloaded once from the project's GitHub release and run only if its SHA-256 matches the one in this package). It stops when your program stops.

LangChain

from mastyf_ai.langchain import guard_tools

agent = create_agent(model, tools=guard_tools([search, read_file]))

LangGraph

from langgraph.prebuilt import ToolNode
from mastyf_ai.langgraph import guard_tool_node

graph.add_node("tools", guard_tool_node(ToolNode([search, read_file])))

OpenAI Agents SDK

from agents import Agent
from mastyf_ai.openai_agents import guard_function_tools

agent = Agent(name="helper", tools=guard_function_tools([search, read_file]))

Hosted tools (web search, file search, code interpreter) run on OpenAI's servers, where no local check can reach them. They're passed through unchanged and a warning is logged.

Shell, computer and apply-patch tools run on your machine but can't be checked yet, so guard_function_tools() refuses them rather than letting them through silently.

Any other framework

from mastyf_ai import Guard

guard = Guard()                      # one Guard per agent run
verdict = guard.check_call("read_file", {"path": path})
if verdict.blocked:
    return verdict.model_message()   # "Blocked by Mastyf (hooks: hook-before)."
result = read_file(path)
after = guard.check_result("read_file", result, {"path": path})
if after.blocked:
    return after.model_message()
return after.result if after.decision == "redact" else result

A blocked call never runs. The model is told which check stopped it, never the text that was matched.

Some checks look at a whole run (for example, reading a secret file and then sending data out). An agent that serves many users should give each request its own session, so one user's run never affects another's:

guard = Guard()
tools = guard_tools([search, read_file], guard=guard)

async def handle(request):
    with guard.session(request.id):
        return await agent.ainvoke(request.messages)

MCP servers

Run an MCP server through the check program and every call and result passes through the same checks:

mastyf-check proxy -- npx -y @modelcontextprotocol/server-filesystem ./project

When no check can be made

By default a call fails with MastyfUnavailable instead of running unchecked. To let calls through with a warning instead, use Guard(on_unavailable="allow"). An input the check refuses (for example, one too large to check) is always blocked, in either mode.

Other settings:

  • MASTYF_CHECK_URL and MASTYF_CHECK_TOKEN: use a check service you run (for example the Docker image) instead of starting one.
  • MASTYF_CHECK_BIN: use a copy of the check program you already have.
  • mastyf-ai status shows which checks are in use; mastyf-ai check read_file '{"path": "/etc/passwd"}' checks one call from the terminal.

Upgrading from 4.x

4.x sent tool calls to a Mastyf proxy (MastyfProxy("http://localhost:4000")). 5.0 doesn't need a proxy: replace MastyfProxy and the old middleware with guard_tools, guard_tool_node, guard_function_tools or Guard as above.

Paid protection

The Shield app adds Mastyf's paid checks and a dashboard of what was blocked: sign up and choose a plan at mastyf.ai, then install Shield. While Shield is running on the same computer, this library uses it on its own, with no change to your code: your agent's calls are checked by Shield and appear in your Mastyf dashboard under the agent's name (Guard(agent="billing-bot"), or MASTYF_AI_AGENT). guard.tier is then "shield". The library only talks to Shield on 127.0.0.1, and only after Shield proves it holds the key in its own file.

Licence

MIT. The check program it starts is AGPL-3.0 and runs as a separate program.

Metadata

Release files for mastyf-ai 5.0.2

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

Source distribution (sdist)

Source distribution for mastyf-ai 5.0.2
File Size Uploaded Provenance Actions
mastyf_ai-5.0.2.tar.gz 25.9 kB Without provenance Details for mastyf_ai-5.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mastyf-ai 5.0.2
File Interpreter ABI Platform Actions
mastyf_ai-5.0.2-py3-none-any.whl Python 3 none any Details for mastyf_ai-5.0.2-py3-none-any.whl

Total release size: 45.9 kB

Release files / mastyf_ai-5.0.2.tar.gz

Download URL mastyf_ai-5.0.2.tar.gz
Size 25.9 kB
Tags Source
SHA-256 checksum
How to use checksums
2b2f516cfc55f4ff1fe5cff50538401afef49e020c89bd17d67af349df4cd40d
BLAKE2b-256 checksum
How to use checksums
601ef44be316348f79db5f574e516f6acadae7d686d8dab38db82f944ff9184c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Release files / mastyf_ai-5.0.2-py3-none-any.whl

Download URL mastyf_ai-5.0.2-py3-none-any.whl
Size 20.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9fb3d2ea2a2848c71405f86bbd8f8e9ba61a445198c98a099ec6c4893d570eee
BLAKE2b-256 checksum
How to use checksums
20a6032738c6d5cee80e46c7c77b8df5124bcd48aa130773a93e4d2d82989cd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Security for mastyf-ai 5.0.2

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