# Confirm agent candidate solutions

Confirm a verified candidate solution and load it as a readable agent version.

```text
POST https://moi.matrixorigin.cn/newmoi/workspaces/{workspace_id}/agent-builder/candidates/{agent_id}/candidate-versions/{candidate_version}/commit
```

## Preparation before calling

First [generate the agent candidate program](propose-candidate.md) or [regenerate the agent candidate program](repropose-candidate.md)] to obtain the candidate version and `source_digest`. Prepare a personal access token with access to the target workspace, target workspace ID, agent ID, and release candidate.

The example below uses:

- `$AI_STUDIO_API_KEY`: The actual personal access token, passed through the `X-API-Key` Header.
- `$WORKSPACE_ID`: Target workspace ID, passed through the `X-Workspace-ID` Header and also as `workspace_id` in the path.
- `$AGENT_ID`: Agent ID, as `agent_id` in the path.
- `$CANDIDATE_VERSION`: The release candidate to be confirmed as `candidate_version` in the path.
- `$SOURCE_DIGEST`: Digest from the current candidate response for `source_digest` in the request body.

## Request example

```bash
curl -X POST "https://moi.matrixorigin.cn/newmoi/workspaces/$WORKSPACE_ID/agent-builder/candidates/$AGENT_ID/candidate-versions/$CANDIDATE_VERSION/commit" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d '{
    "source_digest": "'"$SOURCE_DIGEST"'"
  }'
```

## Path parameters

| Parameters | Type | Is it required | Description |
| --- | --- | --- | --- |
| `workspace_id` | string | Yes | Workspace ID. |
| `agent_id` | string | Yes | Agent ID. |
| `candidate_version` | string | Yes | Candidate version to confirm. |

## Request body

| Parameters | Type | Is it required | Description |
| --- | --- | --- | --- |
| `source_digest` | string | Yes | The digest in the current candidate response. |
| `metadata` | object | No | Metadata to write. |
| `binding` | object | No | Runtime environment binding override. |

## Successful response

Returns `200` on success. Save `load_version` and use it to query the current agent configuration.

```json
{
  "code": 0,
  "data": {
    "workspace_id": "ws_01",
    "agent_id": "agent_01",
    "name": "产品助手",
    "load_version": "v1",
    "source_digest": "sha256:<HEX_DIGEST>",
    "package_digest": "sha256:<HEX_DIGEST>"
  }
}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `code` | integer | `0` on success. |
| `data.workspace_id` | string | Workspace, ID and name of the loaded agent. |
| `data.agent_id` | string | Workspace, ID and name of the loaded agent. |
| `data.name` | string | Workspace, ID and name of the loaded agent. |
| `data.load_version` | string | Loaded version; used to [query the current agent configuration](get-current-agent.md). |
| `data.source_digest` | string | Confirmed candidate content summary and loaded package summary. |
| `data.package_digest` | string | Confirmed candidate content summary and loaded package summary. |

## Error response

```json
{
  "code": 4,
  "message": "<错误信息>"
}
```

### Common HTTP errors

```{list-table}
:header-rows: 1
:widths: 12 22 32 34

* - HTTP status code
  - error code
  - Common causes
  - Recommended actions
* - `400`
  - `2`（`INVALID_ARGUMENT`）
  - The request contains unknown fields, candidate content, or the binding override is invalid.
  - Check the request body and candidate diagnostics.
* - `401`
  - `6`（`UNAUTHENTICATED`）
  - Lack of valid identity credentials.
  - Check API Key.
* - `403`
  - `5`（`PERMISSION_DENIED`）
  - The current identity does not have the authority to confirm the candidate.
  - Check workspace and agent authorizations.
* - `404`
  - `3`（`NOT_FOUND`）
  - Release candidate does not exist.
  - Check for release candidates.
* - `409`
  - `4`（`ALREADY_EXISTS`）
  - The candidate summary does not match, the candidate has been replaced, or the current status cannot be confirmed.
  - Get the latest candidate and use it `source_digest`.
* - `500`
  - `1`（`INTERNAL`）
  - Candidate loading failed.
  - Regenerate after correcting the configuration according to the candidate diagnosis.
* - `503`
  - `15`（`UNAVAILABLE`）
  - Agent construction or authorization services are temporarily unavailable.
  - Try again later.
```

## Follow-up operations

Use `load_version` [Query the current agent configuration](get-current-agent.md).
