Create an agent¶
Create an agent resource in the current workspace. The caller needs permission to create agents in the workspace; do not pass workspace_id or user_id in the request body, the service will determine them from the request context.
POST https://moi.matrixorigin.cn/newmoi/workspaces/{workspace_id}/agents
Preparation before calling¶
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 theX-API-KeyHeader.$WORKSPACE_ID: The workspace ID of the agent to be created, passed via theX-Workspace-IDHeader and asworkspace_idin the path.
Models, tools, skills, knowledge bases, and runtime environments referenced in the request body must be parsable.
Request example¶
curl -X POST "https://moi.matrixorigin.cn/newmoi/workspaces/$WORKSPACE_ID/agents" \
-H "X-API-Key: $AI_STUDIO_API_KEY" \
-H "X-Workspace-ID: $WORKSPACE_ID" \
-H "Content-Type: application/json" \
-d '{
"name": "销售助手",
"instruction": {
"system_prompt": "分析销售数据"
},
"runtime": {
"provider": "astra",
"profile": "default"
}
}'
Path parameters¶
Parameters |
Type |
Is it required |
Description |
|---|---|---|---|
|
string |
Yes |
The ID of the workspace where the agent is to be created. |
Request body¶
Field |
Type |
Is it required |
Description |
|---|---|---|---|
|
string |
Yes |
Agent display name. |
|
object |
Yes |
Command configuration, such as |
|
object |
Yes |
Run target containing |
|
string |
No |
Agent description. |
|
object |
No |
Model configuration, which can include |
|
object |
No |
Resource bindings such as tools, skills, knowledge bases, and channels. |
|
object |
No |
Operation, approval, and guardrail policy references. |
|
object |
No |
Workflow template reference. |
|
string |
No |
Agent state; created as |
|
string |
No |
Agent ID. Generated by the server if not provided. |
|
string |
No |
Agent avatar and icon reference. |
|
string |
No |
Agent avatar and icon reference. |
|
string[] |
No |
Label used for display. |
|
string |
No |
Agent classification. |
|
integer |
No |
Display the sort value. |
|
object |
No |
String key-value label and comment. |
|
object |
No |
String key-value label and comment. |
|
string |
No |
Agent source type: |
|
string |
No |
Agent source reference. |
|
object |
No |
Extended metadata. |
[] after a type denotes an array. [] in a field path denotes each item in an array.
Successful response¶
Returns 201 on success. data is a new agent.
{
"code": 0,
"data": {
"id": "agent_01",
"workspace_id": "ws_01",
"schema_version": 1,
"name": "销售助手",
"instruction": {
"system_prompt": "分析销售数据"
},
"runtime": {
"provider": "matrixone",
"profile": "default"
},
"status": "draft",
"version": 1,
"source_type": "custom",
"created_by": "user_01",
"updated_by": "user_01",
"created_at": "2026-01-15T10:00:00Z",
"updated_at": "2026-01-15T10:00:00Z"
}
}
The response fields are as follows.
Field |
Type |
Description |
|---|---|---|
|
integer |
|
|
string |
Agent ID and workspace ID. |
|
string |
Agent ID and workspace ID. |
|
integer |
Agent metadata structure version. |
|
string |
Agent name and description; will not be returned if no description is set. |
|
string |
Agent name and description; will not be returned if no description is set. |
|
string |
Avatar reference; does not return if not set. |
|
string |
Icon reference; does not return if not set. |
|
string[] |
Display tag; does not return if not set. |
|
string |
Agent classification; does not return if not set. |
|
integer |
Displays the sorting value; does not return if not set. |
|
object |
Command configuration. |
|
object |
Run target containing |
|
object |
Model configuration and resource binding; does not return if not set. |
|
object |
Model configuration and resource binding; does not return if not set. |
|
object |
Policy and workflow reference; not returned if not set. |
|
object |
Policy and workflow reference; not returned if not set. |
|
object |
Life cycle information; does not return if not set. |
|
string |
Agent status and resource version. |
|
integer |
Agent status and resource version. |
|
string |
Source type and source reference; not returned when source reference is not set. |
|
string |
Source type and source reference; not returned when source reference is not set. |
|
object |
Extended tags, comments, and metadata; not returned if not set. |
|
object |
Extended tags, comments, and metadata; not returned if not set. |
|
object |
Extended tags, comments, and metadata; not returned if not set. |
|
string |
Creator and last updater ID; not returned if not set. |
|
string |
Creator and last updater ID; not returned if not set. |
|
string |
Creation and last update times, in RFC 3339 format. |
|
string |
Creation and last update times, in RFC 3339 format. |
[] after a type denotes an array. [] in a field path denotes each item in an array.
Error response¶
{
"code": 2,
"message": "invalid agent metadata"
}
Common HTTP errors¶
HTTP status code |
error code |
Common causes |
Recommended actions |
|---|---|---|---|
|
|
The request body, agent field, run target, or resource reference is invalid. |
Check request fields and referenced resources. |
|
|
Lack of valid identity credentials. |
Check API Key. |
|
|
The current identity does not have permission to create agents in the workspace. |
Use an authorized identity, or contact the administrator for authorization. |
|
|
The same agent ID already exists in the current workspace. |
Use a new ID, or query an existing agent. |
|
|
The agent resource service or its authorized dependencies are temporarily unavailable. |
Try again later. |
Follow-up operations¶
Log data.id. Use the ID to Query agent details to confirm the saving result; when you need to view the version, Query the agent version, when you need to configure binding, Query resource binding or Query execution strategy.