# playbooks.simulate

Simular o copiloto do playbook (IA). Aba Testar do editor: dada a conversa simulada (`turns`, até 40 falas, `host` = vendedor e `guest` = cliente), a ficha (`briefing`: objetivo, perfil, fatos, roteiro, proteções) e o que já foi sugerido, a Atom decide se sopra algo ao vendedor agora. Devolve `{suggest: true, title?, text, tone}` (`tone`: info, warning ou urgent) ou `{suggest: false, reason?}` (silêncio). `reason` é o motivo do acionamento (`question` ou `signal`). `agentId` é aceito por compatibilidade e ainda não muda a resposta. Roda no servidor com o modelo claude-haiku-5-5; sem a variável ANTHROPIC_API_KEY responde `credencial_ausente` (503).

- Endpoint: `POST https://app.atomiks.com.br/api/v1/playbooks.simulate` (corpo JSON)
- Quem pode chamar: administrador da conta
- Escopo da chave: `crm:write`
- Grava dados: não
- Pela chave de API: sim
- Ferramenta MCP: `playbooks_simulate`
- Ficha em JSON: `https://app.atomiks.com.br/api/v1/openapi.json` (operationId `playbooks.simulate`)

## Entrada

| Campo | Tipo | Obrigatório | Nota |
|---|---|---|---|
| `agentId` | string | não |  |
| `turns` | object[] | sim |  |
| `reason` | string | não |  |
| `briefing` | object | não |  |
| `alreadySuggested` | string[] | não |  |
| `locale` | string | não |  |

<details><summary>JSON Schema</summary>

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "agentId": {
      "type": "string",
      "maxLength": 100
    },
    "turns": {
      "minItems": 1,
      "maxItems": 40,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "host",
              "guest"
            ]
          },
          "name": {
            "type": "string",
            "maxLength": 80
          },
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4000
          }
        },
        "required": [
          "role",
          "text"
        ]
      }
    },
    "reason": {
      "type": "string",
      "minLength": 1,
      "maxLength": 40
    },
    "briefing": {
      "type": "object",
      "properties": {
        "goal": {
          "type": "string",
          "maxLength": 400
        },
        "persona": {
          "type": "string",
          "maxLength": 1000
        },
        "facts": {
          "maxItems": 30,
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "label": {
                "type": "string",
                "maxLength": 80
              },
              "value": {
                "type": "string",
                "maxLength": 400
              }
            },
            "required": [
              "label",
              "value"
            ]
          }
        },
        "script": {
          "type": "string",
          "maxLength": 12000
        },
        "guardrails": {
          "maxItems": 20,
          "type": "array",
          "items": {
            "type": "string",
            "maxLength": 300
          }
        },
        "timezone": {
          "type": "string",
          "maxLength": 64
        }
      }
    },
    "alreadySuggested": {
      "maxItems": 10,
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 500
      }
    },
    "locale": {
      "type": "string",
      "maxLength": 20
    }
  },
  "required": [
    "turns"
  ]
}
```

</details>

## Exemplo

```bash
curl -X POST https://app.atomiks.com.br/api/v1/playbooks.simulate \
  -H "Authorization: Bearer $ATOMIKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"turns":[{"role":"guest","text":"Achei o valor alto, vou pensar."}],"reason":"signal","locale":"pt-BR"}'
```

CLI:

```bash
node cli/atomiks.mjs playbooks.simulate --json '{"turns":[{"role":"guest","text":"Achei o valor alto, vou pensar."}],"reason":"signal","locale":"pt-BR"}'
```

MCP: ferramenta `playbooks_simulate` com a mesma entrada.

## Saída

Sucesso: `{"data": ...}` com o formato abaixo.

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "suggest": {
      "type": "boolean"
    },
    "title": {
      "type": "string"
    },
    "text": {
      "type": "string"
    },
    "tone": {
      "type": "string",
      "enum": [
        "info",
        "warning",
        "urgent"
      ]
    },
    "reason": {
      "type": "string"
    }
  },
  "required": [
    "suggest"
  ],
  "additionalProperties": false
}
```

## Erros

`{"error": {"code", "message", "requestId"}}`. Códigos: `invalid_input` (400), `unauthorized` (401), `forbidden` / `account_pending` / `scope_missing` (403), `not_found` (404), `limit_reached` (409), `internal` (500).
