# Update Agent

PATCH https://services.leadconnectorhq.com/agent-studio/agent/versions/{versionId}

Updates a specific agent version by versionId. Supports updating nodes, edges, variables, and configuration. 

## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `agent-studio.write`

## Parameters

### Header Parameters

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

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `versionId` | string | Yes | Agent version ID to update |

### Query Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `source` | string | No | Origin channel attributed to this write for auditing (e.g. public_api, internal) |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/agent-studio/agent/versions/{versionId}": {
      "patch": {
        "summary": "Update Agent",
        "operationId": "updateAgent",
        "description": "Updates a specific agent version by versionId. Supports updating nodes, edges, variables, and configuration. ",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          },
          {
            "name": "versionId",
            "required": true,
            "in": "path",
            "schema": {
              "type": "string"
            },
            "example": "v1a2b3c4d5e6f7g8h9i0",
            "description": "Agent version ID to update"
          },
          {
            "name": "source",
            "required": false,
            "in": "query",
            "schema": {
              "type": "string"
            },
            "example": "api",
            "description": "Origin channel attributed to this write for auditing (e.g. public_api, internal)"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdatePublicAgentVersionDTO"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Version updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpdatePublicAgentResponseDTO"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BadRequestDTO"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnauthorizedDTO"
                }
              }
            }
          },
          "404": {
            "description": "Version not found"
          },
          "422": {
            "description": "Unprocessable Entity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnprocessableDTO"
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InternalServerErrorDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "Location-Access": [
              "agent-studio.write"
            ]
          }
        ]
      }
    }
  },
  "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": {
      "UpdatePublicAgentVersionDTO": {
        "type": "object",
        "properties": {
          "locationId": {
            "type": "string",
            "description": "Location ID for authorization",
            "example": "C2QujeCh8ZnC7al2InWR"
          },
          "versionName": {
            "type": "string",
            "description": "Version name",
            "example": "Customer Support Agent v2"
          },
          "description": {
            "type": "string",
            "description": "Description of the version",
            "example": "Updated version with improved customer handling logic"
          },
          "nodes": {
            "description": "Complete array of nodes for the agent workflow. Provide all nodes including unchanged ones.",
            "example": [
              {
                "nodeId": "node_1",
                "nodeName": "Start",
                "type": "start",
                "isStartNode": true
              },
              {
                "nodeId": "node_2",
                "nodeName": "LLM Node",
                "type": "llm",
                "nodeConfig": {
                  "prompt": "How can I help you?",
                  "llmProvider": "openai",
                  "llmModel": "gpt-4"
                }
              }
            ],
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "edges": {
            "description": "Complete array of edges connecting the nodes. Provide all edges including unchanged ones.",
            "example": [
              {
                "startNode": "node_1",
                "endNode": "node_2"
              }
            ],
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "globalVariables": {
            "description": "Global variables accessible throughout the agent workflow",
            "example": [
              {
                "key": "apiKey",
                "type": "string",
                "value": "your-api-key"
              }
            ],
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "inputVariables": {
            "description": "Input variables required from user at execution time",
            "example": [
              {
                "key": "customerName",
                "type": "string",
                "description": "Customer name for personalization"
              }
            ],
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "runtimeVariables": {
            "description": "Runtime variables generated during agent execution",
            "example": [
              {
                "key": "sessionId",
                "type": "string",
                "description": "Current session identifier"
              }
            ],
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "globalConfig": {
            "type": "object",
            "description": "Global configuration including prompts and settings",
            "example": {
              "globalPrompt": {
                "currentPrompt": "You are a helpful customer support assistant.",
                "history": []
              }
            }
          },
          "userId": {
            "type": "string",
            "description": "User ID performing the update",
            "example": "usr_abc123def456"
          },
          "userName": {
            "type": "string",
            "description": "User name performing the update",
            "example": "John Doe"
          }
        },
        "required": [
          "locationId"
        ],
        "title": "UpdatePublicAgentVersionDTO"
      },
      "UpdatePublicAgentResponseDTO": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "description": "Success status",
            "example": true
          },
          "message": {
            "type": "string",
            "description": "Response message",
            "example": "Agent updated successfully"
          },
          "data": {
            "type": "object",
            "description": "Updated agent or version data",
            "example": {
              "agentId": "p1q2r3s4t5u6v7w8x9y0z1a2",
              "versionId": "v1a2b3c4d5e6f7g8h9i0",
              "name": "Updated Customer Support Agent",
              "description": "Updated AI agent with enhanced customer support capabilities",
              "status": "active",
              "updatedAt": "2024-02-27T11:45:00.000Z"
            }
          }
        },
        "required": [
          "success",
          "message",
          "data"
        ],
        "title": "UpdatePublicAgentResponseDTO"
      },
      "BadRequestDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 400
          },
          "message": {
            "type": "string",
            "example": "Bad Request"
          }
        },
        "title": "BadRequestDTO"
      },
      "UnauthorizedDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 401
          },
          "message": {
            "type": "string",
            "example": "Invalid token: access token is invalid"
          },
          "error": {
            "type": "string",
            "example": "Unauthorized"
          }
        },
        "title": "UnauthorizedDTO"
      },
      "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"
      },
      "InternalServerErrorDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 500,
            "description": "HTTP status code"
          },
          "message": {
            "type": "string",
            "example": "Internal Server Error",
            "description": "Error message"
          }
        },
        "title": "InternalServerErrorDTO"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X PATCH 'https://services.leadconnectorhq.com/agent-studio/agent/versions/<versionId>' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "locationId": "C2QujeCh8ZnC7al2InWR",
  "versionName": "Customer Support Agent v2",
  "description": "Updated version with improved customer handling logic",
  "nodes": [
    {
      "nodeId": "node_1",
      "nodeName": "Start",
      "type": "start",
      "isStartNode": true
    },
    {
      "nodeId": "node_2",
      "nodeName": "LLM Node",
      "type": "llm",
      "nodeConfig": {
        "prompt": "How can I help you?",
        "llmProvider": "openai",
        "llmModel": "gpt-4"
      }
    }
  ],
  "edges": [
    {
      "startNode": "node_1",
      "endNode": "node_2"
    }
  ],
  "globalVariables": [
    {
      "key": "apiKey",
      "type": "string",
      "value": "your-api-key"
    }
  ],
  "inputVariables": [
    {
      "key": "customerName",
      "type": "string",
      "description": "Customer name for personalization"
    }
  ],
  "runtimeVariables": [
    {
      "key": "sessionId",
      "type": "string",
      "description": "Current session identifier"
    }
  ],
  "globalConfig": {
    "globalPrompt": {
      "currentPrompt": "You are a helpful customer support assistant.",
      "history": []
    }
  },
  "userId": "usr_abc123def456",
  "userName": "John Doe"
}'
```

**Node.js**

```javascript
const options = {
  method: 'PATCH',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "locationId": "C2QujeCh8ZnC7al2InWR",
      "versionName": "Customer Support Agent v2",
      "description": "Updated version with improved customer handling logic",
      "nodes": [
        {
          "nodeId": "node_1",
          "nodeName": "Start",
          "type": "start",
          "isStartNode": true
        },
        {
          "nodeId": "node_2",
          "nodeName": "LLM Node",
          "type": "llm",
          "nodeConfig": {
            "prompt": "How can I help you?",
            "llmProvider": "openai",
            "llmModel": "gpt-4"
          }
        }
      ],
      "edges": [
        {
          "startNode": "node_1",
          "endNode": "node_2"
        }
      ],
      "globalVariables": [
        {
          "key": "apiKey",
          "type": "string",
          "value": "your-api-key"
        }
      ],
      "inputVariables": [
        {
          "key": "customerName",
          "type": "string",
          "description": "Customer name for personalization"
        }
      ],
      "runtimeVariables": [
        {
          "key": "sessionId",
          "type": "string",
          "description": "Current session identifier"
        }
      ],
      "globalConfig": {
        "globalPrompt": {
          "currentPrompt": "You are a helpful customer support assistant.",
          "history": []
        }
      },
      "userId": "usr_abc123def456",
      "userName": "John Doe"
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/agent-studio/agent/versions/<versionId>', 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/agent/versions/{versionId}"

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

payload = {
    "locationId": "C2QujeCh8ZnC7al2InWR",
    "versionName": "Customer Support Agent v2",
    "description": "Updated version with improved customer handling logic",
    "nodes": [
        {
            "nodeId": "node_1",
            "nodeName": "Start",
            "type": "start",
            "isStartNode": true
        },
        {
            "nodeId": "node_2",
            "nodeName": "LLM Node",
            "type": "llm",
            "nodeConfig": {
                "prompt": "How can I help you?",
                "llmProvider": "openai",
                "llmModel": "gpt-4"
            }
        }
    ],
    "edges": [
        {
            "startNode": "node_1",
            "endNode": "node_2"
        }
    ],
    "globalVariables": [
        {
            "key": "apiKey",
            "type": "string",
            "value": "your-api-key"
        }
    ],
    "inputVariables": [
        {
            "key": "customerName",
            "type": "string",
            "description": "Customer name for personalization"
        }
    ],
    "runtimeVariables": [
        {
            "key": "sessionId",
            "type": "string",
            "description": "Current session identifier"
        }
    ],
    "globalConfig": {
        "globalPrompt": {
            "currentPrompt": "You are a helpful customer support assistant.",
            "history": []
        }
    },
    "userId": "usr_abc123def456",
    "userName": "John Doe"
}

response = requests.patch(url, json=payload, headers=headers)
print(response.json())
```

**PHP**

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

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/agent-studio/agent/versions/<versionId>',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'PATCH',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "locationId": "C2QujeCh8ZnC7al2InWR",
  "versionName": "Customer Support Agent v2",
  "description": "Updated version with improved customer handling logic",
  "nodes": [
    {
      "nodeId": "node_1",
      "nodeName": "Start",
      "type": "start",
      "isStartNode": true
    },
    {
      "nodeId": "node_2",
      "nodeName": "LLM Node",
      "type": "llm",
      "nodeConfig": {
        "prompt": "How can I help you?",
        "llmProvider": "openai",
        "llmModel": "gpt-4"
      }
    }
  ],
  "edges": [
    {
      "startNode": "node_1",
      "endNode": "node_2"
    }
  ],
  "globalVariables": [
    {
      "key": "apiKey",
      "type": "string",
      "value": "your-api-key"
    }
  ],
  "inputVariables": [
    {
      "key": "customerName",
      "type": "string",
      "description": "Customer name for personalization"
    }
  ],
  "runtimeVariables": [
    {
      "key": "sessionId",
      "type": "string",
      "description": "Current session identifier"
    }
  ],
  "globalConfig": {
    "globalPrompt": {
      "currentPrompt": "You are a helpful customer support assistant.",
      "history": []
    }
  },
  "userId": "usr_abc123def456",
  "userName": "John Doe"
}',
]);

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

**Java**

```java
HttpResponse<String> response = Unirest
  .patch("https://services.leadconnectorhq.com/agent-studio/agent/versions/<versionId>")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/json")
  .body("{\"locationId\":\"C2QujeCh8ZnC7al2InWR\",\"versionName\":\"Customer Support Agent v2\",\"description\":\"Updated version with improved customer handling logic\",\"nodes\":[{\"nodeId\":\"node_1\",\"nodeName\":\"Start\",\"type\":\"start\",\"isStartNode\":true},{\"nodeId\":\"node_2\",\"nodeName\":\"LLM Node\",\"type\":\"llm\",\"nodeConfig\":{\"prompt\":\"How can I help you?\",\"llmProvider\":\"openai\",\"llmModel\":\"gpt-4\"}}],\"edges\":[{\"startNode\":\"node_1\",\"endNode\":\"node_2\"}],\"globalVariables\":[{\"key\":\"apiKey\",\"type\":\"string\",\"value\":\"your-api-key\"}],\"inputVariables\":[{\"key\":\"customerName\",\"type\":\"string\",\"description\":\"Customer name for personalization\"}],\"runtimeVariables\":[{\"key\":\"sessionId\",\"type\":\"string\",\"description\":\"Current session identifier\"}],\"globalConfig\":{\"globalPrompt\":{\"currentPrompt\":\"You are a helpful customer support assistant.\",\"history\":[]}},\"userId\":\"usr_abc123def456\",\"userName\":\"John Doe\"}")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/agent-studio/agent/versions/<versionId>"
  payload := strings.NewReader(`{
  "locationId": "C2QujeCh8ZnC7al2InWR",
  "versionName": "Customer Support Agent v2",
  "description": "Updated version with improved customer handling logic",
  "nodes": [
    {
      "nodeId": "node_1",
      "nodeName": "Start",
      "type": "start",
      "isStartNode": true
    },
    {
      "nodeId": "node_2",
      "nodeName": "LLM Node",
      "type": "llm",
      "nodeConfig": {
        "prompt": "How can I help you?",
        "llmProvider": "openai",
        "llmModel": "gpt-4"
      }
    }
  ],
  "edges": [
    {
      "startNode": "node_1",
      "endNode": "node_2"
    }
  ],
  "globalVariables": [
    {
      "key": "apiKey",
      "type": "string",
      "value": "your-api-key"
    }
  ],
  "inputVariables": [
    {
      "key": "customerName",
      "type": "string",
      "description": "Customer name for personalization"
    }
  ],
  "runtimeVariables": [
    {
      "key": "sessionId",
      "type": "string",
      "description": "Current session identifier"
    }
  ],
  "globalConfig": {
    "globalPrompt": {
      "currentPrompt": "You are a helpful customer support assistant.",
      "history": []
    }
  },
  "userId": "usr_abc123def456",
  "userName": "John Doe"
}`)
  req, _ := http.NewRequest("PATCH", url, payload)
  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/agent/versions/<versionId>")

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

request = Net::HTTP::Patch.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"
request["Content-Type"] = "application/json"
request.body = '{
  "locationId": "C2QujeCh8ZnC7al2InWR",
  "versionName": "Customer Support Agent v2",
  "description": "Updated version with improved customer handling logic",
  "nodes": [
    {
      "nodeId": "node_1",
      "nodeName": "Start",
      "type": "start",
      "isStartNode": true
    },
    {
      "nodeId": "node_2",
      "nodeName": "LLM Node",
      "type": "llm",
      "nodeConfig": {
        "prompt": "How can I help you?",
        "llmProvider": "openai",
        "llmModel": "gpt-4"
      }
    }
  ],
  "edges": [
    {
      "startNode": "node_1",
      "endNode": "node_2"
    }
  ],
  "globalVariables": [
    {
      "key": "apiKey",
      "type": "string",
      "value": "your-api-key"
    }
  ],
  "inputVariables": [
    {
      "key": "customerName",
      "type": "string",
      "description": "Customer name for personalization"
    }
  ],
  "runtimeVariables": [
    {
      "key": "sessionId",
      "type": "string",
      "description": "Current session identifier"
    }
  ],
  "globalConfig": {
    "globalPrompt": {
      "currentPrompt": "You are a helpful customer support assistant.",
      "history": []
    }
  },
  "userId": "usr_abc123def456",
  "userName": "John Doe"
}'

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

