Limai Docs
API ReferenceWebhooks

Agent Run Events

Webhook events fired across the lifecycle of an agent run.

Agent run events report the lifecycle of an agent run. Four event types share one payload shape:

EventFires when
AGENT_RUN_STARTEDAn agent run transitions to RUNNING for the first time
AGENT_RUN_COMPLETEDAn agent run finishes successfully
AGENT_RUN_FAILEDAn agent run terminates with an error
AGENT_RUN_WAITING_HUMANAn agent run pauses at a step that requires human input

Agent-Based Routing

Agent run events are routed to subscriptions by agent route, not deployment route. When you subscribe to any agent event you select which agents the subscription listens to; deployments are not involved in routing these events.

A subscription that includes any agent event must have at least one agent route. This mirrors document events, which must have at least one deployment route. See Webhook Setup for the routing-family model.

The payload carries fileId and deploymentId as optional context only -- they are never used to route the event:

  • Document-triggered runs -- fileId and deploymentId are present, pointing at the document that triggered the run.
  • Email-triggered runs -- fileId and deploymentId are null.

Payload Structure

Run Started

Response200
{
  "eventId": "evt_run_started_111",
  "eventType": "AGENT_RUN_STARTED",
  "timestamp": "2024-01-15T11:00:00Z",
  "organizationId": "org_xyz789",
  "projectId": "proj_abc123",
  "agentId": "agt_555",
  "runId": "run_777",
  "stepId": null,
  "fileId": "file_789ghi",
  "deploymentId": "dep_123abc",
  "data": {
    "status": "RUNNING",
    "errorMessage": null,
    "executionDurationMs": null
  }
}

Run Completed

Response200
{
  "eventId": "evt_run_completed_222",
  "eventType": "AGENT_RUN_COMPLETED",
  "timestamp": "2024-01-15T11:00:42Z",
  "organizationId": "org_xyz789",
  "projectId": "proj_abc123",
  "agentId": "agt_555",
  "runId": "run_777",
  "stepId": null,
  "fileId": "file_789ghi",
  "deploymentId": "dep_123abc",
  "data": {
    "status": "COMPLETED",
    "errorMessage": null,
    "executionDurationMs": 42000
  }
}

Run Failed

Response200
{
  "eventId": "evt_run_failed_333",
  "eventType": "AGENT_RUN_FAILED",
  "timestamp": "2024-01-15T11:01:10Z",
  "organizationId": "org_xyz789",
  "projectId": "proj_abc123",
  "agentId": "agt_555",
  "runId": "run_888",
  "stepId": null,
  "fileId": null,
  "deploymentId": null,
  "data": {
    "status": "FAILED",
    "errorMessage": "Tool call timed out",
    "executionDurationMs": 15000
  }
}

Run Waiting for Human

Response200
{
  "eventId": "evt_run_waiting_444",
  "eventType": "AGENT_RUN_WAITING_HUMAN",
  "timestamp": "2024-01-15T11:00:30Z",
  "organizationId": "org_xyz789",
  "projectId": "proj_abc123",
  "agentId": "agt_555",
  "runId": "run_777",
  "stepId": "step_999",
  "fileId": "file_789ghi",
  "deploymentId": "dep_123abc",
  "data": {
    "status": "WAITING_HUMAN",
    "errorMessage": null,
    "executionDurationMs": null
  }
}

Payload Fields

FieldTypeDescription
eventIdstringUnique event identifier. Use for idempotency.
eventTypestringOne of AGENT_RUN_STARTED, AGENT_RUN_COMPLETED, AGENT_RUN_FAILED, AGENT_RUN_WAITING_HUMAN
timestampISO 8601When the transition occurred (UTC)
organizationIdstringYour organization identifier
projectIdstringThe project the agent belongs to
agentIdstringThe agent that produced this run. Used for routing.
runIdstringThe agent run identifier
stepIdstring | nullThe step identifier. Set for AGENT_RUN_WAITING_HUMAN, otherwise null.
fileIdstring | nullContext only. The triggering file for document-triggered runs, null for email-triggered runs.
deploymentIdstring | nullContext only. The triggering deployment for document-triggered runs, null for email-triggered runs.
data.statusstring"RUNNING" | "WAITING_HUMAN" | "COMPLETED" | "FAILED"
data.errorMessagestring | nullError description for AGENT_RUN_FAILED, otherwise null
data.executionDurationMsnumber | nullTotal execution time in milliseconds, when available (set on terminal events)

Handling the Events

function handleAgentRunEvent(event) {
const { eventType, agentId, runId, fileId, data } = event

switch (eventType) {
  case "AGENT_RUN_STARTED":
    console.log(`Agent ${agentId} started run ${runId}`)
    break
  case "AGENT_RUN_WAITING_HUMAN":
    notifyReviewer(runId, event.stepId)
    break
  case "AGENT_RUN_COMPLETED":
    console.log(`Run ${runId} completed in ${data.executionDurationMs}ms`)
    if (fileId) fetchFileData(fileId).then(exportResults)
    break
  case "AGENT_RUN_FAILED":
    console.error(`Run ${runId} failed: ${data.errorMessage}`)
    break
}
}

On this page