Magisterium AI

Iniziare

Questa guida ti accompagna nell'esecuzione della tua prima richiesta verso l'endpoint A2A di Magisterium, nel recupero dell'attività risultante e nella lettura della risposta strutturata.

Prerequisiti

  1. Un piano Magisterium a pagamento (Pro, Organizzazione o Enterprise). Gli account gratuiti riceveranno un errore PLAN_REQUIRED da A2A.
  2. Un token di accesso OAuth 2.0 collegato al tuo account magisterium.com. A2A utilizza lo stesso flusso OAuth del server MCP Magisterium; scopri gli endpoint di autorizzazione, token e registrazione dinamica a partire dai metadati OAuth disponibili in https://www.magisterium.com/.well-known/oauth-authorization-server.
  3. Le competenze che desideri invocare — consulta Competenze per l'elenco completo.

Attenzione: le chiavi API a lunga durata create nella Console API funzionano per Chat Completions, Search e News, ma non sono valide per A2A — A2A accetta solo token utente emessi tramite OAuth.

Esporta il tuo token di accesso come variabile d'ambiente, in modo che gli esempi sottostanti lo rilevino automaticamente:

bash
export MAGISTERIUM_TOKEN=<your-access-token-here>

Passo 1: individua l'agente

Prima di chiamare l'endpoint, puoi recuperare l'Agent Card pubblica per vedere quali competenze sono disponibili e confermare la versione del protocollo:

bash
curl https://www.magisterium.com/.well-known/agent.json

La card non richiede autenticazione. Gli orchestratori possono metterla in cache per un'ora — l'endpoint imposta Cache-Control: public, max-age=3600.

Passo 2: invia il tuo primo messaggio

Tutte le operazioni A2A passano attraverso un unico endpoint JSON-RPC: POST https://www.magisterium.com/api/v1/a2a. L'esempio seguente richiama message/send sulla competenza catholic_qa.

bash
curl -X POST https://www.magisterium.com/api/v1/a2a \
    -H "Authorization: Bearer $MAGISTERIUM_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "jsonrpc": "2.0",
      "id": 1,
      "method": "message/send",
      "params": {
        "message": {
          "role": "user",
          "messageId": "msg-001",
          "kind": "message",
          "parts": [{ "kind": "text", "text": "What does the Church teach about the Real Presence?" }],
          "metadata": { "skillId": "catholic_qa" }
        }
      }
    }'
typescript
const accessToken = process.env.MAGISTERIUM_TOKEN!;

const response = await fetch("https://www.magisterium.com/api/v1/a2a", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${accessToken}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    jsonrpc: "2.0",
    id: 1,
    method: "message/send",
    params: {
      message: {
        role: "user",
        messageId: crypto.randomUUID(),
        kind: "message",
        parts: [
          { kind: "text", text: "What does the Church teach about the Real Presence?" },
        ],
        metadata: { skillId: "catholic_qa" },
      },
    },
  }),
});

const { result: task } = await response.json();
console.log(task.id, task.status.state);
for (const artifact of task.artifacts ?? []) {
  for (const part of artifact.parts) {
    if (part.kind === "text") console.log(part.text);
  }
}
python
import os
import uuid
import httpx

access_token = os.environ["MAGISTERIUM_TOKEN"]

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "message/send",
    "params": {
        "message": {
            "role": "user",
            "messageId": str(uuid.uuid4()),
            "kind": "message",
            "parts": [
                {"kind": "text", "text": "What does the Church teach about the Real Presence?"}
            ],
            "metadata": {"skillId": "catholic_qa"},
        }
    },
}

response = httpx.post(
    "https://www.magisterium.com/api/v1/a2a",
    headers={
        "Authorization": f"Bearer {access_token}",
        "Content-Type": "application/json",
    },
    json=payload,
    timeout=60,
)
task = response.json()["result"]
print(task["id"], task["status"]["state"])
for artifact in task.get("artifacts", []):
    for part in artifact["parts"]:
        if part["kind"] == "text":
            print(part["text"])

Passo 3: leggi la risposta

message/send restituisce un oggetto Task con kind: "task". Una chiamata sincrona a una competenza termina sempre in uno di due stati terminali:

  • status.state == "completed" — i risultati si trovano in result.artifacts. Ogni artefatto ha un artifactId, un name opzionale e una o più parts (text, data o file).
  • status.state == "failed" — il motivo del fallimento si trova in status.message.parts[0].text.
json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "id": "task_abc123",
    "contextId": "ctx_def456",
    "kind": "task",
    "status": { "state": "completed", "timestamp": "2026-04-20T12:00:00.000Z" },
    "artifacts": [
      {
        "artifactId": "art_ghi789",
        "name": "catholic_qa_response",
        "parts": [
          { "kind": "text", "text": "The Catholic Church teaches..." },
          { "kind": "data", "data": { "citations": [] } }
        ]
      }
    ]
  }
}

Passo 4: recupera o annulla un'attività

Le attività vengono conservate per 24 ore e possono essere recuperate tramite ID usando tasks/get:

bash
curl -X POST https://www.magisterium.com/api/v1/a2a \
    -H "Authorization: Bearer $MAGISTERIUM_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "jsonrpc": "2.0",
      "id": 2,
      "method": "tasks/get",
      "params": { "id": "task_abc123" }
    }'

Se hai bisogno di interrompere un'attività, chiama tasks/cancel con lo stesso ID. Poiché tutte le competenze di Magisterium si risolvono in modo sincrono, l'annullamento è utile solo in rari scenari di retry — un'attività già completed o failed non può essere annullata e restituirà INVALID_PARAMS.

Errori comuni

CodiceSignificatoSoluzione
-32004Non autorizzatoVerifica l'header Authorization e che il token di accesso sia valido e non sia scaduto.
-32005Richiesto piano a pagamentoAggiorna il tuo account su magisterium.com/plan.
-32002Competenza non trovataVerifica che metadata.skillId corrisponda a un ID elencato nell'Agent Card.
-32003Limite di utilizzo superatoAttendi i secondi indicati in retryAfter (presente nel data dell'errore) prima di riprovare.

Consulta il Riferimento API completo per tutti i metodi e i codici di errore.