> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stateset.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ResponseAutomationV2

> The primary workflow — phases, review gate, signals and queries, and the LLM tool-use loop.

# ResponseAutomationV2

The primary workflow. A single, data-driven workflow that serves every brand rather than one
workflow per brand — behavior comes from the brand's
[AutomationConfig](/next-temporal/configuration), not from code.

## Phases

```
 1. Load AutomationConfig      from brand_workflow_bindings
 2. Get Ticket                 Gorgias connector
 3. Skip Rules?          ──────────────▶ Return: Skipped
 4. Escalation Check?    ──tag_and_skip─▶ Return: Escalated
                         │
                         ├─tag_and_continue / tag_and_review─┐
 5. Gather Context  ◀────────────────────────────────────────┘
      ├─ Shopify: customer, orders ≤20
      ├─ Recharge: subscriptions ≤20
      └─ Knowledge Base: vector search, top_k ≤100
 6. Build System Prompt + Message History
 7. Function-Calling Loop      max 10 rounds
 8. Classification & Tagging
 9. Review Gate?
      ├─ confidence < threshold ─▶ wait for human signal
      │                              ├─ approved ─▶ dispatch
      │                              └─ rejected ─▶ Return: Rejected
      └─ otherwise ─▶ dispatch
10. Dispatch Response          create message, add tags, set status
11. Post-Actions               start snooze child workflows
                               ─▶ Return: Completed
```

A **cancel signal** is checked at each phase, so a workflow can be aborted partway without
leaving the ticket in an inconsistent state.

## Signals and queries

| Type   | Name                | Purpose                                      |
| ------ | ------------------- | -------------------------------------------- |
| Signal | `review_decision`   | Human approves or rejects at the review gate |
| Signal | `cancel`            | Abort the workflow at any phase              |
| Query  | `automation_status` | Current phase, tags, escalation info         |

## Function-calling loop

The LLM can call tools defined in the brand's config. The workflow executes each tool call as a
Temporal activity and feeds the result back:

```
Workflow ──▶ OpenAI    system prompt + ticket + tools
         ◀── tool_calls: [get_order("12345")]
Workflow ──▶ Shopify   shopify_get_order("12345")
         ◀── {order details}
Workflow ──▶ OpenAI    tool result + continue
         ◀── tool_calls: [search_knowledge_base("return policy")]
Workflow ──▶ Qdrant    search_knowledge_base("return policy")
         ◀── {matching articles}
Workflow ──▶ OpenAI    tool result + continue
         ◀── content: "Based on your order #12345..."
```

The loop ends when the LLM returns content instead of tool calls. **A maximum of 10 rounds is
enforced**, so a model that keeps calling tools cannot spin indefinitely.

### Available tools

| Tool                    | Connector         | Description                        |
| ----------------------- | ----------------- | ---------------------------------- |
| `get_order`             | Shopify           | Fetch order with line items        |
| `get_customer`          | Shopify           | Fetch customer — name, email, tags |
| `create_fulfillment`    | Shopify           | Ship order items                   |
| `get_subscription`      | Recharge          | Fetch subscription details         |
| `cancel_subscription`   | Recharge          | Cancel with reason                 |
| `skip_charge`           | Recharge          | Skip the next charge               |
| `search_knowledge_base` | Qdrant / Pinecone | Vector similarity search           |
| `classify_intent`       | OpenAI            | Classify ticket intent             |

<Warning>
  `create_fulfillment`, `cancel_subscription`, and `skip_charge` take **real action on customer
  accounts**. Which tools a brand exposes is part of its AutomationConfig — scope
  `tool_definitions` to what that brand's agent should actually be able to do, and use the review
  gate for the rest.
</Warning>

## Review gate

The gate compares the classification confidence against `min_confidence`. Below the threshold,
the workflow waits for a `review_decision` signal rather than dispatching.

`escalation_always_review` forces the gate on escalation paths regardless of confidence.

## Runtime API

| Method | Path                                               | Description                 |
| ------ | -------------------------------------------------- | --------------------------- |
| `POST` | `/v1/workflows/response-automation-v2/start`       | Start a workflow            |
| `POST` | `/v1/workflows/response-automation-v2/{id}/review` | Send a review decision      |
| `POST` | `/v1/workflows/response-automation-v2/{id}/cancel` | Cancel                      |
| `GET`  | `/v1/workflows/response-automation-v2/{id}/status` | Query status                |
| `POST` | `/v1/workflows/connector/start`                    | Start a connector workflow  |
| `POST` | `/v1/workflows/connector/{id}/cancel`              | Cancel a connector workflow |
| `GET`  | `/v1/workflows/connector/{id}/status`              | Connector workflow status   |
| `POST` | `/v1/workflows/snooze/{id}/cancel`                 | Cancel a snooze workflow    |
| `GET`  | `/v1/workflows/snooze/{id}/status`                 | Snooze workflow status      |

<Note>
  `POST /v1/workflows/response/start`, `/v1/workflows/{id}/signal/review`, and
  `/v1/workflows/{id}/status` are the **deprecated v1** surface. New integrations should use the
  `response-automation-v2` paths above.
</Note>

## Related

* [Configuration](/next-temporal/configuration) — AutomationConfig, skip rules, escalation
* [Control plane](/next-temporal/control-plane)
* [Workflow Studio](/stateset-response/responsecx-workflow-studio) — the UI over this engine
