How do I run and schedule an AI agent that runs unattended in production?
Summary
- Run an agent unattended in one of three ways: as agent code in a job task, as a deployed agent that a job calls, or with the Genie Code task (Beta). Start the job with a schedule, a table update or a file arrival.
- Plan for failures nobody sees: task retries, task-level notifications, repair runs, and a service principal as the Run as identity.
- A repair re-runs failed tasks from the beginning, so use idempotent writes. A deployed agent treats the client-generated invocation ID as an idempotency key.
- Trace every run with MLflow Tracing, and scope what the agent's identity and tools can reach, because an unattended run has no one to approve actions.
How do I run and schedule an AI agent that runs unattended in production?
Make the agent callable without a person, start it with a Lakeflow Jobs trigger, and add the failure handling, identity and tracing that a person would otherwise supply. Lakeflow Jobs provides the triggers, retries, notifications and run history. The agent provides the work, and you decide what it may touch.
What does an unattended agent need?
- A trigger. A schedule, a table update, or a file arrival. A job can also run continuously.
- An identity. The job's Run as setting. Databricks recommends a service principal.
- Failure handling. Task retries, notifications and repair runs.
- Safe reruns. Idempotent writes and idempotent agent calls.
- A record of what happened. Run history and MLflow traces.
- Limits. The data and tools the identity can reach, because an unattended run has no one to approve actions.
Which Databricks options run an agent on a schedule?
| Option | How it runs | Watch for |
|---|---|---|
| Agent code in a notebook or Python script task | The agent loop runs inside the job | You configure the retries and write the idempotent code |
| Deployed agent called from a task | The Agent Bricks CLI (Beta) deploys the agent to Agent Runtime on Databricks Apps, and a task calls its invocation API | Callers need a Databricks OAuth token, because personal access tokens do not work for Databricks Apps |
| Genie Code task (Beta) | A natural-language prompt runs an autonomous agent as a job task | Auto-approval is always on and is not a security boundary |
For a deployed agent, a Python script task can call the invocation API at /api/invocations. The WorkspaceClient must use OAuth authentication. Set background to true to get a 202 response immediately and poll for the result.
import uuid
import requests
from databricks.sdk import WorkspaceClient
w = WorkspaceClient()
app_url = w.apps.get("agent-bricks-<name>").url
batch_id = "tickets-2026-10-09"
response = requests.post(
f"{app_url}/api/invocations",
headers=w.config.authenticate(),
json={
"id": str(uuid.uuid5(uuid.NAMESPACE_URL, batch_id)),
"session_id": batch_id,
"input": [{"role": "user", "content": "Classify the new tickets"}],
},
)
response.raise_for_status()
print(response.json()["output"])
How do I handle failures when nobody is watching?
Set a retry policy on the task that calls the agent, because the default depends on the job configuration. Serverless jobs auto-optimize retries by default, and you can turn that off for work that must run at most once.
Send notifications for start, success or failure to email addresses or to system destinations that an admin configures. Put them on the task, because job-level notifications are not sent when failed tasks are retried. A repair run then re-runs the unsuccessful tasks and their dependents.
A job allows one concurrent run by default, and Databricks skips a run when the job has reached its maximum number of active runs. Turn on queueing if a late run should wait, for up to 48 hours, instead of being skipped.
How do I keep reruns from duplicating work?
A repair re-runs each unsuccessful task from the beginning, and Lakeflow Jobs does not make tasks idempotent. Databricks advises idempotent operations, such as overwrite or merge instead of append, wherever duplicate data is a concern.
For a deployed agent, the invocation id is an idempotency key. Resending the same request with the same ID returns the existing invocation instead of running the agent again, so derive the ID from a stable batch key, as the example does. Reusing an ID for a different request returns a 409 error.
How do I see what the agent did?
MLflow Tracing records the inputs, outputs, latency, token usage and cost of every intermediate step, and projects created with the Agent Bricks CLI have tracing on by default. Each Genie Code task run produces a conversation that you can open and continue from the run output. The job run history and the system.lakeflow tables record runs and tasks across your account.
FAQs
Can I run several agents in parallel in one job?
Yes. Tasks that do not depend on each other run in parallel, and a For each task can loop one task over a list of inputs. Its concurrency setting defaults to 1.
Can the agent run when new data arrives instead of on a clock?
Yes. A table update trigger starts the job when source tables are updated, and a file arrival trigger starts it when new files arrive in a Unity Catalog volume or external location.
How do I limit what an unattended agent can reach?
Grant the Run as service principal only the access the agent needs. A deployed agent runs as the service principal of its app, which needs access to the resources its tools use. A Genie Code task runs with auto-approval on, so be deliberate about the production data and shared resources its prompt can reach.
The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.