Call an agent from another agent¶
Send messages or query tasks through A2A JSON-RPC. Generating a workflow and executing it are separate operations.
POST https://api.moi.matrixorigin.cn/v5/workspaces/{workspace_id}/agents/{agent_id}/a2a
Preparation before calling¶
Get the Agent Card to check capabilities. To generate or revise a workflow candidate, also list available models and select a generation model.
Prepare a personal access token with access to the target workspace and the workspace ID.
Request example¶
$AGENT_ID and $AGENT_WORKSPACE_ID come from the same agent list item’s id and workspace_id. $WORKSPACE_ID identifies the workspace for this task. $MODEL is a returned model name, not a model configuration ID. Generate unique $REQUEST_ID and $MESSAGE_ID strings for this request and message.
This example marks the conversation for workflow generation. Other agent messages can omit conversation_purpose; whether they require an explicit model depends on the target agent.
curl -X POST "https://api.moi.matrixorigin.cn/v5/workspaces/$WORKSPACE_ID/agents/$AGENT_ID/a2a?agent_workspace_id=$AGENT_WORKSPACE_ID" \
-H "X-API-Key: $AI_STUDIO_API_KEY" \
-H "X-Workspace-ID: $WORKSPACE_ID" \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc": "2.0",
"id": "'"$REQUEST_ID"'",
"method": "message/send",
"params": {
"model": "'"$MODEL"'",
"metadata": {
"conversation_purpose": "workflow"
},
"message": {
"kind": "message",
"role": "user",
"messageId": "'"$MESSAGE_ID"'",
"parts": [
{
"kind": "text",
"text": "Generate a manually triggered text-cleaning workflow with a required string input text, using a registered cleaning operator. Submit a deployable candidate; do not deploy or run it."
}
]
}
}
}'
Path parameters¶
Parameter |
Type |
Required |
Description |
|---|---|---|---|
|
string |
Yes |
Task workspace; must match the workspace header. |
|
string |
Yes |
Target agent ID from the agent list. |
Query parameters¶
Parameter |
Type |
Required |
Description |
|---|---|---|---|
|
string |
No |
Agent’s owning workspace: the current workspace or |
The generic POST /v5/agents/a2a endpoint takes agent_id and optional agent_workspace_id in its body; supported built-in codes can use agent_code. The workspace-scoped endpoint above places selectors in the path and query, and accepts only JSON-RPC in the body.
Request body¶
Field |
Type |
Required |
Description |
|---|---|---|---|
|
string |
Yes |
Set to |
|
string or number |
No |
JSON-RPC request ID, echoed in the response. |
|
string |
Yes |
|
|
object |
Yes |
Method parameters. |
|
string |
For workflow generation |
Available model name; required for generation and revisions, not task queries. |
|
object |
No |
Extension information such as conversation purpose. |
|
string |
No |
Use |
|
object |
For sending |
A2A message. |
|
string |
For sending |
Set to |
|
string |
For sending |
Use |
|
string |
For sending |
Unique message identifier. |
|
string |
No |
Previous task’s |
|
object[] |
For sending |
Message parts. |
|
string |
Yes |
Use |
|
string |
For text parts |
Natural-language requirements. |
|
string |
For task queries |
Actual task ID for |
[] in a field path denotes each array item; after a type it denotes an array.
Successful response¶
Returns JSON-RPC. Sending a message may return a message or a task. An accepted or working task still needs polling and is not a completed result.
{
"jsonrpc": "2.0",
"id": "req_01",
"result": {
"kind": "task",
"id": "task_01",
"contextId": "ctx_01",
"status": {
"state": "submitted"
}
}
}
Field |
Type |
Description |
|---|---|---|
|
string |
|
|
string, number, or null |
Echoed request ID. |
|
object |
Method result. |
|
string |
Task or message type. |
|
string |
Task ID in a task result. |
|
string |
Conversation context for subsequent revisions. |
|
object |
Task status. |
|
string |
|
|
object[] |
Task artifacts; check for a valid candidate when generating workflows. |
Send tasks/get to the same URL with this body. Use result.id, not a conversation or message ID.
{
"jsonrpc": "2.0",
"id": "get-task-1",
"method": "tasks/get",
"params": {
"id": "task_01"
}
}
Provide requested information or authorization for tasks waiting on input or authorization. Stop deployment if generation fails, is canceled, or is rejected. Even a completed task may have no deployable candidate. In that case, ask the assistant to continue with a new message ID, the previous contextId, and params.model again.
Error response¶
The workspace-scoped endpoint returns this error excerpt when a workflow generation request omits the model. Error display text may be localized.
{
"jsonrpc": "2.0",
"id": "req_01",
"error": {
"code": -32602,
"message": "智能体运行时请求无效。",
"data": {
"domain": "moi-core.agent_runtime",
"meta": {
"cause": "workflow agent model is required"
},
"reason": "INVALID_PARAMS"
}
}
}
HTTP status |
Error code |
Cause and action |
|---|---|---|
400 |
|
Invalid agent parameters, such as a missing workflow generation model. Inspect |
500 |
|
Generic endpoint forwarding or processing failure. Save request time and request/trace IDs; check the workspace-scoped endpoint for details. Query conversations and tasks before resubmitting an uncertain request. |
Use error.data.trace_id when available to locate a request. Generic endpoint errors use a different envelope from runtime JSON-RPC errors; handle both formats.
Follow-up operations¶
Keep result.id for polling and result.contextId for revisions.