Skip to content

Events

Events let an external system queue work for a PinionAI agent. The API stores each event, and a separate event worker matches it to a route and runs that route's intent. The sender does not need to start an agent session or wait for the flow to finish.

Set up event processing

  1. In Studio, open Events from the Data menu and select the account.
  2. Create and enable a route. Choose the agent and one of its active intents, then enter the event type the sender will post. Use Then post as only when a second route should run after this route succeeds.
  3. Ensure the pinionai-event-worker container is running. It processes queued events independently of the API.
  4. Give the sender an account bearer token and the PinionAI API base URL.

Routes are unique by event type within an account. They can be enabled or paused with On/Off, and edited after creation. The selected agent is the initial agent choice in the new-route form; choose a different agent there when needed. Each route must name a concrete agent and intent.

Post an event

Send a JSON request to POST /events with the account's bearer token (see PinionAI API):

curl -X POST "$PINIONAI_API_URL/events" \
  -H "Authorization: Bearer $ACCOUNT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "deal.changed",
    "key": "deal:123:7",
    "occurred_at": "2026-10-27T18:00:00Z",
    "payload": {
      "dealId": "123",
      "state": "Ordered"
    }
  }'

The event fields are:

Field Required Meaning
type Yes Event type used to find a route. Types may contain letters, digits, ., _, :, and -.
key Yes Sender-provided idempotency key, unique per account.
payload Yes JSON object passed to the routed intent.
occurred_at No Event occurrence time in RFC 3339 format.

Use the same key when retrying delivery of the same logical event; duplicates are not enqueued twice. Use a new key for a new occurrence. A successful API response means the event was accepted for processing, not that the intent completed. The response includes accepted, duplicate, and rejected counts and per-event details.

You can also post a batch of 1–500 events:

{
  "events": [
    {
      "type": "deal.changed",
      "key": "deal:123:7",
      "payload": { "dealId": "123", "state": "Ordered" }
    },
    {
      "type": "deal.changed",
      "key": "deal:456:2",
      "payload": { "dealId": "456", "state": "Review" }
    }
  ]
}

Configure routes

A route maps an event type to one agent and intent. An exact route such as deal.changed takes precedence over prefix routes. If there is no exact route, the matching route with the longest prefix wins; for example, deal.* matches deal.changed. A * is used as the trailing prefix wildcard.

For a new route, the intent list contains active intents assigned to the selected agent. Intent names must not contain the words for, using, with, or in: the worker starts the intent by sending :<intent> to the agent.

Each route has a Max attempts value (default 8), a description, and an optional Then post as event type. A then-type hand-off runs only after the current route's intent succeeds. It enqueues the same payload using the new event type, so that event is matched to its own route. For example:

support.changed -> CRM sync agent -> then support.triage
support.triage  -> support triage agent

This lets the second intent use data written by the first. The hand-off key is derived from the original key and the then type, so the same hand-off is not enqueued twice. A route cannot hand an event off to its own type.

How the worker runs events

The worker claims due events and runs the selected route's intent. It provides these variables:

  • var.event: the JSON payload.
  • var.event_type: the posted event type.
  • var.event_key: the sender's idempotency key.
  • var.event_uid: the stored event UID.
  • var.stopOnError: set to true so the flow stops when a step fails.

The worker reuses a session per agent, but resets its history and variables for each event. This is background event processing, not a new interactive chat.

Failed events retry with exponential backoff starting at 30 seconds, then 1 minute, 2 minutes, and so on, capped at one hour. After the route's max attempts, an event is marked dead. Events without a matching enabled route become unrouted.

Monitor and retry

The Events page shows counts by status. Use the Status filter and Event type starts with filter to find events. Each event's details include its payload, attempt count, schedule, and last error. Retry now retries one failed, dead, or unrouted event; the bulk retry button re-queues all retryable events shown on the page. A retry resets the attempt count and clears the previous error. For an unrouted event, add or enable a matching route before retrying.

Status Meaning
pending Waiting for the worker.
running Claimed by a worker.
done The routed intent succeeded.
failed An attempt failed and will be retried.
dead The route's maximum attempts were exhausted.
unrouted No enabled route matched the event type.

To troubleshoot, confirm the worker is running, verify the event type matches an enabled route, then inspect the event's last error and payload. Fix the route or intent before retrying so the next attempt can succeed.

Call external services from an event

An MCP step can call a configured tool directly when its Parameters JSON names a tool with the reserved _tool key. The other parameter values can use event variables:

{
  "_tool": "upsert_contact",
  "key": "crm:{{ var.event.email }}",
  "email": "{{ var.event.email }}",
  "tags": "{{ var.event.tags }}"
}

When a value is exactly one template expression, its type is preserved; for example, a list in var.event.tags stays a list. Direct calls do not ask a model to select a tool. See MCP direct tool calls and the PinionAI API for additional reference.