> For the complete documentation index, see [llms.txt](https://docs.lingoql.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lingoql.com/sub0/apis-abi/action-chaining.md).

# Action Chaining

Action chaining lets one actionable reuse the output of another.

That is how Sub0 handles multi-step workflows without controllers or service classes.

### Use `depends_on`

Add `depends_on` inside the actionable that needs previous output.

```json
"depends_on": [ ... ]
```

You can depend on:

* another actionable in the same resource
* an actionable in another resource

### Same-resource example

Action `2` reuses the result from action `1`.

```json
{
  "id": 2,
  "mode": "QUERY",
  "depends_on": [
    {
      "resource_id": "self",
      "action_ids": [1],
      "extract_response_for": [
        {
          "extract": "id",
          "for": "user_id"
        }
      ]
    }
  ],
  "sql_query": {
    "query": "SELECT * FROM users WHERE id = $1",
    "parameters": ["user_id"]
  }
}
```

`self` refers to the current resource.

### Cross-resource example

Reuse an actionable from another endpoint:

```json
{
  "depends_on": [
    {
      "resource_id": "transactions-fetch-01",
      "action_ids": [1],
      "extract_response_for": [
        {
          "extract": "transaction_id",
          "for": "txn_id"
        }
      ]
    }
  ]
}
```

This is useful when the same workflow step should serve multiple endpoints.

### Extract values with `extract_response_for`

Each rule maps a value from the dependency result into a new field.

```json
{
  "extract": "transactionNo",
  "for": "txn_id"
}
```

Special extractor:

* `self_` returns the full response body

Nested paths also work:

* `user.profile.email`
* `items.0.id`

### HTTP request example

Fetch data first, then reuse it in another request:

```json
{
  "id": 4,
  "mode": "HTTPREQUEST",
  "depends_on": [
    {
      "resource_id": "self",
      "action_ids": [3],
      "extract_response_for": [
        {
          "extract": "self_",
          "for": "message"
        }
      ]
    }
  ],
  "http": {
    "url": "https://api.sendgrid.com/send",
    "method": "POST"
  }
}
```

### Upload chaining

Upload results automatically flow into the next actionable.

```json
{
  "id": 1,
  "mode": "UPLOAD"
}
```

```json
{
  "id": 2,
  "mode": "QUERY",
  "sql_query": {
    "query": "INSERT INTO gallery (url, file_size) VALUES ($1, $2)",
    "parameters": ["url", "file_size"]
  }
}
```

### Guardrails

* Actionables run sequentially by default.
* Use `parallel: true` only for independent actions.
* Use `no_op: true` when an action should run only through `depends_on`.

### Why this matters

Action chaining is where Sub0 starts to feel different.

You stop writing orchestration code and start declaring the flow directly.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.lingoql.com/sub0/apis-abi/action-chaining.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
