> For the complete documentation index, see [llms.txt](https://docs.uptiq.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.uptiq.ai/platform/platform-resources/agent-webhooks.md). Agents can also search and read this documentation through its [MCP server](https://docs.uptiq.ai/~gitbook/mcp).

# Agent Webhooks

Reference for the signed requests an agent sends to its webhooks, with the events, headers, signature check and delivery rules.

An agent sends its results, questions and errors to its webhooks as signed HTTPS requests. This page is the reference for the people who build the receiving system: what each request holds, how to verify its signature, and how delivery works. Agent webhooks work on agents that run on executor version 1.5 and above. See [Versions and features](https://docs.uptiq.ai/platform/platform-resources/agent-executor/versions.md#which-features-need-which-version).

To add, change, disable or delete a webhook, and to get an agent's public key, see [Webhooks](https://docs.uptiq.ai/platform/console/agent-builder/build/webhooks.md) in the Agent Builder.

{% hint style="info" %}
**Agent webhooks aren't run webhooks.** The webhooks set in Agent Config belong to the agent and receive every run. A webhook URL passed in the trigger request of one run is set in the API call. See [Webhooks](https://docs.uptiq.ai/platform/console/agent-builder/deploy/agent-integration/agent-api.md#webhooks).
{% endhint %}

## What the receiver needs

Each message is signed with the agent's private key, so the receiver can check that it came from the platform and wasn't changed. The receiver needs no shared signing secret. It needs two values, both from the agent's **Webhooks** settings.

| Value                | What it identifies                                                                                      |
| -------------------- | ------------------------------------------------------------------------------------------------------- |
| **Agent public key** | The key that verifies messages from this agent. All webhooks on the same agent use the same public key. |
| **Webhook ID**       | The webhook that delivers to the receiver.                                                              |

A message from one webhook can't be verified with another webhook's ID, even when both belong to the same agent. Each agent has one public key, and there's no option to replace it.

## Messages

Agent webhooks apply to runs started through the playground, embedded widgets, the API, and calls to the agent as a sub-agent. Every webhook on the agent gets every event, and each turn of a conversation sends its own event.

| Agent event                             | `elementType`   | What the receiver gets                                                                                                       |
| --------------------------------------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| The agent finishes and returns a result | `done`          | `success: true`, and `result.content` with the answer. When the agent's response format is JSON, the content is parsed JSON. |
| The agent run fails                     | `done`          | `success: false`, and `error`.                                                                                               |
| The agent asks the user a question      | `agent_message` | `elementSubtype: "question"`, and `result.content` with the question.                                                        |

Every message also carries `agentId`, `executionId` and `conversationId`.

A question isn't a final answer. Receiving a message doesn't by itself mean the run succeeded, so the receiving system must check `success` and `elementType` before it treats a message as a success.

Each active destination gets the message for an event, and messages for the same event share the same event ID across destinations. A webhook set on one agent doesn't subscribe that destination to the results of other agents that it calls.

## Request headers

| Header              | Value                            |
| ------------------- | -------------------------------- |
| `webhook-id`        | The event's ID                   |
| `webhook-timestamp` | Unix seconds                     |
| `webhook-signature` | The RSA-SHA256 signature, in hex |

The webhook's own ID isn't sent in any header, so the receiver must store it. Standard Webhooks libraries don't verify these deliveries.

## Verify a delivery

The **Public Key** tab in the agent's **Webhooks** settings states the signing rules.

| Item            | Value                                                                            |
| --------------- | -------------------------------------------------------------------------------- |
| **Signed text** | `{webhook ID}.{webhook-id header}.{webhook-timestamp header}.{raw request body}` |
| **Algorithm**   | RSA-SHA256 with PKCS#1 v1.5 padding                                              |
| **Signature**   | The hex value of the `webhook-signature` header                                  |
| **Timestamp**   | Unix seconds. Reject stale requests to block replays.                            |

1. Reject a timestamp that is more than about 5 minutes old.
2. Build the signed text from the webhook's ID, the `webhook-id` header, the `webhook-timestamp` header, and the raw request body exactly as received.
3. Verify the hex signature against the signed text with the public key, using RSA-SHA256.

{% tabs %}
{% tab title="Node.js" %}

```js
import crypto from 'node:crypto';

function isValidAgentWebhook({ rawBody, headers, webhookId, publicKey }) {
    const eventId = headers['webhook-id'];
    const timestamp = headers['webhook-timestamp'];
    const signature = headers['webhook-signature'];

    if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;

    const signedText = `${webhookId}.${eventId}.${timestamp}.${rawBody}`;
    return crypto.verify('RSA-SHA256', Buffer.from(signedText), publicKey, Buffer.from(signature, 'hex'));
}
```

{% endtab %}

{% tab title="Python" %}

```python
import time
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.exceptions import InvalidSignature

def is_valid_agent_webhook(raw_body: bytes, headers, webhook_id: str, public_key_pem: str) -> bool:
    event_id = headers["webhook-id"]
    timestamp = headers["webhook-timestamp"]
    signature = bytes.fromhex(headers["webhook-signature"])

    if abs(time.time() - int(timestamp)) > 300:
        return False

    signed_text = f"{webhook_id}.{event_id}.{timestamp}.".encode() + raw_body
    public_key = serialization.load_pem_public_key(public_key_pem.encode())
    try:
        public_key.verify(signature, signed_text, padding.PKCS1v15(), hashes.SHA256())
        return True
    except InvalidSignature:
        return False
```

{% endtab %}
{% endtabs %}

Run the agent and check that the receiver verifies a new message before it uses the contents.

## Respond to a delivery

* Return a 2xx status within 15 seconds.
* An event can arrive more than once. Deduplicate on the `webhook-id` header.

## Delivery failures and retries

If the receiver is unavailable or returns an error, the platform makes up to three delivery attempts over about three minutes.

The agent run can finish normally even when delivery fails, so a successful agent response doesn't prove that the receiving system got it.

## Troubleshoot deliveries

| Problem                                   | What to check or do                                                                                                                                                                                                                |
| ----------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Signature verification fails              | Use this agent's public key and this destination's webhook ID. Another webhook's ID doesn't verify the message. Build the signed text from the raw body exactly as received.                                                       |
| The same event arrives twice              | Deduplicate on the `webhook-id` header.                                                                                                                                                                                            |
| A message holds a question                | Treat it as a request for user input, not a final answer.                                                                                                                                                                          |
| A message shows a failure                 | Read the error. Don't treat it as a success.                                                                                                                                                                                       |
| No message arrives after the retry window | Check the endpoint address, the webhook's status in the builder, and whether the receiver is available. See [Troubleshoot webhooks](https://docs.uptiq.ai/platform/console/agent-builder/build/webhooks.md#troubleshoot-webhooks). |

## What's next

{% content-ref url="/pages/RJudvOwUOJlZ66SwT1b3" %}
[Webhooks](https://docs.uptiq.ai/platform/console/agent-builder/build/webhooks.md)
{% endcontent-ref %}

{% content-ref url="/pages/lsLBRS4eOj0g8ndRCgiq" %}
[Versions and features](https://docs.uptiq.ai/platform/platform-resources/agent-executor/versions.md)
{% endcontent-ref %}

{% content-ref url="/pages/FRNOzo7JXcLJUGyEW6Is" %}
[Integrate Agent](https://docs.uptiq.ai/platform/console/agent-builder/deploy/agent-integration.md)
{% endcontent-ref %}

***

{% columns %}
{% column width="83.33333333333334%" %}

<p align="right"><em>Maintained by</em> <mark style="color:green;">Abhishek Paul</mark><br><code>AI-assisted, human-approved</code></p>
{% endcolumn %}

{% column width="16.666666666666664%" %}

<div align="left"><img src="https://1326225582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0qmgQjJ5aArDTj2ACFHG%2Fuploads%2Fgit-blob-d034645b4f8f8ee661985f5306b60ded3289653c%2Fmaintainer-abhishek-paul.png?alt=media" alt="" width="60"></div>
{% endcolumn %}
{% endcolumns %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.uptiq.ai/platform/platform-resources/agent-webhooks.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
