Skip to main content
The chat widget runs the Caylex agent interactively. Background agent tasks let your backend hand the same agent a long-running job to complete on its own, without keeping an HTTP connection open. You submit a prompt, get a task_id back immediately, and poll for the result when it’s done. This is ideal for work that takes longer than a request cycle: multi-step research, batch updates across connected tools, scheduled summaries, and similar autonomous jobs. Background tasks can also involve a human before running sensitive tools. A task can pause immediately on the first approval-gated action, or it can defer and batch gated actions while the agent continues independent work. The Caylex chat widget surfaces both workflows under Background Tasks.

Overview

A background task is launched server-to-server, authenticated exactly like agent session init (a platform access token). Caylex records the task, runs it on a dedicated background worker, and persists progress as it goes so the run is durable: if a worker is interrupted, the task resumes from the last completed step rather than starting over.
approval_mode: "human" is limited to tool approval decisions. approval_mode: "deferred_human" can also request written feedback or a decision on an important draft, schedule, document, or other work product.

How It Works

The run executes against the same project, tools, and per-user authentication as an interactive session for that user_email, so the agent can use every integration the user is connected to.

Submit a Task

Response

Poll for Status

Poll on an interval that suits your task length (for example, every few seconds). The report field contains the agent’s own summary of what it completed versus what it could not.

Tool Approval

Some tools require explicit user approval before they run—for example, tools that send a message, write data, or otherwise change external state. Set approval_mode according to the task’s trust model:
  • exclude (default) — approval-gated tools are excluded from the run. The agent completes what it can with the remaining tools and explains any limitation in its report.
  • human — approval-gated tools remain available, but the task pauses at the first gated action before execution. The matching end user can approve or reject the action from the chat widget.
  • deferred_human — gated actions are queued durably while the agent continues work that does not depend on their results. At a blocker or meaningful review point, the agent requests one consolidated human review containing its progress, the input it needs, and any queued tool approvals.
  • auto_approve — approval-gated tools execute without a user decision. Use this only when the task is explicitly authorized to perform those actions autonomously.
approval_mode: "auto_approve" lets the background agent execute state-changing tools—including sending, writing, and deleting—with no human in the loop.

Immediate human approval

approval_mode: "human" uses the user_email and navigator associated with the task to route approvals:
  1. The worker reaches a tool configured as User Approval, persists the pending action, changes the task to AWAITING_APPROVAL, and releases its worker lease.
  2. A chat widget initialized for the same navigator and user_email shows a notification and an item under Background Tasks.
  3. Opening the item shows the background task transcript and approval card. The message composer is disabled because this remains a background task, not an interactive conversation.
  4. After the user submits decisions, Caylex requeues the task, executes only approved actions, records rejected actions as tool results, and continues the workflow.
  5. If another approval is needed while the transcript is open, the next approval card appears inline. The user does not need to return to the Background Tasks list.
The task does not hold a worker or browser connection while it waits. An unanswered approval expires after seven days, is treated as rejected, and the task resumes so it can finish with an accurate report.
Immediate approvals are an interruption surface. Pending items disappear after a decision. If the user keeps the transcript open, it continues updating until the task finishes.

Deferred human review

approval_mode: "deferred_human" reduces repeated workflow interruptions and supports broader human feedback:
  1. When the agent calls an approval-gated tool, Caylex stores the action in PostgreSQL instead of executing it. Safe calls in the same workflow can continue.
  2. The agent may queue multiple gated actions. If it needs one result immediately, or reaches another blocker or quality checkpoint, it calls request_human_review.
  3. The task changes to AWAITING_REVIEW and releases its worker lease. GET /agent-task/{task_id} includes a pending_review object.
  4. Under Background Tasks, the matching user sees the agent’s progress summary, requested input, and queued tool approvals in one review card. The composer is enabled for optional written feedback.
  5. The user can approve or reject any subset of queued actions and submit feedback. Approved actions execute, rejected actions are finalized, and omitted actions remain queued.
  6. Caylex resumes the agent with the feedback and decision outcomes. The agent can revise its work, cancel obsolete queued actions, and request another review later.
Deferred tool approvals are durable for up to 30 days. They are not executed unless explicitly approved. If execution has an ambiguous outcome—for example, a timeout after dispatch—Caylex reports unknown_outcome and does not automatically replay the action.

Review through the API

Your backend can retrieve and submit the same review shown in the widget:
Submit at least one feedback message or approval decision:
Omit a queued approval from decisions to leave it pending for a later review.

Skills

To point the agent at a specific skill, pass its name or slug as skill_ref. The reference is validated against the project when you submit the task (you get a 404 if it doesn’t exist), and the agent is given a mandatory instruction to load that skill (by its resolved id) and follow it before doing any work. Omit skill_ref to let the agent discover and use skills on its own.

Example

agent_task.py