Metadata-Version: 2.4
Name: django-reststroke
Version: 0.1.0a4
Summary: Human-in-the-loop approval for the tool calls of AI agents, in Django: an MCP gateway asks your Django project about each call, a rule or a person accepts or refuses it before it reaches its tool, and an append-only audit log keeps every decision.
Keywords: django,ai-agents,human-in-the-loop,approval,audit
Author: tryph0n
License-Expression: Apache-2.0
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: Django
Classifier: Framework :: Django :: 6.1
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Requires-Dist: django>=6.1,<6.3
Requires-Dist: fastmcp>=4.2.6,<4.3 ; extra == 'gate'
Requires-Dist: httpx2>=2.5.0,<3 ; extra == 'gate'
Requires-Python: >=3.12
Project-URL: Documentation, https://django-reststroke.readthedocs.io/
Project-URL: Source, https://github.com/tryph0n/django-reststroke
Project-URL: Issues, https://github.com/tryph0n/django-reststroke/issues
Project-URL: Changelog, https://github.com/tryph0n/django-reststroke/blob/main/CHANGELOG.md
Provides-Extra: gate
Description-Content-Type: text/markdown

# django-reststroke

*Agent actions rest until a human lets them play.*

Human-in-the-loop approval for the tool calls of AI agents, in Django: an MCP gateway asks your Django project about each call, a rule or a person accepts or refuses it before it reaches its tool, and an append-only audit log keeps every decision.

