Skip to content

abt watch

abt watch runs long-lived processes that listen for external events (Slack, GitHub, Jira, cron) and dispatch a workflow when a matching event arrives. These are entrypoint workflows: workflows under workflows/ that declare a trigger:. Each dispatch runs the same way as abt dispatch. Flags, payloads and error codes are in the abt watch reference.

Quick start

A Slack message in #support triggers a workflow that reads the thread, triages it, and replies in the same thread. Six small files:

# triggers/support_slack.yaml
name: support_slack
description: A customer message in #support that needs triage
type: slack
credentials: slack
config:
  channel_ids: [C0MOCK00004]
  poll_interval_seconds: 5
  events: [message]
enabled: true
# sources/support_thread.yaml
name: support_thread
type: slack_thread
description: The Slack thread that triggered the run
credentials: slack
config:
  channel_id: "{{ var('channel_id', '') }}"
  thread_ts: "{{ var('thread_ts', '') }}"
# exposures/triage_writeback.yaml
name: triage_writeback
type: slack
credentials: slack
config:
  channel_id: "{{ var('channel_id', '') }}"
  thread_ts: "{{ var('thread_ts', '') }}"
  require_thread_ts: true   # fail instead of posting an unthreaded message
# workflows/triage_request.yaml
description: Entrypoint — triages an incoming Slack support message
trigger:
  support_slack:
    vars:
      channel_id: "{{ event.scope_id }}"
      thread_ts: "{{ event.thread_id }}"
steps: [support_thread, triage_task, triage-request, triage_writeback]

Save this as prompts/triage_task.md:

Read the Slack message and decide how to route this support request.

{{ upstream('support_thread') }}

Save this as agents/triage-request.md:

---
description: Triages an incoming Slack support message
---
You route incoming support requests. Reply with the routing decision only.

The var() defaults let the project compile before any event exists. The trigger's vars: binding fills them from each event at dispatch time. Check the wiring without Slack credentials:

abt compile
abt watch list        # shows support_slack → triage_request and its vars binding

Starting the watcher needs a slack entry under credentials: in profiles.yaml.

