# Get a Managed Agent build

GET https://services.leadconnectorhq.com/agent-studio/managed-agents/builds/{buildId}

Returns the state of a build: still running, waiting for answers or a reply, or finished. nextAction says what to do next. Builds are kept for 24 hours; the agent and its build history stay after that.

## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `managed-agents.buildAndPublish`

## Parameters

### Header Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `Version` | string | Yes | API version. |

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `buildId` | string | Yes | Build ID |

### Query Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `locationId` | string | Yes | Location (sub-account) the build belongs to |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/agent-studio/managed-agents/builds/{buildId}": {
      "get": {
        "summary": "Get a Managed Agent build",
        "operationId": "getAManagedAgentBuild",
        "description": "Returns the state of a build: still running, waiting for answers or a reply, or finished. nextAction says what to do next. Builds are kept for 24 hours; the agent and its build history stay after that.",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "required": true,
            "description": "API version.",
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          },
          {
            "name": "buildId",
            "required": true,
            "in": "path",
            "description": "Build ID",
            "schema": {
              "example": "b7a1f0e2-4c3d-4e5f-8a9b-0c1d2e3f4a5b",
              "type": "string"
            }
          },
          {
            "name": "locationId",
            "required": true,
            "in": "query",
            "description": "Location (sub-account) the build belongs to",
            "schema": {
              "example": "ve9EPM428h8vShlRW1KT",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Build state",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ManagedAgentBuild"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PublicApiError"
                }
              }
            }
          },
          "401": {
            "description": "Authentication is missing or invalid, or the token lacks the required Managed Agents route scope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PublicApiError"
                }
              }
            }
          },
          "403": {
            "description": "The user the request acts as lacks the Managed Agents permission",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PublicApiError"
                }
              }
            }
          },
          "404": {
            "description": "Build not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PublicApiError"
                }
              }
            }
          },
          "422": {
            "description": "Unprocessable Entity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnprocessableDTO"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected internal server error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PublicApiError"
                }
              }
            }
          },
          "503": {
            "description": "Build state is temporarily unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PublicApiError"
                }
              }
            }
          }
        },
        "security": [
          {
            "Location-Access": [
              "managed-agents.buildAndPublish"
            ]
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account.",
        "type": "http"
      },
      "Agency-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency (OR) Private Integration Token of Agency.",
        "type": "http"
      },
      "Agency-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency.",
        "type": "http"
      }
    },
    "schemas": {
      "ManagedAgentBuild": {
        "type": "object",
        "properties": {
          "buildId": {
            "type": "string",
            "description": "Build id to poll and to continue the build with",
            "example": "b7a1f0e2-4c3d-4e5f-8a9b-0c1d2e3f4a5b"
          },
          "status": {
            "type": "string",
            "description": "RUNNING: still building. NEEDS_INPUT: answer questions. NEEDS_REPLY: the builder asked something in message; send the reply as a new message on this build. ANSWERS_STALE: the questions changed, so send the request again. COMPLETED: done (changed tells whether the agent was saved). FAILED: see error.",
            "enum": [
              "RUNNING",
              "NEEDS_INPUT",
              "NEEDS_REPLY",
              "ANSWERS_STALE",
              "COMPLETED",
              "FAILED"
            ],
            "example": "RUNNING"
          },
          "nextAction": {
            "type": "string",
            "description": "What to do next. POLL: call get build again after pollAfterMs. ASK_USER: show the user the questions or message and send their answer. REVIEW: the draft was saved; review it, then publish when ready. USE_RESULT: use message as the answer; nothing changed. RETRY: nothing was applied (see error or staleReason); send the request again with a new Idempotency-Key.",
            "enum": [
              "POLL",
              "ASK_USER",
              "REVIEW",
              "USE_RESULT",
              "RETRY"
            ],
            "example": "POLL"
          },
          "pollAfterMs": {
            "type": "number",
            "description": "Milliseconds to wait before polling again (RUNNING only)",
            "example": 5000
          },
          "managedAgentId": {
            "type": "string",
            "description": "The agent this build creates or edits, once known",
            "example": "027ee957-ae94-40ad-89a3-b25c985f729b"
          },
          "changed": {
            "type": "boolean",
            "description": "COMPLETED only: true when the agent draft was saved, false when the builder only answered",
            "example": true
          },
          "message": {
            "type": "string",
            "description": "The builder's message: its summary, its answer, or the question it needs answered",
            "example": "I built a lead qualifier that books qualified leads into your Sales calendar."
          },
          "questions": {
            "description": "NEEDS_INPUT only: the questions to answer",
            "example": [
              {
                "id": "a1b2c3d4e5f6",
                "prompt": "Which calendar should booked leads go to?",
                "options": [
                  {
                    "value": "uQWaF4gPj7NQ1696EEp2",
                    "label": "Sales calendar"
                  }
                ],
                "allowMultiple": false
              }
            ],
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "description": "Question id to send back in answers[].questionId",
                  "example": "a1b2c3d4e5f6"
                },
                "prompt": {
                  "type": "string",
                  "description": "Question to show the user",
                  "example": "Which calendar should booked leads go to?"
                },
                "options": {
                  "description": "Options to choose from",
                  "example": [
                    {
                      "value": "uQWaF4gPj7NQ1696EEp2",
                      "label": "Sales calendar"
                    }
                  ],
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "value": {
                        "type": "string",
                        "description": "Value to send back in answers[].values",
                        "example": "uQWaF4gPj7NQ1696EEp2"
                      },
                      "label": {
                        "type": "string",
                        "description": "Label to show the user",
                        "example": "Sales calendar"
                      }
                    },
                    "required": [
                      "value",
                      "label"
                    ],
                    "title": "ManagedAgentBuildQuestionOption"
                  }
                },
                "allowMultiple": {
                  "type": "boolean",
                  "description": "Whether more than one option may be chosen",
                  "example": false
                },
                "hasMore": {
                  "type": "boolean",
                  "description": "True when the location has more choices than the options listed",
                  "example": false
                }
              },
              "required": [
                "id",
                "prompt",
                "options",
                "allowMultiple"
              ],
              "title": "ManagedAgentBuildQuestion"
            }
          },
          "staleReason": {
            "type": "string",
            "description": "ANSWERS_STALE only: why the answers no longer apply",
            "enum": [
              "no_pending_round",
              "expired",
              "config_changed",
              "wrong_target",
              "round_mismatch"
            ],
            "example": "expired"
          },
          "error": {
            "description": "FAILED only: why the build failed",
            "example": {
              "code": "BUILD_FAILED",
              "message": "The build failed before it completed"
            },
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "code": {
                    "type": "string",
                    "description": "Stable error code",
                    "example": "BUILD_FAILED"
                  },
                  "message": {
                    "type": "string",
                    "description": "What went wrong",
                    "example": "The build failed before it completed"
                  }
                },
                "required": [
                  "code",
                  "message"
                ],
                "title": "ManagedAgentBuildError"
              }
            ]
          },
          "hasPublishedVersion": {
            "type": "boolean",
            "description": "Whether the agent has a published version",
            "example": false
          },
          "hasUnpublishedChanges": {
            "type": "boolean",
            "description": "Whether the saved draft differs from the published version",
            "example": true
          },
          "createdAt": {
            "type": "string",
            "description": "When the build started",
            "example": "2026-10-29T12:00:00.000Z"
          },
          "updatedAt": {
            "type": "string",
            "description": "When the build last changed state",
            "example": "2026-10-29T12:01:30.000Z"
          }
        },
        "required": [
          "buildId",
          "status",
          "nextAction",
          "createdAt",
          "updatedAt"
        ],
        "title": "ManagedAgentBuild"
      },
      "PublicApiError": {
        "type": "object",
        "additionalProperties": true,
        "required": [
          "message"
        ],
        "properties": {
          "message": {
            "type": "string",
            "description": "Human-readable description of the failure.",
            "example": "Fair usage limit exceeded for this location."
          },
          "statusCode": {
            "type": "integer",
            "description": "HTTP status code of the response.",
            "example": 429
          },
          "code": {
            "type": "string",
            "description": "Machine-readable error code.",
            "example": "policy_denied"
          },
          "category": {
            "type": "string",
            "description": "Broad classification of the failure, such as policy, provider or internal.",
            "example": "policy"
          },
          "retryable": {
            "type": "boolean",
            "description": "Whether retrying the same logical request is safe. For 429 responses, retry only when this is true and Retry-After is present.",
            "example": true
          },
          "reasonCode": {
            "type": "string",
            "description": "Machine-readable policy denial reason.",
            "enum": [
              "agency_inactive",
              "agency_wallet_inactive",
              "billing_config_unavailable",
              "fup_exceeded",
              "location_inactive",
              "location_limit_exceeded",
              "location_wallet_inactive",
              "plan_state_unavailable",
              "platform_limit_exceeded",
              "product_disabled",
              "promo_exhausted",
              "user_limit_exceeded"
            ],
            "example": "fup_exceeded"
          },
          "resetAt": {
            "type": "string",
            "format": "date-time",
            "description": "Time at which the applicable policy allowance resets.",
            "example": "2024-07-29T15:51:28.071Z"
          },
          "retryAfterSeconds": {
            "type": "integer",
            "minimum": 1,
            "description": "Number of seconds to wait before retrying a rate-limited request. Present only when retryable is true.",
            "example": 5
          }
        },
        "title": "PublicApiError"
      },
      "UnprocessableDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 422
          },
          "message": {
            "example": [
              "Unprocessable Entity"
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "error": {
            "type": "string",
            "example": "Unprocessable Entity"
          }
        },
        "title": "UnprocessableDTO"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X GET 'https://services.leadconnectorhq.com/agent-studio/managed-agents/builds/<buildId>?locationId=<LOCATIONID>' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3'
```

**Node.js**

```javascript
const options = {
  method: 'GET',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3'
  }
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/agent-studio/managed-agents/builds/<buildId>?locationId=<LOCATIONID>', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/agent-studio/managed-agents/builds/{buildId}"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "v3"
}

params = {
    "locationId": "<LOCATIONID>"
}

response = requests.get(url, params=params, headers=headers)
print(response.json())
```

**PHP**

```php
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/agent-studio/managed-agents/builds/<buildId>?locationId=<LOCATIONID>',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
  ],
]);

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

**Java**

```java
HttpResponse<String> response = Unirest
  .get("https://services.leadconnectorhq.com/agent-studio/managed-agents/builds/<buildId>?locationId=<LOCATIONID>")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .asString();
```

**Go**

```go
package main

import (
  "fmt"
  "net/http"
  "io"
)

func main() {
  url := "https://services.leadconnectorhq.com/agent-studio/managed-agents/builds/<buildId>?locationId=<LOCATIONID>"
  req, _ := http.NewRequest("GET", url, nil)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "v3")

  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)
  fmt.Println(string(body))
}
```

**Ruby**

```ruby
require 'uri'
require 'net/http'

url = URI("https://services.leadconnectorhq.com/agent-studio/managed-agents/builds/<buildId>?locationId=<LOCATIONID>")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"

response = http.request(request)
puts response.read_body
```

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "v3"
}

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/agent-studio/managed-agents/builds/<buildId>?locationId=<LOCATIONID>' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
```
