# Agents as customers: rules per agent and who answers for them

An agent that signs its requests names itself: Shield calls it by the host of its key directory (`agent.example`). You can decide, per agent, what it may do on your site, and see who answers for it.

## 1. Set the rules

A site has a default for declared agents: `welcome`, `read_only` (the default), `refuse`, or `accountable_only` (any declared agent may read; it may act only if its owner was verified). On top of it, a rule per agent:

```js
await fetch("https://shield.praecise.com/agents?site=ps_...", {
  method: "PUT",
  headers: { "Content-Type": "application/json", Authorization: "Bearer " + process.env.SHIELD_SECRET },
  body: JSON.stringify({
    default: "accountable_only",
    agents: {
      "shop-helper.example": { mode: "welcome" },
      "crawler.example": { mode: "ceiling", perMinute: 30, note: "be gentle" },
      "scraper.example": { mode: "refuse", note: "scraped us in November" },
    },
  }),
});
```

A field you send replaces that field whole: send `agents` and it is the full list of rules. `GET /agents?site=ps_...` reads them. A Praecise product with the admin key does the same at `/sites/<site>/agents`.

Modes: `welcome` (reads and acts allowed), `read_only` (reads allowed, acts refused), `ceiling` (reads and acts allowed up to `perMinute` requests a minute, counted per site and agent in memory, so a restart forgets the minute), `refuse`. A `note` of up to 200 characters is kept and quoted in the reason.

## 2. Ask for the decision

Call `POST /verify-agent` as before, and add `intent` (`"read"` or `"act"`) when the method does not say it: GET and HEAD read, the rest act.

```js
// { ok: true, class: "declared_agent", agent, keyid,
//   decision: { allowed: false, rule: "read_only", reason: "..." },
//   accountable: { kind: "network_identity", id: "0x...", verified: true, since: "..." } | null }
```

`decision.rule` is `welcome`, `read_only`, `ceiling`, `refuse`, or `default` when no rule names the agent. Your server enforces `allowed`: Shield only answers. A caller that did not sign gets `{ ok: false, class: "undeclared", reason }` and no decision.

The weekly report (`GET /report?site=...`) gains `agents`: each agent seen, with requests, allowed, refused, the rule that applied and one sentence in plain words.

## 3. Who answers for an agent

An agent's operator proves control of the agent's name, then states an owner.

1. `POST /agent-owners` with `{ "agent": "agent.example" }` gives a `token`.
2. Publish `{ "token": "..." }` at `https://agent.example/.well-known/praecise-agent.json` (https only, public host, no redirect).
3. `POST /agent-owners/prove` with the same body: when Shield reads the token, it answers `manageSecret`, shown once.
4. `PUT /agent-owners/agent.example` with `Authorization: Bearer <manageSecret>` and `{ "owner": ... }`:
   - `{ "kind": "organisation", "name": "Legal Name Ltd", "contact": "legal@agent.example" }`: self-declared, never marked verified.
   - `{ "kind": "network_identity", "address": "0x...", "proof": "0x..." }`: the proof is the identity's signature (EIP-191 personal message) over the text `praecise-shield agent <host> owner <address> <token>`. Verified only when the signature recovers that address. Another form of address is kept as "claimed, not verified".
   - `{ "kind": "praecise_account", "id": "..." }`: only a Praecise product with the admin key can set it, after the person signed in there.

`verify-agent` returns `accountable` for an agent that has an owner. `accountable.verified` is true only for a praecise_account and for a network_identity whose signature matched.

## What this does not tell you

- A signature proves control of a key directory, not good intent. A declared agent can still misbehave: that is what the rules and the ceiling are for.
- An owner of kind `organisation` is self-declared: Shield did not check the name or the address.
- An agent that does not declare itself is not covered by any of this: it is judged as any other caller, by the quiet check.
- The network identity check covers Ethereum-style addresses; it has not met a real agent network identity yet.

## What Shield does not do

- It is early and unproven.
- A touch is not proof of a human: the device is not attested yet.
- An agent driving a real browser passes as a person.
- The signature check for declared agents has not met a real agent yet.
- The agent owner check (a signature over an Ethereum-style address) has not met a real network identity yet.
- There are no edge rules and no certificates.
- One instance; counts are kept on its disk.
