Skip to main content
When an Agent completes a Run, Kolena will send an HTTP request of the Run result to the webhook URL. The server listening for webhook deliveries at that URL can take action when it receives one.

Run Result Format

When making a request to your webhook, Kolena will send a JSON object of the following format:
  • agent_id: Agent id.
  • run_id: Agent Run id.
  • run_url: Link to web UI of the Run result.
  • created: Timestamp when the Run result was created.
  • updated: Timestamp when the Run result was last updated.
  • files: List of files of the Run.
  • order: User specified order of the prompts for the Agent. It is mainly used for UI display.
  • data: Prompt results of the Run, a dictionary keyed by prompt name.
Here’s an example of the JSON object:

Respond to Webhook Request

Your webhook handler should respond to the webhook request with an HTTP 2xx status within ten seconds. We will retry up to three times if it does not, with exponential back off. If the delivery still fails after that, we will mark the delivery as failed, and will schedule another delivery after a longer period, for up to five times. If these attempts still fail, the Run result will be omitted from any further delivery.

Example Servers

Below are example servers demonstrating handling webhook deliveries. Since this is an example server, you can use any arbitrary value for the KOLENA_WEBHOOK_SECRET environment variable. When creating your own production server, you should use the secret generated by Kolena after creating the Webhook integration.
main.py
Start the server:

Testing Webhooks

The Python SDK provides a CLI to help test your webhook locally. Install Python SDK and set up an API key. Forward events from an Agent to your webhook by using listen command.
This will listen to new Agent Run results and forward them to your service set in the --forward option. You can use the secret from an existing webhook integration, if you already created one, or any arbitrary value for KOLENA_WEBHOOK_SECRET, as we are just locally testing. The secret passed to the CLI will be used by the kolena_agents CLI to sign the request forwarded to your service. The --tail <N> option can be provided to fetch N most recent results of the Agent. If --tail isn’t included, the command would only listen to new results. You can test your Agent with demo data without relying on the Agent having active data using the sample command.

Register Webhook

Once your service is ready to process Kolena webhook events, follow the steps in Integrations to set it as a destination for your Agent.

Technical Details

Kolena Custom Headers

Kolena includes additional information in request headers:
  • X-Kolena-Timestamp: Timestamp of the request
  • X-Kolena-Delivery-ID: Unique id for the request
  • X-Kolena-Signature: HMAC value of request body, timestamp, and Delivery ID signed with webhook secret
You can use this information to verify that requests are coming from Kolena, detailed in the next section.

Signature Verification

When Kolena makes a request to your webhook URL, it will use the shared secret to create a signature from the timestamp the request is created, the request Delivery ID, and the body of the request. The signature, timestamp and Delivery ID are put in the request headers X-Kolena-Signature, X-Kolena-Timestamp, and X-Kolena-Delivery-ID, respectively. Upon receiving a request, use the secret to compute the signature from the X-Kolena-Timestamp, X-Kolena-Delivery-ID and request body, and verify the signature you computed matches the value in X-Kolena-Signature. It is also advised to verify that X-Kolena-Timestamp is within a short time window from the time the request is received. Kolena provides a utility function webhook.construct_event in our Python SDK. It performs signature verification and returns the parsed JSON object.