No Slack workspace? A type: cron trigger works the same way with no source or exposure. See Cron. The full triggers/*.yaml shape and the trigger: binding syntax are in Triggers.

Run the watcher

abt watch run --all

abt watch run starts one event source for each enabled trigger and dispatches matching events. It recompiles the project every --reconcile-interval (default 60 seconds), so new and changed agents and workflows take effect without a restart. A reconcile whose compile fails, for example on an invalid agent file, leaves the running sources as they are, reports degraded in the log and last_error in the status payload, and retries on the next interval. Select workflows by name, with --all, or with --tags. Running with no selection exits with code 2.

Set --cooldown (default 30 seconds) to at least the run_timeout of the entrypoint node. The cooldown drops duplicate events for the same workflow and thread. A redelivered event that arrives after the cooldown expires, but before the first dispatch finishes, runs the whole workflow again.

On SIGTERM the runner waits up to --shutdown-timeout (default 30 seconds) for in-flight dispatches, then abandons the rest. On Kubernetes, set terminationGracePeriodSeconds above it. See Deploying to Kubernetes.

Guardrails for unattended runs

Nobody watches a triggered run, and abt applies no run limit that a project did not declare. A project with no run_timeout, model_call_limit or token_budget entry lets one stuck or looping run hold a --max-concurrent slot and spend tokens until someone notices. abt init writes all three into abt.yaml; a project written by hand needs them added:

config:
  middleware:
    - run_timeout:
        graceful_timeout_seconds: 600
        hard_timeout_seconds: 680
    - model_call_limit:
        max_model_calls: 300
    - token_budget:
        max_total_tokens: 2500000
  • Check what an agent will run with: abt config show --agent <name>. A limit that shows None is not set. abt doctor flags agents that have tools and no limit (missing_guardrails).
  • Keep --cooldown at least as long as the run_timeout, and --reclaim-idle-seconds above 60 seconds. See Run the watcher and the queue.
  • Set --shutdown-timeout above the hard_timeout_seconds, or a deploy abandons runs that were about to finish.
  • Alert on the dlq_depth field of the health payload.

Checkpointing triggered runs

Every event in one conversation runs on one thread, named {source_type}:{scope_id}:{thread_id}. With a persistent checkpoint backend (set in abt.yaml or with ABT_CHECKPOINT_BACKEND), a second event on that thread resumes the conversation. The default memory backend keeps nothing after a run ends. An event without a thread, such as a cron tick, runs with --ephemeral.

Events that resolve to the same thread run one at a time, so they never write the same checkpoint concurrently. Events on different threads run in parallel, up to --max-concurrent. A Slack reply to a thread whose run is in flight is the exception: the run reads it at its next model call (steering).

Slack reactions resolve to their thread root, so a reaction on a bot reply resumes the thread it belongs to. The lookup is best-effort: if it fails, the reaction still dispatches, keyed to the reacted message. A Slack: could not resolve the thread root warning means a Slack history scope is missing. See Slack integration.

abt watch produce / abt watch consume — distributed split

abt watch produce runs the event sources and publishes dispatch requests to a Redis Streams queue. It never dispatches a workflow itself. abt watch consume processes read the queue and run each request through abt dispatch. Consumers compete for jobs, so you can run as many identical copies as you need.

Both commands need the queue extra: uv pip install "abt-core[queue]". Pass the queue URL with --queue (for example redis://host:6379) or with ABT_WATCH_QUEUE.

Produce elects a leader, so replicas: N is safe for the trigger plane: one replica runs the sources and the others stand by. See Deploying to Kubernetes for replica patterns.

Consume acks each job when it reads it, so a worker that dies mid-run loses the job. Add --acks-late to ack after the run finishes instead. The queue then redelivers unfinished jobs to another worker. Set --acks-late the same way on every consume replica that shares a queue. Two sizing rules apply:

  • --reclaim-idle-seconds (default 300) is how long a worker may go silent before another one takes its job. A live worker refreshes the claim on every job it is running, once per third of that window, so a run can outlast it without being redelivered or dead-lettered. A crashed worker's job waits one window. Keep it above 60 seconds.
  • --completed-ttl-seconds (default 600) must exceed --reclaim-idle-seconds. Otherwise a redelivered duplicate can run again.

Consume prunes target/run_results/ by default (--prune-run-results), which keeps disk use bounded on a long-lived worker. Retention flags are in the reference.

Embedding the worker in your own entrypoint with the SDK? Pass a RunRetentionPolicy to prune run directories:

import asyncio

from abt.sdk.watch import RunRetentionPolicy, worker

asyncio.run(
    worker(
        "/workspace/repo",  # queue URL comes from ABT_WATCH_QUEUE
        run_retention=RunRetentionPolicy(
            keep=20,
            older_than_days=1.0,
            max_total_bytes=512 * 1024 * 1024,
        ),
    )
)

For querying retention metrics in Datadog, see Deploying to Kubernetes.

Agent invoke API (consume --serve-api)

Experimental — endpoint shapes and response fields may still change in a minor release.

abt watch consume --serve-api lets other services run an access: public agent over HTTP. It is the producer side of loom's mode: remote. Each request is queued in Redis, and any worker runs it. A POST through one replica and a GET through another return the same result. It needs the queue and serve extras: uv pip install "abt-core[queue,serve]".

export ABT_INVOKE_TOKEN=$(cat /run/secrets/invoke-token)
abt watch consume --queue redis://redis:6379 --serve-api --health-port 8080

Submit a run, then poll it until status is succeeded, failed or cancelled. Treat any other status as a failed run.

T=$ABT_INVOKE_TOKEN
curl -sX POST localhost:8080/api/agents/investigator/invoke \
  -H "Authorization: Bearer $T" -H 'Content-Type: application/json' -d '{"input":"orders_daily 6h stale"}'
# {"run_id":"ab12…","status_url":"/api/agents/investigator/runs/ab12…"}

curl -s localhost:8080/api/agents/investigator/runs/ab12… -H "Authorization: Bearer $T"
# {"status":"succeeded","output":"…","tokens_in":59,"tokens_out":89,…}

The endpoints, response fields and error codes are in the reference.

  • Auth. Every request sends Authorization: Bearer $ABT_INVOKE_TOKEN. The worker refuses to start without the token unless you pass --insecure-no-invoke-auth. Expose the port through a ClusterIP Service only, because the token travels in clear text over HTTP.
  • Input. input is one agent's literal message, as with abt run -p. The API runs the agent alone, so send the text a workflow source would fetch, or let the agent fetch it. A {{ source(...) }} or {{ upstream(...) }} reference in input returns 400.
  • Template variables. vars sets the var() values that the agent's prompt body references. Values land in the system prompt, so treat what callers send as untrusted when you write the prompt.
  • Retries. Resend the same idempotency_key with the same body to get the existing run_id back. Reusing the key with a different body returns 422.
  • Gates. Tools marked confirmation_required have no human to ask. They follow the agent's on_missing_gate policy, which defaults to deny: the call returns an error to the model and the tool does not run. Set on_missing_gate: approve only for tools that are safe to run unattended, or raise to abort the run.

Run --serve-api workers with --acks-late, and upgrade every worker before you enable --serve-api or send vars. The manifest and rollout order are in Deploying to Kubernetes. Redis sizing and the run time limit are in the reference.

Cancelling a run

A caller that times out or retries should cancel the run it abandons. Otherwise the run keeps spending tokens until it finishes or hits --invoke-max-run-seconds.

curl -sX POST localhost:8080/api/agents/investigator/runs/ab12…/cancel -H "Authorization: Bearer $T"

A 200 means the run is cancelled, or was already in a final state. A 202 means a worker is stopping it, so poll until status is cancelled. Cancellation is cooperative: tokens already spent still count, and a run that records its result before the worker sees the cancel stays succeeded. The loom remote tool sends a cancel when it gives up on a delegated run. The response for each run state is in the reference.

Kubernetes deployment

One pod running abt watch run --all needs no extra setup. The Deployment manifests for the standalone and split modes, shutdown settings and sizing are in Deploying to Kubernetes.

Health probes

--health-port serves a JSON health payload on /health: 200 while the process runs, and 503 once it has stopped or its runner has crashed. A failed publish keeps 200 and sets healthy to false in the payload. Use it for the liveness probe. On run, it answers 200 before the first reconcile starts any source, so check the sources count for readiness. The probes, the 503 conditions and every payload field for run, produce and consume are in Deploying to Kubernetes.

Trigger types

Each triggers/*.yaml declares type:, credentials: and config:. The workflow's trigger: adds the vars: binding. Types are cron, slack, github and jira, or a custom provider. The per-type keys and the {{ event.* }} fields are in Triggers.

Progress UX ("agent is working" indicator)

Set progress and progress_reaction in a slack trigger's config:. See Triggers. progress: true shows Slack's native thread status, which needs only the chat:write scope that every Slack trigger has. progress_reaction: <emoji-name> adds the emoji to the triggering message and needs reactions:write. Both clear automatically when the workflow finishes, under abt watch run and under produce/consume. A manual abt dispatch has no triggering event, so it shows no indicator.

Under produce and consume:

  • Upgrade consume before you enable these settings for produce. An older consumer ignores the description, so the indicator stays set.
  • Each consume replica clears the indicator with the trigger's bot token. It reads the credentials: namespace from its profiles.yaml and falls back to SLACK_BOT_TOKEN. Each replica also needs the slack extra: uv pip install "abt-core[queue,slack]". Without that extra, the run completes, the indicator stays set, and the consumer logs a warning.
  • A worker that crashes mid-run leaves the indicator set. With --acks-late, the redelivered run clears it.

Timing and per-thread details are in the reference.

Artifact upload with handlers

The entrypoint agent's on_success: and on_failure: hooks can run the built-in UploadArtifacts handler after each triggered dispatch. Keying the artifacts by source identity (Slack channel and thread) keeps them available after a pod restart.

In the frontmatter of agents/triage-request.md, add:

on_success:
  - UploadArtifacts:
      type: s3
      bucket: <your-bucket>
      key: "{project}/{agent}/{source_key}/{timestamp}"
      include: [run_results.json, dag_summary.json]
on_failure:
  - UploadArtifacts:
      type: s3
      bucket: <your-bucket>
      key: "{project}/{agent}/failures/{run_id}"

See Handlers for the full UploadArtifacts reference.