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 thatuser_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. Setapproval_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.
Immediate human approval
approval_mode: "human" uses the user_email and navigator associated with the task to route approvals:
- The worker reaches a tool configured as User Approval, persists the pending action, changes the task to
AWAITING_APPROVAL, and releases its worker lease. - A chat widget initialized for the same navigator and
user_emailshows a notification and an item under Background Tasks. - 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.
- After the user submits decisions, Caylex requeues the task, executes only approved actions, records rejected actions as tool results, and continues the workflow.
- 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.
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:
- 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.
- 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. - The task changes to
AWAITING_REVIEWand releases its worker lease.GET /agent-task/{task_id}includes apending_reviewobject. - 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.
- 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.
- 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.
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:decisions to leave it pending for a later review.
Skills
To point the agent at a specific skill, pass its name or slug asskill_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
- Python
- TypeScript
agent_task.py