# Update automated tasks

Partially update the configuration of the automation task. Fields not provided remain unchanged.

```text
PATCH https://moi.matrixorigin.cn/newmoi/workspaces/{workspace_id}/agent-automation-tasks/{automation_task_id}
```

## Preparation before calling

First [Query automation task details](get-task.md)confirm the current configuration of the task and obtain the task ID. Prepare a personal access token and target workspace ID that has access to the target workspace.

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.
- `$TASK_ID`: The automation task ID to be updated as `automation_task_id` in the path.

## Request example

```bash
curl -X PATCH "https://moi.matrixorigin.cn/newmoi/workspaces/$WORKSPACE_ID/agent-automation-tasks/$TASK_ID" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d '{
    "status": "disabled"
  }'
```

## Path parameters

| Parameters | Type | Is it required | Description |
| --- | --- | --- | --- |
| `workspace_id` | string | Yes | Workspace ID. |
| `automation_task_id` | string | Yes | Automation task ID. |

## Request body

The request body must be a JSON object. All fields are optional; fields not provided remain unchanged.

| Parameters | Type | Is it required | Description |
| --- | --- | --- | --- |
| `name` | string | No | Task name and description. |
| `description` | string | No | Task name and description. |
| `agent_workspace_id` | string | No | The workspace and agent ID to which the agent belongs. The agent workspace can only be the current workspace or the system workspace. |
| `agent_id` | string | No | The workspace and agent ID to which the agent belongs. The agent workspace can only be the current workspace or the system workspace. |
| `model` | string | No | Model name and LLM backend ID. |
| `llm_backend_id` | integer | No | Model name and LLM backend ID. |
| `instruction_text` | string | No | Fixed instructions used for each run. |
| `trigger` | object | No | Trigger configuration. |
| `auth_policy` | object | No | Certification policy and tool, run, and approval policy references. |
| `tool_policy_ref` | string | No | Certification policy and tool, run, and approval policy references. |
| `runtime_policy_ref` | string | no | Certification policy and tool, run, and approval policy references. |
| `approval_policy_ref` | string | No | Certification policy and tool, run, and approval policy references. |
| `output_contract` | object | No | Structured output constraints. |
| `status` | string | No | Task status. |
| `labels` | object | No | Label and annotation key-value pairs. |
| `annotations` | object | No | Label and annotation key-value pairs. |
| `workflow_app_id` | string | No | Workflow related reference. |
| `agent_task_template_id` | string | No | Workflow related reference. |
| `agent_workflow_binding_id` | string | No | Workflow related reference. |
| `next_trigger_at` | string | No | Next trigger time, using RFC 3339 format. |
| `api_summary` | object | No | API summary. |

Set `status` to `active` to enable the task; set to `disabled` to stop subsequent triggering. Whether triggering configuration or authentication policy changes is valid depends on whether the two are compatible.

## Successful response

Returns `200` on success. Updating the task configuration will not overwrite the configuration snapshot used by existing running records.

```json
{
  "code": 0,
  "data": {
    "id": "task_01",
    "workspace_id": "ws_01",
    "status": "disabled",
    "version": 2,
    "updated_at": "2026-08-18T02:00:00Z"
  }
}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `code` | integer | `0` on success. |
| `data.id` | string | Task ID and workspace ID. |
| `data.workspace_id` | string | Task ID and workspace ID. |
| `data.status` | string | Updated status and task version. |
| `data.version` | integer | The updated status and task version. |
| `data.trigger` | object | Updated trigger, authentication, and output configuration; does not return if not set. |
| `data.auth_policy` | object | Updated trigger, authentication, and output configuration; does not return if not set. |
| `data.output_contract` | object | Updated trigger, authentication, and output configuration; does not return if not set. |
| `data.execution` | object | The updated task execution plan. |
| `data.updated_at` | string | Last updated time, using RFC 3339 format. |

## Error response

```json
{
  "code": 2,
  "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 body, workspace scope, trigger configuration, authentication policy, or status fields are invalid.
  - Check the configuration corresponding to JSON and triggering methods.
* - `401`
  - `6`（`UNAUTHENTICATED`）
  - Lack of valid identity credentials.
  - Check API Key.
* - `403`
  - `5`（`PERMISSION_DENIED`）
  - The current identity has not been verified for workspace access and valid roles.
  - Use an identity and a valid role with access to the workspace.
* - `404`
  - `3`（`NOT_FOUND`）
  - The task or updated target agent does not exist.
  - Check task and agent identification.
* - `409`
  - `4`（`ALREADY_EXISTS`）
  - The update conflicts with the current state of the task or with concurrent versions.
  - After refreshing the task details, resubmit the update based on the current version.
* - `503`
  - `15`（`UNAVAILABLE`）
  - Execution plan, workflow or task services are temporarily unavailable.
  - Try again later.
```

## Follow-up operations

Use the same task ID [Query automation task details](get-task.md) to confirm the current configuration and status.
