# Replace agent

URL: https://docs.hanzo.ai/docs/openapi/compute/bindmachineagent

> Binds a cloud Agent to one of the caller org's machines: the machine is recorded as running that Agent's @hanzo/bot runtime.

`PUT /v1/compute/machines/{id}/agent`

> [Compute →](https://docs.hanzo.ai/docs/openapi/compute) · [All API references →](https://docs.hanzo.ai/docs/openapi) · [Get started →](https://docs.hanzo.ai/docs/guides)

|               |                                                       |
| ------------- | ----------------------------------------------------- |
| **Address**   | `https://api.hanzo.ai/v1/compute/machines/{id}/agent` |
| **Method**    | `PUT`                                                 |
| **Operation** | `bindMachineAgent`                                    |
| **Auth**      | `Authorization: Bearer $HANZO_API_KEY`                |

Binds a cloud Agent to one of the caller org's machines: the
machine is recorded as running that Agent's @hanzo/bot runtime. The owning org is
the validated tenant, never a client field.

## Request

4 fields, body `application/json` (required).

| Field        | In   | Type   | Required | Description                                                              |
| ------------ | ---- | ------ | -------- | ------------------------------------------------------------------------ |
| `id`         | path | string | yes      | ID is the machine to bind, from the URL path.                            |
| `agentName`  | body | string | —        | AgentName is the cloud Agent (/v1/agent) the machine will run.           |
| `botVersion` | body | string | —        | BotVersion pins the @hanzo/bot runtime version; empty takes the default. |
| `id`         | body | string | —        | ID is the machine to bind, from the URL path.                            |

## Response

| Status    | Body                 | Meaning |
| --------- | -------------------- | ------- |
| `200`     | compute.agentBinding | ok      |
| `default` | problem-details      | refused |

`200` body — 12 fields.

| Field         | In   | Type   | Always | Description                                                                                                                                                       |
| ------------- | ---- | ------ | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `agentName`   | body | string | —      | AgentName is the cloud Agent (/v1/agent) this machine runs — the agent a message to the bot is actually run against.                                              |
| `botVersion`  | body | string | —      | BotVersion pins the @hanzo/bot runtime version the machine runs.                                                                                                  |
| `createdTime` | body | string | —      | CreatedTime is when the binding was first made.                                                                                                                   |
| `machineId`   | body | string | —      | MachineId is the bound machine as vm addresses it, owner-qualified ("\<org>/\<machine>").                                                                         |
| `message`     | body | string | —      | Message is vm's human-readable detail on Status ("machine provisioning; @hanzo/bot runtime not yet confirmed") — the reason behind the state, not a second state. |
| `name`        | body | string | —      | Name is the binding's own key, which is the machine's id: a machine hosts at most one agent, so the binding is named for it.                                      |
| `org`         | body | string | —      | Org is the Hanzo tenant the binding belongs to.                                                                                                                   |
| `owner`       | body | string | —      | Owner is the tenant vm filed the binding under, resolved from the ?owner it was called with — which is the caller's validated org and never a body field.         |
| `provider`    | body | string | —      | Provider is the cloud the bound machine runs on, carried here so a bindings list says where each bot lives without a second read per machine.                     |
| `publicIp`    | body | string | —      | PublicIp is the bound machine's public address as vm recorded it on the binding.                                                                                  |
| `status`      | body | string | —      | Status is the binding's lifecycle in VM's OWN words — "Pending" while the machine provisions and the runtime is unconfirmed, "running" once vm has confirmed it.  |
| `updatedTime` | body | string | —      | UpdatedTime is when vm last reconciled it — the age of Status.                                                                                                    |

Failure carries the platform error shape — see [Errors](https://docs.hanzo.ai/docs/errors).

## Examples

**CLI**

```bash
hanzo compute machines agent replace <id>
```

**SDK**

**.ts**

```ts
import { Configuration, ComputeApi } from 'hanzoai';

const api = new ComputeApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data } = await api.bindMachineAgent({ id: 'id', agentName: "<agentName>", botVersion: "<botVersion>" });
```

**.py**

```python
from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import ComputeApi

client = ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"]))
result = ComputeApi(client).bind_machine_agent(id='id', agent_name="<agentName>", bot_version="<botVersion>")
```

**.go**

```go
cfg := hanzoai.NewConfiguration()
cfg.AddDefaultHeader("Authorization", "Bearer "+os.Getenv("HANZO_API_KEY"))
client := hanzoai.NewAPIClient(cfg)

resp, _, err := client.ComputeAPI.BindMachineAgent(context.Background()).Execute()
if err != nil {
	return err
}
```

**.rs**

```rust
use hanzo_client::apis::{configuration::Configuration, compute_api};

let mut cfg = Configuration::new();
cfg.bearer_access_token = std::env::var("HANZO_API_KEY").ok();

let result = compute_api::bind_machine_agent(&cfg, Default::default()).await?;
```

**.java**

```java
import ai.hanzo.cloud.ApiClient;
import ai.hanzo.cloud.api.ComputeApi;

ApiClient client = new ApiClient();
client.setBearerToken(System.getenv("HANZO_API_KEY"));

var result = new ComputeApi(client).bindMachineAgent();
```

**HTTP**

```bash
curl -X PUT https://api.hanzo.ai/v1/compute/machines/<id>/agent \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "agentName": "<agentName>",
       "botVersion": "<botVersion>"
     }'
```

**MCP**

Tool `compute`, op `bindMachineAgent` — POST the JSON-RPC envelope to `https://api.hanzo.ai/v1/mcp`.

```bash
curl -X POST https://api.hanzo.ai/v1/mcp \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "jsonrpc": "2.0",
       "id": 1,
       "method": "tools/call",
       "params": {
         "name": "compute",
         "arguments": {
           "op": "bindMachineAgent",
           "input": {
             "id": "<id>",
             "agentName": "<agentName>",
             "botVersion": "<botVersion>"
           }
         }
       }
     }'
```

---

[Compute API](https://docs.hanzo.ai/docs/openapi/compute) · [All Hanzo APIs](https://docs.hanzo.ai/docs/openapi) · [Interactive reference](https://docs.hanzo.ai/docs/openapi/reference)
