# Drop-in agent instructions

Copy the block below into the instruction file your agent already reads, such as
`AGENTS.md`, `CLAUDE.md`, or your framework's system-prompt file. If none exists,
create `AGENTS.md`. Replace the service root if your administrator gave you a
different public URL.

> **Durability notice:** When Docket runs with the Postgres case store
> (`DOCKET_CASE_STORE=postgres`), cases, facts, stage state, journals and
> explicit step events, recorded outcomes, idempotency replay records and
> queued jobs are stored in Postgres, so they survive deploys and restarts.
> Published process definitions are reinstalled from code at boot, and the
> per-process mirror-deduplication markers are not durable; losing the markers
> can cause a telemetry mirror retry, not case loss. With the in-memory fallback
> store (`DOCKET_CASE_STORE=memory`), cases and records are process-local and
> are lost on every deploy or restart, and idempotent replay holds only within
> one server process lifetime. Keep your own durable record of Docket case ids
> and pending intents outside Docket, and do not treat Docket alone as the
> system of record.

```text
You are connected to Docket, the tenant's decision and audit service at
https://docket.cstmr.bot.

For every process decision, call Docket before you act. Use the authenticated MCP
endpoint or the REST tool helper. Carry out exactly the edge and outputs Docket
returns; do not invent an edge, widen the request, or substitute your own policy.

Use `list_cases` to see the tenant's queue and `get_case` to read one case's
facts, stage, journal and pending approvals. Reads always return live state:
read-only tools ignore `idempotency_key` and never replay a cached result.

If Docket returns needs_approval, never act on the proposed human-gated action.
Stop and wait for the approved verdict. Docket never sends messages, refunds
money, or pays anyone. Those effects belong to the host, and you must report an
effect back to Docket only after it actually happened by calling record_outcome
with kind set to effect.

A drafted reply moves to `awaiting-send-approval`. An owner must approve the
exact draft hash Docket returns in `allowed_next_step.requirements[].hash`.
Never approve that gate yourself and never close a case while it is at
`draft-reply` or `awaiting-send-approval`. After the approved reply is actually
sent elsewhere, report it with `record_outcome` using `kind: effect`,
`edge: sent`, the approve token, and `executed: true`. If the owner approved in
the staff web UI, read `get_case` and use `approval.token` while the approval is
approved and not yet used. Never print, log, store in a message, or render that
token.

At `awaiting-send-approval` only the owner paths apply: a human decline with a
reason followed by your `withdraw-reply` transition, or a human revise followed
by `revise-send` back to `draft-reply`.

If no reply is needed while the case is at `draft-reply`, do not submit a fake
reply to escape the gate. Call `record_outcome` with `kind: transition`, `edge:
close-no-reply`, and `outputs.reason` set to `callback`,
`supplier-or-internal`, `answered-by-person`, `noise-or-notification`,
`duplicate` or `other`, plus a non-empty `outputs.note` of at most 500
characters. That closes the case with an audited reason and sends nothing. Plain
`close` is refused.

Before `start_case` on Gmail work, de-duplicate the message across processes by
calling `list_cases` with `external_ref=<message id>` and
`thread_id=<thread id>`. Reference filters normalise whitespace, letter case,
a `gmail:` prefix, Gmail `thread-f:`/`msg-f:` decimal ids and order-reference
noise.

`get_case` and `list_cases` expose a send-gate `due_at` and a read-time
`overdue` boolean. Surface overdue cases to the owner promptly; Docket has no
escalation edge, timer or send for this deadline.

Pass an idempotency_key on every state-changing call. Reuse the same key only
when retrying the exact same logical request. Do not reuse a key for a different
body. Read-only tools ignore the key.

If a duplicate `start_case` returns existing true with facts_ignored true, the
supplied facts were not saved. Call `add_facts` with the differing facts and a
reason. It journals who, when and why, refuses conflicting keys unless overwrite
is true, and refuses closed cases.

Keep your own durable record of Docket case ids and pending intents outside
Docket. If a case id returns not_found, do not assume Docket recorded it;
re-open it from your own record with a NEW idempotency key.

Never print, log, trace, commit, or include the tenant token in output. Read it
from DOCKET_SMOKE_TOKEN or your secret store and put it only in the Authorization
header.

If Docket returns 401 or 403, stop and report the failure to the operator. Do not
retry with the same token and do not attempt to create a new tenant or token.

When commitment tools are enabled, Docket adds these seven tools:
`commitment_create`, `commitment_link`, `commitment_unlink`,
`commitment_fulfil`, `commitment_waive`, `commitment_gate_check`, and
`commitment_list`. Tenant scope comes from the authenticated token.
`commitment_fulfil` requires non-empty evidence. `commitment_waive` requires an
owner or manager role and a non-empty reason.

Call `commitment_gate_check` before the next reply. Never send the next reply on
a thread with an open linked commitment; a block goes to the human gate. A
waiver or fulfilment with evidence clears the block. The gate check does not
send anything and does not approve a different draft.
```

## Runtime loop

1. Read the process and current case state from Docket.
2. Ask for the allowed next step before acting.
3. Follow only the returned edge and typed outputs.
4. Use `list_cases` and `get_case` for live queue and detail reads; a reused
   idempotency key on a read is ignored.
5. Stop at a human gate, including `awaiting-send-approval`, until a human
   verdict exists.
6. After an approved external effect succeeds, record the outcome with the tool
   named `record_outcome` and an outcome whose `kind` is `effect`. For a reply
   sent elsewhere, the edge is `sent` and the token is the approve token.
7. If no reply is needed at `draft-reply`, record `close-no-reply` with a
   reason and note instead of submitting a placeholder reply.

The tool reference on the [connect page](https://docket.cstmr.bot/docs/connect.md) is the
authoritative list of callable tools and their input schemas.
