# Agent Audit Ledger - Tamper-Evident Action Log (`apricot_blackberry/agent-audit-ledger`) Actor

A tamper-evident record of everything your agent does. Hash-chains each decision, tool call, and cost into a verifiable ledger and pinpoints the exact entry if anything is altered - accountability and forensics for autonomous agents.

- **URL**: https://apify.com/apricot\_blackberry/agent-audit-ledger.md
- **Developed by:** [Creator Fusion](https://apify.com/apricot_blackberry) (community)
- **Categories:** Developer tools, Business
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per event

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Agent Audit Ledger

**Creator Fusion Labs — Agent Protection Suite**

Give your AI agent a **tamper-evident, hash-chained record** of everything it did — a forensic trail you (or an auditor) can verify later. Feed it a list of actions and it returns a sha256 chain where every link depends on the one before it, so a single altered, reordered, or inserted event breaks the chain and is pinpointed exactly.

Built for agents: call it over **MCP**, `curl`, JS, or Python. Deterministic by design — the same events always produce the same hashes (no wall-clock is ever mixed into a hash), so any party can reproduce and check the ledger.

***

### What it does

- **`append` mode** — canonicalizes each event (stable key order), sha256-hashes it (`eventHash`), and hash-chains it: `chainHash[i] = sha256(chainHash[i-1] + eventHash[i])`, seeded by your `prevHash` or a built-in genesis constant. Emits one row per event plus a summary (`headHash`, `eventCount`, `totalCost`, `verifiable`).
- **`verify` mode** — takes events that already carry their `eventHash`/`chainHash`, recomputes everything, and reports the **first broken link** (`breakIndex`) — catching tampered values, reordering, and insertions.

Chain runs together: pass one run's `headHash` as the next run's `prevHash` to build a single unbroken ledger across many runs.

***

### Input

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `events` | array | yes | Action objects. Each needs a string `action`; optional `ts`, `actor`, `detail`, `cost` (number). In `verify` mode, include the `eventHash`/`chainHash` each event was emitted with. |
| `mode` | string | no | `append` (default) or `verify`. |
| `prevHash` | string | no | Head hash of a prior chain to continue from. Omit to seed from genesis. |

An event with no `ts` keeps `ts: null` — the ledger never injects the current time, so the chain stays reproducible.

```json
{
  "events": [
    { "ts": "2026-08-19T10:00:00Z", "actor": "agent-a", "action": "search", "detail": "query=competitors", "cost": 0.01 },
    { "ts": "2026-08-19T10:00:01Z", "actor": "agent-a", "action": "fetch", "detail": "url=example.com", "cost": 0.02 },
    { "actor": "agent-a", "action": "summarize", "detail": "3 sources", "cost": 0.03 }
  ],
  "mode": "append"
}
```

### Output

Per-event rows:

```json
{ "rowType": "event", "seq": 0, "ts": "2026-08-19T10:00:00Z", "actor": "agent-a",
  "action": "search", "detail": "query=competitors", "cost": 0.01,
  "eventHash": "…", "chainHash": "…" }
```

One summary row:

```json
{ "rowType": "summary", "headHash": "…", "eventCount": 3, "totalCost": 0.06,
  "verifiable": true, "breakIndex": null }
```

In `verify` mode each event row also carries `storedEventHash`, `storedChainHash`, and `ok`; the summary sets `verifiable: false` and `breakIndex` to the first failing index when the chain is broken.

***

### Verifying a chain (tamper detection)

Take the rows from an `append` run, change any one field, and re-run in `verify` mode. The summary comes back `verifiable: false` with `breakIndex` at the altered event.

```json
{ "mode": "verify", "prevHash": "<the append run's prevHash>",
  "events": [ /* the emitted event rows, one of them tampered */ ] }
```

***

### Integration

**MCP** — expose this actor to your agent via the Apify MCP server and call it by name (`apricot_blackberry/agent-audit-ledger`) with the input above.

**curl**

```bash
curl -X POST "https://api.apify.com/v2/acts/apricot_blackberry~agent-audit-ledger/run-sync-get-dataset-items?token=$APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"events":[{"actor":"agent-a","action":"search","cost":0.01}],"mode":"append"}'
```

**JavaScript**

```js
import { ApifyClient } from 'apify-client';
const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
const run = await client.actor('apricot_blackberry/agent-audit-ledger').call({
  events: [{ actor: 'agent-a', action: 'search', cost: 0.01 }],
  mode: 'append',
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(items);
```

**Python**

```python
from apify_client import ApifyClient
client = ApifyClient(os.environ["APIFY_TOKEN"])
run = client.actor("apricot_blackberry/agent-audit-ledger").call(run_input={
    "events": [{"actor": "agent-a", "action": "search", "cost": 0.01}],
    "mode": "append",
})
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)
```

***

### Pricing

Pay-per-event: a small actor-start fee plus one **`ledger`** charge per successful run. Failed runs (bad input) are not charged.

### Notes

- Crypto is standard `node:crypto` sha256 over a canonical (sorted-key) JSON encoding of each event.
- Fully deterministic — no randomness, no wall-clock in any hash.
- Run `npm test` locally for a free self-check of the chain and tamper-detection logic.

# Actor input Schema

## `events` (type: `array`):

The agent actions to record (append mode) or verify (verify mode). Each item is an object with a required string 'action', plus optional 'ts' (timestamp string), 'actor' (who did it), 'detail' (free-form value), and 'cost' (number). In verify mode, each item should also carry the 'eventHash' and 'chainHash' it was emitted with so they can be recomputed and checked.

## `mode` (type: `string`):

'append' (default) builds a fresh hash chain over the events and emits per-event rows plus a summary. 'verify' recomputes the chain from the supplied eventHash/chainHash values and reports the first broken link (tampered, reordered, or inserted event).

## `prevHash` (type: `string`):

Optional. The head hash of a prior chain to continue from, so multiple runs form one unbroken ledger. Leave empty to seed from the built-in genesis constant. Used as the chain seed in both append and verify modes.

## Actor input object example

```json
{
  "events": [
    {
      "ts": "2026-08-19T10:00:00Z",
      "actor": "agent-a",
      "action": "search",
      "detail": "query=competitors",
      "cost": 0.01
    },
    {
      "ts": "2026-08-19T10:00:01Z",
      "actor": "agent-a",
      "action": "fetch",
      "detail": "url=example.com",
      "cost": 0.02
    },
    {
      "actor": "agent-a",
      "action": "summarize",
      "detail": "3 sources",
      "cost": 0.03
    }
  ],
  "mode": "append"
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "events": [
        {
            "ts": "2026-08-19T10:00:00Z",
            "actor": "agent-a",
            "action": "search",
            "detail": "query=competitors",
            "cost": 0.01
        },
        {
            "ts": "2026-08-19T10:00:01Z",
            "actor": "agent-a",
            "action": "fetch",
            "detail": "url=example.com",
            "cost": 0.02
        },
        {
            "actor": "agent-a",
            "action": "summarize",
            "detail": "3 sources",
            "cost": 0.03
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("apricot_blackberry/agent-audit-ledger").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "events": [
        {
            "ts": "2026-08-19T10:00:00Z",
            "actor": "agent-a",
            "action": "search",
            "detail": "query=competitors",
            "cost": 0.01,
        },
        {
            "ts": "2026-08-19T10:00:01Z",
            "actor": "agent-a",
            "action": "fetch",
            "detail": "url=example.com",
            "cost": 0.02,
        },
        {
            "actor": "agent-a",
            "action": "summarize",
            "detail": "3 sources",
            "cost": 0.03,
        },
    ] }

# Run the Actor and wait for it to finish
run = client.actor("apricot_blackberry/agent-audit-ledger").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "events": [
    {
      "ts": "2026-08-19T10:00:00Z",
      "actor": "agent-a",
      "action": "search",
      "detail": "query=competitors",
      "cost": 0.01
    },
    {
      "ts": "2026-08-19T10:00:01Z",
      "actor": "agent-a",
      "action": "fetch",
      "detail": "url=example.com",
      "cost": 0.02
    },
    {
      "actor": "agent-a",
      "action": "summarize",
      "detail": "3 sources",
      "cost": 0.03
    }
  ]
}' |
apify call apricot_blackberry/agent-audit-ledger --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,apricot_blackberry/agent-audit-ledger"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/b90LkOVdLDTW9nICa/builds/TJaFNMzp52j4Xo3uL/openapi.json
