Agent Webhooks
Receive agent response notifications via HTTP callbacks.
How It Works
When you send a message to an agent via POST /UserAgent/Message/Send, include a callbackurl parameter. Once the agent's turn ends, Wiro sends a POST request to your URL with the result. Callbacks fire on agent_end (success), agent_error (failure during processing), and agent_cancel only when a turn that had started is stopped. Messages cancelled while still queued (status agent_queue, before the agent starts on them) are marked agent_cancel in the database but do not fire a webhook, because there was no processing attempt to report on. See the "When the cancel webhook fires" note below for the full decision table.
This lets you build fully asynchronous workflows: fire a message and let your backend handle the response whenever it arrives, without polling or maintaining a WebSocket connection.
A setup reply that Wiro handles itself, such as a yes that applies a setup card, runs no agent turn: Wiro posts its result to the callbackurl right away, with status: "agent_end". Its metadata holds type: "setup_result", cards (the ids of the cards it acted on) and via ("api" for a message sent with a project API key, "web" otherwise). It also holds next when the answer leaves connectors to connect ([{ connector, title, mode, cardid?, messageguid? }], as in setupresult), listed and listedfrom for a card listing (the ids of the cards it showed and the guid of the message they are on), and teamguid when the message was sent in a team's workspace. See Replies Wiro handles itself.
A reply to a connector's approval card, such as a yes that allows the card's call once or gets Wiro's listing of it, is posted the same way, right away and with status: "agent_end". Its metadata also holds approvalresult: answered ([{ cardid, messageguid, action, result, code? }], what Wiro did with each card) and listed ([{ number, cardid, messageguid }], the cards a listing showed), and for a listing listedfrom, the guid of the agent's latest reply when it was made: the message the cards are on, or the reply that came after them for cards on earlier messages. See Answering with a reply.
An unknown or disabled slash command that Wiro answers itself, such as /status, and an operator-only command sent with a project API key, such as /agent_limits, are posted the same way, right away and with status: "agent_end". Their metadata holds type: "setup_result", cards: [], command (the command's name, such as "status" or "agent_limits"), via and, in a team's workspace, teamguid. See Unknown or disabled commands.
Results that arrive later. When the agent moves longer work to the background, its turn ends with a short line saying the result will follow, and that line is what your
callbackurlreceives (status: "agent_end"). The result is added to the session later as a separate message and doesn't call thecallbackurl. Read it withMessage/History, or follow the session on the Agent WebSocket.
Setting a Callback URL
Include callbackurl in your message request body. POST /UserAgent/Message/Send:
{
"useragentguid": "your-useragent-guid",
"message": "What are today's trending topics?",
"sessionkey": "user-123",
"callbackurl": "https://your-server.com/webhooks/agent-response"
}
The callback URL is stored per-message. You can use different URLs for different messages, or omit it entirely if you prefer polling or WebSocket.
Callback Payload
When the agent finishes, Wiro sends a POST request to your callbackurl with Content-Type: application/json. The payload is deliberately answer-focused: it contains the final answer/error and structured answer metadata, but not the ordered turn timeline.
Successful Completion (agent_end)
{
"messageguid": "c3d4e5f6-a7b8-9012-cdef-345678901234",
"status": "agent_end",
"content": "What are today's trending topics?",
"response": "Here are today's trending topics in tech...",
"debugoutput": "Here are today's trending topics in tech...",
"metadata": {
"type": "progressGenerate",
"task": "Generate",
"speed": "14.2",
"speedType": "words/s",
"elapsedTime": "8.1s",
"tokenCount": 156,
"wordCount": 118,
"raw": "Here are today's trending topics in tech...",
"answer": ["Here are today's trending topics in tech..."]
},
"endedat": 1712050004
}
Error (agent_error)
{
"messageguid": "c3d4e5f6-a7b8-9012-cdef-345678901234",
"status": "agent_error",
"content": "What are today's trending topics?",
"response": "[AGENT_UNAVAILABLE] Agent is temporarily unavailable. Please try again shortly.",
"debugoutput": "[AGENT_UNAVAILABLE] Agent is temporarily unavailable. Please try again shortly.",
"metadata": {},
"endedat": 1712050004
}
Cancelled (agent_cancel)
{
"messageguid": "c3d4e5f6-a7b8-9012-cdef-345678901234",
"status": "agent_cancel",
"content": "What are today's trending topics?",
"response": "[REQUEST_CANCELLED] Request cancelled.",
"debugoutput": "[REQUEST_CANCELLED] Request cancelled.",
"metadata": {},
"endedat": 1712050004
}
The
responseanddebugoutputfields hold[REQUEST_CANCELLED] Request cancelled.; usestatus === "agent_cancel"as the signal.When the cancel webhook fires:
agent_cancelis delivered only when the turn had already started and was stopped while it ran (byPOST /UserAgent/Message/Cancelor a timeout). For messages cancelled before the agent starts on them (still queued, or an instantMessage/Cancelthat beats dispatching), the message is markedagent_cancelin the database and returned as such inPOST /UserAgent/Message/Detail, but no webhook is fired, because there was no processing attempt to report on. UsePOST /UserAgent/Message/Detail(checkingstatus === "agent_cancel") as the canonical source of truth for cancellation; WebSocket subscribers receive theagent_cancelevent only on active-processing aborts (same condition as the webhook). Treat the webhook as a best-effort "processing was interrupted" signal.
Field Reference
| Field | Type | Description |
|---|---|---|
messageguid |
string | Unique identifier of the message. Use this to correlate with your records. |
status |
string | Final status: agent_end, agent_error, or agent_cancel. |
content |
string | The original user message you sent. |
response |
string | The agent's full response text on success. For errors, contains the error message. For cancellation, contains the abort reason. |
debugoutput |
string | Same as response: the full accumulated output text. Included for consistency with the polling API. |
metadata |
object | Structured answer data, performance metrics, and raw text. Timeline blocks are not embedded in webhooks. Empty object ({}) for agent_cancel and for an agent_error that cut the turn off; see The metadata Object. |
endedat |
number | Unix timestamp (UTC seconds) when processing finished. |
The metadata Object
On successful completion (agent_end), the metadata object contains the structured answer and final stream metrics:
| Field | Type | Description |
|---|---|---|
type |
string | "progressGenerate" for an agent turn. A reply Wiro handles itself has "setup_result" instead, with the keys described under How It Works. |
task |
string | Always "Generate". |
raw |
string | The complete response text. |
answer |
array | Array of response segments: the content to show the user. |
speed |
string | Final generation speed (e.g. "14.2"). |
speedType |
string | Speed unit: "words/s". |
elapsedTime |
string | Total generation time (e.g. "8.1s"). |
tokenCount |
number | Number of answer chunks streamed for the turn. Use the message's billing columns for authoritative model tokens. |
wordCount |
number | Total words in the response. |
For agent_cancel, and for an agent_error that cut the turn off, such as [TURN_INTERRUPTED] or [AGENT_UNAVAILABLE] after an outage, metadata is an empty object {}. A turn that ended with a coded failure, such as [SPEND_LIMIT_REACHED], [CREDITS_EXHAUSTED] or [MODEL_NOT_ALLOWED], posts the usual progressGenerate metadata, and its raw and answer hold the same coded message as response. Read the outcome from status and response, never from metadata.
After receiving the webhook, call POST /UserAgent/Message/Detail with messageguid whenever you need the authoritative top-level timeline[]. It preserves the ordered reasoning, answer, and safe tool-label/status blocks for the completed turn.
Note: For
agent_errorandagent_cancel, the webhook'sresponseanddebugoutputhold the same coded failure message asPOST /UserAgent/Message/Detail; see Failed turns. The underlying error is never sent. A turn the agent's security rules block can also come withagent_endand[SECURITY_BLOCKED] …inresponse.
Status Values
| Status | Description | response contains |
metadata contains |
|---|---|---|---|
agent_end |
Agent completed successfully | Full response text | Structured answer and metrics |
agent_error |
The turn failed | The public failure message; see Failed turns | Empty object {}, or the usual metrics when the turn ended with a coded failure such as [SPEND_LIMIT_REACHED] |
agent_cancel |
Message was cancelled before completion | [REQUEST_CANCELLED] Request cancelled. |
Empty object {} |
Retry Policy
Wiro attempts to deliver each webhook up to 3 times:
- First attempt is immediate when the agent finishes
- 2-second delay between retries
- Any 2xx answer counts as delivered
- Any other answer, a redirect (3xx) included, or no answer, is tried again
- After 3 failed attempts, the webhook is abandoned and the failure is logged server-side
The message result is always persisted in the database regardless of webhook delivery. You can retrieve it at any time via POST /UserAgent/Message/Detail.
Security Considerations
- Webhook calls do not include authentication headers: verify incoming requests by checking the
messageguidagainst your own records - Always use HTTPS endpoints in production
- Use a public address. Wiro doesn't call a
callbackurlwhose host is, or resolves to, a private, loopback or link-local address; that message gets no webhook, and its result stays readable withMessage/Detail - Validate the payload structure before processing
- Consider answering with a 2xx at once and processing the payload asynchronously to avoid timeouts
Code Examples
Webhook Receiver: Node.js (Express)
const express = require('express');
const app = express();
app.use(express.json());
app.post('/webhooks/agent-response', (req, res) => {
const { messageguid, status, content, response, endedat } = req.body;
if (status === 'agent_end') {
console.log(`Agent completed: ${messageguid}`);
console.log(`Response: ${response}`);
} else if (status === 'agent_error') {
console.error(`Agent error for ${messageguid}: ${response}`);
} else if (status === 'agent_cancel') {
console.log(`Agent cancelled: ${messageguid}`);
}
res.sendStatus(200);
});
app.listen(3000);
Webhook Receiver: Python (Flask)
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/webhooks/agent-response', methods=['POST'])
def agent_webhook():
data = request.json
messageguid = data.get('messageguid')
status = data.get('status')
response_text = data.get('response')
if status == 'agent_end':
print(f"Agent completed: {messageguid}")
print(f"Response: {response_text}")
elif status == 'agent_error':
print(f"Agent error for {messageguid}: {response_text}")
elif status == 'agent_cancel':
print(f"Agent cancelled: {messageguid}")
return jsonify({"ok": True}), 200
if __name__ == '__main__':
app.run(port=3000)
Webhook Receiver: PHP
<?php
$payload = json_decode(file_get_contents('php://input'), true);
$messageguid = $payload['messageguid'] ?? '';
$status = $payload['status'] ?? '';
$response = $payload['response'] ?? '';
if ($status === 'agent_end') {
error_log("Agent completed: $messageguid");
error_log("Response: $response");
} elseif ($status === 'agent_error') {
error_log("Agent error for $messageguid: $response");
} elseif ($status === 'agent_cancel') {
error_log("Agent cancelled: $messageguid");
}
http_response_code(200);
echo json_encode(['ok' => true]);
Sending a Message with Callback: curl
curl -X POST "https://api.wiro.ai/v1/UserAgent/Message/Send" \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-d '{
"useragentguid": "your-useragent-guid",
"message": "Summarize today'\''s news",
"sessionkey": "user-123",
"callbackurl": "https://your-server.com/webhooks/agent-response"
}'
Response
{
"result": true,
"errors": [],
"messageguid": "c3d4e5f6-a7b8-9012-cdef-345678901234",
"agenttoken": "eDcCm5yyUfIvMFspTwww49OUfgXkQt",
"status": "agent_queue"
}
The agenttoken can be used to track the message via Agent WebSocket for real-time streaming, while the webhook delivers the final result to your server.