[![PyPI version](https://img.shields.io/pypi/v/django-reststroke)](https://pypi.org/project/django-reststroke/)
[![Python versions](https://img.shields.io/pypi/pyversions/django-reststroke)](https://pypi.org/project/django-reststroke/)
[![Django versions](https://img.shields.io/pypi/frameworkversions/django/django-reststroke)](https://pypi.org/project/django-reststroke/)
[![Documentation status](https://app.readthedocs.org/projects/django-reststroke/badge/?version=latest)](https://django-reststroke.readthedocs.io/)
[![CI](https://github.com/tryph0n/django-reststroke/actions/workflows/ci.yml/badge.svg)](https://github.com/tryph0n/django-reststroke/actions/workflows/ci.yml)
[![License](https://img.shields.io/pypi/l/django-reststroke)](https://github.com/tryph0n/django-reststroke/blob/main/LICENSE)

What reststroke guarantees:

- **[Human-in-the-loop approval](https://django-reststroke.readthedocs.io/page/explanation/how-it-works.html#human-in-the-loop-approval).** A call that no rule decides waits for a person with the right to decide, who sees its exact arguments.
- **[Exfiltration mitigation](https://django-reststroke.readthedocs.io/page/explanation/how-it-works.html#exfiltration-mitigation).** No rule accepts a call to a tool marked "sends data out" (the default) or to a tool whose current definition no person reviewed.
- **[Rules and requester rights](https://django-reststroke.readthedocs.io/page/explanation/how-it-works.html#rules-and-requester-rights).** Rules answer routine calls at once; the strictest wins, and no rule accepts a call above the rights of the requester.
- **[The exact call, at most once](https://django-reststroke.readthedocs.io/page/explanation/how-it-works.html#the-exact-call-at-most-once).** Before the forward, reststroke checks the fingerprint (SHA-256) of the call and the rights again; an accepted call reaches its tool at most once.
- **[Tool keys in the gate, fail closed](https://django-reststroke.readthedocs.io/page/explanation/how-it-works.html#tool-keys-in-the-gate-fail-closed).** Only the gate holds the tool keys, and no call passes it while your Django project does not answer.
- **[Two-person activation, append-only audit](https://django-reststroke.readthedocs.io/page/explanation/how-it-works.html#two-person-activation-append-only-audit).** A new rule text acts only after a second person, or a superuser author, activates it. The models and the admin refuse to change or delete an audit entry.

**Status:** alpha. The API, the settings and the database schema can change between releases, and the [changelog](https://github.com/tryph0n/django-reststroke/blob/main/CHANGELOG.md) lists each breaking change. Not for production use yet.

What it does not do ([all the limits](https://django-reststroke.readthedocs.io/page/explanation/security-model.html)):

- At most once: when the tool server does not answer, the gate does not send the call again, and its outcome becomes "unknown".
- Only `tools/list` and the accepted `tools/call` requests reach a tool server; the gate refuses the requests for resources and prompts.
- No detection of prompt injection: a call that a hidden instruction causes meets the same checks as any other call.

## How a tool call passes

The agent sends each tool call to the gate, an MCP gateway that runs apart from Django and holds the keys of your tools. The gate asks your Django project if the call may pass, and sends only an accepted call to its tool ([how it works](https://django-reststroke.readthedocs.io/page/explanation/how-it-works.html)).

![Activity diagram of the path of one tool call, with one lane for each part and the key that each part holds](https://raw.githubusercontent.com/tryph0n/django-reststroke/main/doc/diagrams/call-path-activity.drawio.png)

## Why the approval of an agent framework is not enough

An agent framework gives a pause and a yes or no. It does not check the rights of the requester again before the call goes out, and it keeps no audit trail. reststroke adds rules on each tool, a decision by a person who has the right to decide, a gate that holds the tool keys, and the audit trail. Each team would have to code these again in each tool. An automatic check does not replace a person.

## Design decisions and checks

Read the [security model](https://django-reststroke.readthedocs.io/page/explanation/security-model.html), the [design decisions](https://django-reststroke.readthedocs.io/page/adr/index.html) and [how reststroke is built and checked](https://django-reststroke.readthedocs.io/page/project/how-it-is-built.html).

How it is built: the maintainer sets the plan and takes every design decision. The maintainer shapes each issue with an AI agent, which writes it, and reads each issue, and each pull request before its merge. AI agents write the code, the tests and the docs, in a workflow that the maintainer designed: one agent builds each issue, a separate agent checks each commit against its issue, and the CI runs the tests and the scans before each merge.

## Try the demo

The demo runs in Docker: a Django project with reststroke, the gate, demo tools and a scripted agent that obeys an instruction hidden in a note. You need git and Docker; the [tutorial](https://django-reststroke.readthedocs.io/page/getting-started/tutorial.html) gives the versions and the ports. The demo is in French.

```sh
git clone https://github.com/tryph0n/django-reststroke.git
cd django-reststroke
cp .env.example .env
docker compose up -d --wait
docker compose exec web python manage.py seed_demo
docker compose exec agent python -m scripted_agent --gate-url http://gate:8100/mcp
```

The last command then waits for a person. The [tutorial](https://django-reststroke.readthedocs.io/page/getting-started/tutorial.html) shows how to refuse that call as `bob` in the inbox, and what the agent logs then.

## Requirements

- Python 3.12 or later.
- Django 6.1.
- PostgreSQL: the demo and the CI tests run on it.

## Quick start

In your Django project:

1. Install the package: `pip install django-reststroke`. On the machine where the gate runs: `pip install "django-reststroke[gate]"`.
2. Add `"reststroke"` to `INSTALLED_APPS`.
3. In the root URL configuration, include the interface of the gate and the inbox: `path("reststroke/", include("reststroke.urls"))` and `path("inbox/", include("reststroke.inbox_urls"))`.
4. Create the tables: `python manage.py migrate`.
5. Make the key of the gate with `python manage.py new_gate_key gate.key`, and add the hash that it prints to the setting `RESTSTROKE_GATE_KEY_HASHES`.

Then follow [Install in your project](https://django-reststroke.readthedocs.io/page/getting-started/install.html) for the other steps, the cron line of `expire_calls` included, and [Run the gate and add an agent](https://django-reststroke.readthedocs.io/page/how-to/gate-and-agent.html).

## Links

- Documentation: <https://django-reststroke.readthedocs.io/>
- Changelog: [CHANGELOG.md](https://github.com/tryph0n/django-reststroke/blob/main/CHANGELOG.md)
- Security policy: report a vulnerability privately, as [SECURITY.md](https://github.com/tryph0n/django-reststroke/blob/main/.github/SECURITY.md) explains.
- Contributing: [CONTRIBUTING.md](https://github.com/tryph0n/django-reststroke/blob/main/CONTRIBUTING.md), the developer guide.
- License: Apache-2.0, see [LICENSE](https://github.com/tryph0n/django-reststroke/blob/main/LICENSE).

## About the name

Named after the rest stroke, the gypsy jazz picking technique Django Reinhardt used: the pick comes to rest on the next string before the note moves on.
