Metadata-Version: 2.5
Name: mnestiq
Version: 1.1.0
Summary: Tamper-evident flight recorder for AI agents: hash-chained, signed evidence logs with provenance-tagged context.
Project-URL: Homepage, https://mnestiq.com
Project-URL: Repository, https://github.com/mnestiq/mnestiq
Project-URL: Issues, https://github.com/mnestiq/mnestiq/issues
Project-URL: Specification, https://github.com/mnestiq/mnestiq/blob/main/spec/SPEC.md
Project-URL: Changelog, https://github.com/mnestiq/mnestiq/blob/main/CHANGELOG.md
Author: Mnestiq
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: ai-agents,audit-log,forensics,incident-response,llm,provenance,security
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Security
Classifier: Topic :: System :: Logging
Requires-Python: >=3.10
Requires-Dist: cryptography>=42
Requires-Dist: jsonschema>=4.18
Provides-Extra: anthropic
Requires-Dist: anthropic>=0.40; extra == 'anthropic'
Provides-Extra: azure
Requires-Dist: azure-identity>=1.17; extra == 'azure'
Requires-Dist: azure-keyvault-keys>=4.9; extra == 'azure'
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == 'dev'
Provides-Extra: openai
Requires-Dist: openai>=1.40; extra == 'openai'
Provides-Extra: timestamps
Requires-Dist: rfc3161-client>=1.0.3; extra == 'timestamps'
Description-Content-Type: text/markdown

# Mnestiq

**A flight recorder for AI agents.** Tamper-evident, signed evidence of what an agent saw,
decided and did, built for incident response.

Mnestiq records the model calls, tool calls, approvals and outbound connections it is set up to
capture, and tags each piece of model input with its origin: the user, a web page, tool output
or another agent. Records are hash-chained and sealed with signed checkpoints. When an
incident occurs, investigators can identify the run and the step, see which untrusted input
came before it, and, for records under a signed checkpoint, demonstrate that the record has not
been altered since.

Version 1.1: the evidence format and the documented Python API are stable. A change that would
break existing evidence, older verifiers or code using the documented API needs a 2.0.

## Try it

```bash
pip install mnestiq
mnestiq demo
```

A scripted support agent reads a poisoned web page and emails customer data out. The demo records
it, traces a firewall connection back to the agent step, catches a tampered copy, verifies a
redacted copy and opens the local dashboard. No API key, and nothing leaves your machine.

## Install

```bash
pip install "mnestiq[anthropic]"     # or mnestiq[openai], or plain mnestiq
```

Optional extras:

| Extra | Adds |
|---|---|
| `azure` | Signing with keys held in Azure Key Vault or Managed HSM |
| `timestamps` | RFC 3161 timestamps from public timestamp authorities, and their verification |

## Quick start

```python
import anthropic
from mnestiq import FileSink, Recorder
from mnestiq.egress import instrument_egress
from mnestiq.integrations.anthropic import instrument_anthropic
from mnestiq.keys import load_private_key

recorder = Recorder(FileSink("evidence.jsonl"), agent_id="support-bot",
                    signing_key=load_private_key("keys/signing.key"))
client = instrument_anthropic(anthropic.Anthropic(), recorder)
instrument_egress()

with recorder.run():
    ...  # your agent, unchanged

recorder.close()
```

```bash
mnestiq keygen --out keys
mnestiq verify evidence.jsonl --trusted-key keys/signing.pub
mnestiq dashboard . --trusted-key keys/signing.pub
```

## Record an agent without code changes

`mnestiq proxy` sits between an agent and its model API and records every call sent through it,
whatever language or framework the agent is written in. Point the agent's base URL at it:

```bash
mnestiq proxy evidence.jsonl --agent my-agent --key keys/signing.key
export ANTHROPIC_BASE_URL=http://127.0.0.1:8787/anthropic    # or OPENAI_BASE_URL=.../openai/v1
```

OpenAI, Anthropic, Azure OpenAI and OpenAI-compatible servers (Ollama, vLLM, LiteLLM) are supported.
See the [proxy guide](https://github.com/mnestiq/mnestiq/blob/main/docs/proxy.md).

## Production signing

A key file readable by the agent is suitable for evaluation only. In production, keep the
signing key out of the agent's reach, so that a compromised agent cannot copy it. The signing
service also refuses to sign earlier evidence again:

```python
from mnestiq import AzureKeyVaultSigner, FileSink, Recorder, SignerClient, Timestamper

# Azure Key Vault: the key is held by Key Vault, and only a SHA-256 digest is sent.
signer = AzureKeyVaultSigner("https://<vault>.vault.azure.net/keys/<name>/<version>")

# Or a local signing service running under a separate account (`mnestiq signer serve`).
signer = SignerClient.from_env()

recorder = Recorder(FileSink("evidence.jsonl"), agent_id="support-bot", signer=signer,
                    timestamper=Timestamper(),       # independent RFC 3161 timestamps
                    checkpoint_interval=300)         # signed heartbeat when idle
```

Keys are rotated with a signed hand-over (`recorder.rotate_signer(new_signer)`), which the
verifier follows. The signing service signs a hand-over only if it was started with
`--allow-handover`. See the [signing guide](https://github.com/mnestiq/mnestiq/blob/main/docs/signing.md).

## Security model

Evidence is tamper-evident after it is written: with a pinned key, edits, insertions, reordering and
re-signing of records under a checkpoint are detected. Redacted values keep a salted digest, so they
can't be recovered by guessing. The exception is `system_prompt_hash`, a plain digest that redaction
leaves in place, so a guessed system prompt can be confirmed from it. Records cut back past a head kept elsewhere
(a HeadFile or the Evidence Vault) are detected, and backdating is detected against RFC 3161 timestamps. It cannot
prove that a compromised agent told the
truth at the time of writing. The [threat model](https://github.com/mnestiq/mnestiq/blob/main/docs/threat-model.md)
lists each attack considered, how it is detected, and the automated test that demonstrates it.
What it says about the Evidence Vault, a separate service, has no test in this repository.
Independent reviewers are invited to try the
[break-it challenge](https://github.com/mnestiq/mnestiq/blob/main/examples/break-it/README.md).

## Links

- Documentation and examples: https://github.com/mnestiq/mnestiq
- Evidence format specification: https://github.com/mnestiq/mnestiq/blob/main/spec/SPEC.md
- Test vectors for other implementations: https://github.com/mnestiq/mnestiq/tree/main/spec/vectors
- Installation on Windows, macOS and Linux: https://github.com/mnestiq/mnestiq/blob/main/docs/install.md
- Changelog: https://github.com/mnestiq/mnestiq/blob/main/CHANGELOG.md
- Security policy and vulnerability reporting: https://github.com/mnestiq/mnestiq/blob/main/SECURITY.md

## Citing

If you use the recorder or refer to it in your work, please cite it, with the DOI
[10.5281/zenodo.23800724](https://doi.org/10.5281/zenodo.23800724). "Cite this repository" on https://github.com/mnestiq/mnestiq
gives APA and BibTeX entries.

Licensed under Apache-2.0.
