# sessions.agent_attach

`POST /api/public/v1/sessions/{id}/agent-attach`

Giữ quyền đọc hoặc ghi cho agent; ghi cần thêm agent.act trong dữ liệu. Đây không phải vé kết nối CDP.

- Quyền: `agent.observe`
- Lệnh (chống trùng): Không
- Tool MCP: `sessions_agent_attach`

## Tham số

| Tên | Vị trí | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|---|
| `id` | path | string (uuid) | Có |  |
| `idempotency_key` | body | string | Có | (độ dài tối thiểu 1, độ dài tối đa 163) |
| `holder_kind` | body | "api" \| "mcp" \| "rpa" \| "cdp" \| "human" | Có |  |
| `mode` | body | "reader" \| "writer" | Không | Mặc định: `"writer"`. |
| `epoch` | body | integer | Không | (tối thiểu 0, tối đa 9007199254740991) |
| `ttl_seconds` | body | integer | Không | (tối thiểu 1, tối đa 900) Mặc định: `300`. |
| `control_mode` | body | "quiet" \| "compat" | Không | Mặc định: `"quiet"`. |

## Phản hồi

200 với { data, correlation_id }.

Danh sách trường của phản hồi này chưa được công bố; đọc data như JSON.

## Lỗi

| Mã | HTTP | Thử lại |
|---|---|---|
| `UNAUTHENTICATED` | 401 | Không |
| `FORBIDDEN` | 403 | Không |
| `RATE_LIMITED` | 429 | Có |
| `VALIDATION_FAILED` | 422 | Không |
| `NOT_FOUND` | 404 | Không |
| `DEPENDENCY_UNAVAILABLE` | 503 | Có |
| `UNKNOWN` | 500 | Không |

## Ví dụ (curl)

```bash
curl -X POST "https://browlix.com/api/public/v1/sessions/<id>/agent-attach" \
  -H "Authorization: Bearer $BROWLIX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"idempotency_key":"<idempotency_key>","holder_kind":"api"}'
```

## Ví dụ (TypeScript SDK)

```ts
import { Browlix } from "@browlix/sdk";

const bx = new Browlix({ apiKey: process.env.BROWLIX_API_KEY! });
const reply = await bx.call("sessions.agent_attach", { path: { id: "<id>" }, body: {"idempotency_key":"<idempotency_key>","holder_kind":"api"} });
console.log(reply.data);
```

## Ví dụ (Python)

```python
import os
import requests

r = requests.post(
    "https://browlix.com/api/public/v1/sessions/<id>/agent-attach",
    headers={"Authorization": f"Bearer {os.environ['BROWLIX_API_KEY']}"},
    json={"idempotency_key":"<idempotency_key>","holder_kind":"api"},
    timeout=60,
)
print(r.status_code, r.json())
```

## Ví dụ (MCP)

```json
{
  "method": "tools/call",
  "params": {
    "name": "sessions_agent_attach",
    "arguments": {
      "id": "<id>",
      "idempotency_key": "<idempotency_key>",
      "holder_kind": "api"
    }
  }
}
```
