Skip to main content

Create Task

Start a new task with AI agents to execute your requirements.

Endpoint​

POST https://api.xmz.ai/v1/agentrix/tasks/start

Authentication​

Requires API key in the Authorization header:

Authorization: Bearer YOUR_API_KEY

Prerequisites​

Before creating a task, you must first create a chat session. The chat provides the context and agent for task execution. See Create Chat for details.

Execution Modes​

Tasks can be executed in three modes:

  1. Cloud Mode: Task runs on Agentrix cloud infrastructure (requires cloudId + message)
  2. Local Mode: Task runs on your local machine (requires machineId + encryptedMessage + dataEncryptionKey)
  3. Sub-task Mode: Task inherits execution context from parent task (requires parentTaskId)

Request Body​

Core Required Field​

ParameterTypeRequiredDescription
chatIdstringYesChat identifier (see Create Chat)

Execution Mode (choose one)​

Cloud Mode​

ParameterTypeRequiredDescription
cloudIdstringYes*Cloud cluster identifier
messageobjectYes*User message with role and content

Local Mode​

ParameterTypeRequiredDescription
machineIdstringYes*Local machine identifier
encryptedMessagestringYes*Base64 encrypted message payload
dataEncryptionKeystringYes*Base64 encryption key
cwdstringNoWorking directory
forceUserCwdbooleanNoForce use of user cwd (no worktree)

Sub-task Mode​

ParameterTypeRequiredDescription
parentTaskIdstringYes*Parent task ID (inherits execution context)

*One execution mode is required

Optional Configuration​

ParameterTypeDescription
customTitlestringCustom task title (1-200 characters)
agentIdstringSpecific agent ID (defaults to first chat agent)
repositoryIdstringAssociated repository identifier
baseBranchstringGit branch name
repositorySourceTypestringRepository source type: temporary, directory, or git-server

Response​

Success Response (201 Created)​

{
"taskId": "task-xxx",
"chatId": "chat-xxx",
"agentId": "agent-xxx",
"userId": "user-xxx",
"state": "pending",
"machineId": null,
"cloudId": "cloud-xxx",
"repositoryId": null,
"baseBranch": null,
"title": null,
"customTitle": "My Task",
"userCwd": null,
"forceUserCwd": null,
"createdAt": "2024-01-15T10:30:00Z",
"updatedAt": "2024-01-15T10:30:00Z"
}

Response Fields​

FieldTypeDescription
taskIdstringUnique task identifier
chatIdstringChat identifier
agentIdstringAgent identifier executing the task
userIdstringUser identifier who created the task
statestringTask state (e.g., pending, running, completed)
machineIdstring | nullMachine ID (if local mode)
cloudIdstring | nullCloud ID (if cloud mode)
repositoryIdstring | nullRepository ID
baseBranchstring | nullGit branch name
titlestring | nullAuto-generated task title
customTitlestring | nullUser-provided custom title
userCwdstring | nullWorking directory
forceUserCwdboolean | nullForce user cwd flag
createdAtstringISO 8601 creation timestamp
updatedAtstringISO 8601 last update timestamp

Error Responses​

400 Bad Request​

{
"code": "INVALID_REQUEST",
"error": "validation_error",
"message": "Invalid request parameters"
}

401 Unauthorized​

{
"code": "UNAUTHORIZED",
"error": "unauthorized",
"message": "Invalid or missing API key"
}

404 Not Found​

{
"code": "CHAT_NOT_FOUND",
"error": "not_found",
"message": "Chat not found"
}

Examples​

Example 1: Cloud Mode Task​

Create a task that runs on cloud infrastructure with a repository context:

curl -X POST https://api.xmz.ai/v1/agentrix/tasks/start \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"chatId": "chat-xxx",
"cloudId": "cloud-xxx",
"message": {
"role": "user",
"content": "Fix the authentication bug in login.ts"
},
"customTitle": "Fix login bug",
"repositoryId": "repo-xxx",
"baseBranch": "develop"
}'

Example 2: Sub-task Mode​

Create a child task that inherits execution context from a parent task:

curl -X POST https://api.xmz.ai/v1/agentrix/tasks/start \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"chatId": "chat-xxx",
"parentTaskId": "task-parent-xxx",
"message": {
"role": "user",
"content": "Add unit tests for the fixed code"
},
"customTitle": "Add tests"
}'

Example 3: Simple Cloud Task​

Create a basic task without repository context:

curl -X POST https://api.xmz.ai/v1/agentrix/tasks/start \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"chatId": "chat-xxx",
"cloudId": "cloud-xxx",
"message": {
"role": "user",
"content": "Explain how async/await works in JavaScript"
}
}'

Workflow​

  1. Create a chat (prerequisite): Use Create Chat to establish a chat session
  2. Save the chatId: Store the returned chat ID for use in task creation
  3. Create a task: Call this endpoint with the chatId and execution mode
  4. Save the taskId: Store the returned task ID for monitoring progress
  5. Monitor progress: Use WebSocket or polling to track task status
  • Create Chat - Required prerequisite for creating tasks
  • Create Share Link - Share task results with others
  • List Tasks - View all your tasks (GET /v1/tasks)
  • Resume Task - Continue a paused task (POST /v1/tasks/:taskId/resume)
  • Cancel Task - Cancel a running task (POST /v1/tasks/:taskId/cancel)
  • Stop Task - Stop task execution (POST /v1/tasks/:taskId/stop)

Need Help?​