**PowerShell**

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

$body = '{
  "locationId": "C2QujeCh8ZnC7al2InWR",
  "versionName": "Customer Support Agent v2",
  "description": "Updated version with improved customer handling logic",
  "nodes": [
    {
      "nodeId": "node_1",
      "nodeName": "Start",
      "type": "start",
      "isStartNode": true
    },
    {
      "nodeId": "node_2",
      "nodeName": "LLM Node",
      "type": "llm",
      "nodeConfig": {
        "prompt": "How can I help you?",
        "llmProvider": "openai",
        "llmModel": "gpt-4"
      }
    }
  ],
  "edges": [
    {
      "startNode": "node_1",
      "endNode": "node_2"
    }
  ],
  "globalVariables": [
    {
      "key": "apiKey",
      "type": "string",
      "value": "your-api-key"
    }
  ],
  "inputVariables": [
    {
      "key": "customerName",
      "type": "string",
      "description": "Customer name for personalization"
    }
  ],
  "runtimeVariables": [
    {
      "key": "sessionId",
      "type": "string",
      "description": "Current session identifier"
    }
  ],
  "globalConfig": {
    "globalPrompt": {
      "currentPrompt": "You are a helpful customer support assistant.",
      "history": []
    }
  },
  "userId": "usr_abc123def456",
  "userName": "John Doe"
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/agent-studio/agent/versions/<versionId>' -Method 'PATCH' -Headers $headers -Body $body -ContentType 'application/json'
$response | ConvertTo-Json
```
