# Preview a procedure turn

```http
POST https://trydimmi.com/api/v1/procedures/{procedure}/simulate
```

## Authorization

Send an API token as `Authorization: Bearer <token>`.
The token needs: `ai:write`.

## Path parameters

- `procedure` (string, required): Id of the AI agent procedure, starting with prc_, such as prc_01jx2m8k4t. Find it with GET /procedures.

## Body

- `action_mocks` (object): What each action answers instead of really being called, as an object keyed by action id; each value has status (HTTP status, 100 to 599) and body (any JSON), such as {"aac_abc123": {"status": 200, "body": {"order": {"status": "shipped"}}}}. An action with no mock answers with the result of its last live test.
- `active_state` (object)
  - `branches` (object): Copy it unchanged from the state the last preview turn handed back: an object of step id to the side that step took.
  - `called_action_ids` (string[] | null): Copy it unchanged from the state the last preview turn handed back: the list of ids of the actions already called, such as ["aac_01jx2m8k4t"].
  - `completed_step_ids` (string[] | null): Copy it unchanged from the state the last preview turn handed back: the list of ids of the procedure's steps already done.
  - `pending` (object[] | null): Copy it unchanged from the state the last preview turn handed back: the list of writes still waiting to be confirmed or approved, each with action_id, tool, args, state and summary.
    - `action_id` (string, required): Id of the action whose write is waiting, starting with aac_, such as aac_01jx2m8k4t, copied from the last turn's state. Put it in confirmed_action_ids to confirm it.
    - `args` (object): The arguments the waiting write would be called with, as an object, copied unchanged from the last turn's state, such as {"order_id": "1042"}.
    - `state` (string): Why the write waits, copied from the last turn's state: awaiting_confirmation (the customer must confirm) or pending_approval (a teammate must approve).
    - `summary` (string): The short text that says what the waiting write would do, copied unchanged from the last turn's state.
    - `tool` (string, required): The tool name of the action whose write is waiting, copied unchanged from the last turn's state.
  - `procedure_id` (string): Id of the procedure the conversation is in, starting with prc_, such as prc_01jx2m8k4t, copied from the state the last preview turn handed back.
  - `status` (string): Where the procedure stands, copied from the state the last preview turn handed back: active, completed, handed_off or exited. Only active carries the procedure on.
  - `step_outputs` (object): Copy it unchanged from the state the last preview turn handed back: an object of what the procedure's steps have produced so far.
- `confirmed_action_ids` (string[] | null): Ids of the waiting writes you confirm or approve this turn, taken from action_id in the pending list of the state the last simulated turn handed back (send that state as active_state). At most 10, such as ["aac_abc123"]. You may send these without a message.
- `history` (object[] | null): The turns so far, oldest first, as returned by earlier calls.
  - `role` (string, required): Who wrote this earlier message: customer or agent, such as "customer". One of: `customer`, `agent`.
  - `text` (string, required): What that earlier message said, at most 4000 characters, such as Hi, where is my order?
- `message` (string): What the customer writes, up to 4000 characters.
- `persona` (object)
  - `attributes` (object): The made-up customer's custom attributes, as an object of attribute key to value. They count as trusted. Such as {"plan": "pro"}.
  - `channel` (string): The channel the made-up customer writes from: widget, email, slack, whatsapp, instagram, facebook or api. Left out or empty, it is widget. Such as "email". One of: `widget`, `email`, `slack`, `whatsapp`, `instagram`, `facebook`, `api`, ``.
  - `company` (object): The custom attributes of the made-up customer's company, as an object of attribute key to value, such as {"plan": "enterprise"}.
  - `email` (string): The made-up customer's email address, at most 320 characters, such as ada@example.com.
  - `external_id` (string): Your own system's id of the made-up customer, at most 200 characters, such as user_8421. Giving one makes them a known user, not a lead.
  - `inbox_id` (string): Id of the inbox the made-up conversation is placed in, starting with inbox_, such as inbox_01jx2m8k4t. Find it with GET /inboxes.
  - `name` (string): The made-up customer's name, at most 200 characters, such as Ada Lovelace.
  - `verified` (boolean): true when the made-up customer is signed in, so their identity and email count as verified; false or left out for an unverified visitor.
- `source_conversation_id` (string): Id of the conversation, such as conv_01jx2m8k4t, or its number, such as 1042 for #1042. Find it with GET /conversations or GET /search.
- `stream_id` (string): An id you make up, at most 64 characters, so the run reports its progress live on your own realtime channel while it happens. Only useful to a client listening on that channel; leave it out otherwise. Such as "sim-7f3a2c".
- `target` (string): draft tests the working copy, live the published one. One of: `draft`, `live`, ``.

## Response 200 (OK)

- `data` (object, required)
  - `action_calls` (object[] | null, required): The actions the simulated turn called. They are mocked and never really run. Empty when it called none.
    - `action_id` (string, required): Id of the workspace action the simulation called (starts with aac_).
    - `args` (object): The arguments the action was called with, as a JSON object. Left out when there were none.
    - `blocked` (boolean): True when the call was stopped before it ran; a blocked call does not count as called in a test's assertions. Left out when false.
    - `succeeded` (boolean, required): True when the mocked call answered with success. Nothing real is run in a simulation.
    - `tool` (string, required): The action's tool name, the name the AI calls it by.
  - `active_state` (object, required)
    - `branches` (object, required): Branches of the procedure taken so far in the simulated conversation, as an object of strings. Send the whole state back with the next turn.
    - `called_action_ids` (string[] | null, required): Ids of the actions called so far in the simulated conversation. Send the whole state back with the next turn.
    - `completed_step_ids` (string[] | null, required): Ids of the procedure steps completed so far. Send the whole state back with the next turn.
    - `pending` (object[] | null, required): Writes that wait on the customer's confirmation or a teammate's approval; empty for none.
      - `action_id` (string, required): Id of the action whose write is waiting, such as aac_....
      - `args` (object, required): The arguments the action was called with, as an object.
      - `state` (string, required): What the write waits on: awaiting_confirmation for the customer's yes, pending_approval for a teammate's approval.
      - `summary` (string, required): One line saying what the write would do.
      - `tool` (string, required): Name of the tool the agent called for the action.
    - `procedure_id` (string): Id of the procedure the simulated conversation is running, such as prc_.... Left out when it runs none.
    - `status` (string): Where the procedure stands: active, completed, handed_off or exited. Left out when no procedure runs.
    - `step_outputs` (object, required): What the procedure's steps produced so far, as an object. Send the whole state back with the next turn.
  - `handoff` (object, required)
    - `note` (string): Note the agent left for the team at the handover. Left out when there is none.
    - `priority` (string): Priority the handover set on the conversation. Left out when it set none.
    - `reason` (string, required): Why the simulated turn handed over, such as customer_requested, unknown, frustration, safety or max_replies.
    - `team_id` (string): Id of the team the handover sent the conversation to, such as team_.... Left out when it chose none.
  - `matched` (boolean, required): True when the procedure under test was the one followed in this turn.
  - `object` (string, required): The kind of record this is, the same for every record of its kind, such as article.
  - `outcome` (string, required): How the simulated turn ended, such as answered, handoff, unknown, silent or refused.
  - `procedure_trace` (any): What the procedure did in this turn, as a JSON object with the steps reached and any guardrail events. Left out when there is none.
  - `reply` (string, required): The reply the AI agent would have sent the customer. Empty when it would send none.
  - `run_id` (string, required): Id of the AI run behind the simulated turn (starts with air_).

## Response default (Error)

- `code` (string, required): Stable code for programs to tell errors apart, such as validation_failed or internal_error.
- `errors` (object): Each rejected field mapped to its messages. Only present when the input was invalid.
- `message` (string, required): What went wrong, in words safe to show a person.

## Example request

```bash
curl --request POST \
  --url 'https://trydimmi.com/api/v1/procedures/{procedure}/simulate' \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "action_mocks": {
    "<key>": {
      "body": null,
      "status": 123
    }
  },
  "active_state": {
    "branches": {
      "<key>": "<string>"
    },
    "called_action_ids": [
      "<string>"
    ],
    "completed_step_ids": [
      "<string>"
    ],
    "pending": [
      {
        "action_id": "<string>",
        "args": {
          "<key>": null
        },
        "state": "<string>",
        "summary": "<string>",
        "tool": "<string>"
      }
    ],
    "procedure_id": "<string>",
    "status": "<string>",
    "step_outputs": {
      "<key>": null
    }
  },
  "confirmed_action_ids": [
    "<string>"
  ],
  "history": [
    {
      "role": "customer",
      "text": "<string>"
    }
  ],
  "message": "<string>",
  "persona": {
    "attributes": {
      "<key>": null
    },
    "channel": "widget",
    "company": {
      "<key>": null
    },
    "email": "<string>",
    "external_id": "<string>",
    "inbox_id": "<string>",
    "name": "<string>",
    "verified": true
  },
  "source_conversation_id": "<string>",
  "stream_id": "<string>",
  "target": "draft"
}'
```

## Example response

```json
{
  "data": {
    "action_calls": [
      {
        "action_id": "<string>",
        "args": {
          "<key>": null
        },
        "blocked": true,
        "succeeded": true,
        "tool": "<string>"
      }
    ],
    "active_state": {
      "branches": {
        "<key>": "<string>"
      },
      "called_action_ids": [
        "<string>"
      ],
      "completed_step_ids": [
        "<string>"
      ],
      "pending": [
        {
          "action_id": "<string>",
          "args": {},
          "state": "<string>",
          "summary": "<string>",
          "tool": "<string>"
        }
      ],
      "procedure_id": "<string>",
      "status": "<string>",
      "step_outputs": {
        "<key>": null
      }
    },
    "handoff": {
      "note": "<string>",
      "priority": "<string>",
      "reason": "<string>",
      "team_id": "<string>"
    },
    "matched": true,
    "object": "<string>",
    "outcome": "<string>",
    "procedure_trace": null,
    "reply": "<string>",
    "run_id": "<string>"
  }
}
```

---

Index of all dimmi docs: https://trydimmi.com/llms.txt (full text: https://trydimmi.com/llms-full.txt)
