---
title: Getting started with agents
description: Set up a new or existing dltHub workspace for background agents and declare the job inspector agent with your coding agent
keywords: [dlthub, background agents, job inspector, ai harness, dlthub-platform, design partners, getting started]
---
# Getting started with agents

:::info
Background agents are in public preview.
:::

[Background agents](https://dlthub.com/products/background-agents) are dltHub jobs that run an AI agent loop. They run unattended, for example after another job fails, and report a structured result next to the job run they acted on.

The agents ship with the [dltHub AI Harness](../ai-harness/introduction.md). The [`dlthub-platform`](../ai-harness/toolkits.md#dlthub-platform) toolkit includes `job-inspector`, a verified agent that diagnoses failed job runs.

## Prerequisites

- [uv](https://docs.astral.sh/uv/) and Python 3.12 to 3.14.
- A coding agent: Claude Code, Cursor, or Codex.
- The model name, endpoint URL, and API key for your agents.

## Set up with your coding agent

Open your coding agent in your dltHub workspace, or in an empty directory to start from scratch, and paste this prompt:

```text
Set up this directory for dltHub background agents. Use `uv run` and pass
`--non-interactive` to `dlthub` commands.

1. If there is no `.dlt/.workspace` file, run `uvx dlthub-init@latest`. If it lists
   changes to my existing files, show them to me and run it again with `-y` once I agree.
2. Add these dependencies to pyproject.toml and run `uv sync`:
   "dlt[hub]==1.31.0", "dlthub[mcp]", "dlthub-client>=0.28.7",
   "pydantic-ai-slim[anthropic,openai,google,mcp,spec]>=2.45.0", "aiohttp>=3.14.3"
3. Run `uv run dlthub ai toolkit install dlthub-platform --overwrite`, then
   `uv run dlthub ai status`, and fix any warnings.
4. Declare the `job-inspector` agent in `__deployment__.py`.
   Trigger `job-inspector` on the jobs I choose, never the default `job.fail:*`.
   Ask me which jobs to watch, or which pipeline to build first if there are none.

5. Ask me whether I keep the model key in `.dlt/secrets.toml` or in workspace
   variables. For the file, add an `[agent]` section to `.dlt/secrets.toml` with
   the placeholder `api_key = "<paste-your-api-key-here>"`. I'll set the key
   myself either way. Never ask for it, put it in a command or an environment
   variable, or read it back.
```

## Set the model credentials

Set the model and its key in the settings files of the workspace, or as workspace variables. Pick one: a key in both places makes local runs and deployed runs use different keys.

### In the settings files

The model and its key are configuration, like the credentials of a pipeline. The `[agent]` section applies to every agent job in the workspace. Add the model and the endpoint URL to `.dlt/config.toml`:

```toml
[agent]
model = "azure:gpt-5.6-sol"
api_url = "<endpoint URL>"
api_version = "2024-12-01-preview"  # Azure endpoints only
```

Open `.dlt/secrets.toml` yourself and paste the API key over the placeholder that your coding agent wrote:

```toml
[agent]
api_key = "<your API key>"
```

`.dlt/secrets.toml` is gitignored. It applies to every profile, and `dlthub deploy` ships it with the workspace, so local runs and deployed runs read the same key.

### As workspace variables

Workspace variables live in the workspace deployment, so you set them once from any terminal, without a settings file. Set the model as a plain variable and the key as a secret one. Without `--value`, `variable set` asks for the key, so it stays out of your shell history:

```sh
uv run dlthub login
uv run dlthub variable set AGENT__MODEL --value "azure:gpt-5.6-sol" --plain --workspace
uv run dlthub variable set AGENT__API_URL --value "<endpoint URL>" --plain --workspace
uv run dlthub variable set AGENT__API_VERSION --value "2024-12-01-preview" --plain --workspace   # Azure only
uv run dlthub variable set AGENT__API_KEY --secret --workspace
```

If your workspace is not connected to dltHub yet, run `uv run dlthub workspace connect` before `variable set`. Variables reach deployed runs and override the settings files there. A local run gets the plain variables but not the secret one: for local runs, export the key in your own terminal with `export AGENT__API_KEY=<your API key>`.

See [Model and credentials](../agents/agent-definitions.md#model-and-credentials) for one job's own model.

## Deploy and run

`job-inspector` starts only when a job it watches fails. When the coding agent asks which jobs to watch, pick a job that can fail, for example one that calls an external API or reads credentials.

Deploy the workspace:

```cli
uv run dlthub deploy
```

Then run the watched job, from the CLI:

```cli
uv run dlthub run <job-name>
```

Or from the Web UI: open the **Jobs** page at [app.dlthub.com](https://app.dlthub.com), select the job, and start a run.

If the run fails, `job-inspector` starts on its own. To read its diagnosis, open the inspector run:

- From the **failed run's page** in the Web UI, which links to the inspector run.
- From the **Agents** tab, which lists all agents in your workspace and their runs.

## Customize the job inspector

Override the inspector's defaults in `__deployment__.py`, for example its model, turn limit, or extra instructions:

```py notype
job_inspector = run.agent(
    "dlthub-platform:job-inspector",
    trigger=[my_job.fail],
    limits={"max_turns": 20},
    instructions="focus on the loader step",
)
```

The same call can also replace the access, tools, skills, and rules of the inspector, for example to let it read your data. See [Customize an existing agent](../agents/index.md#customize-an-existing-agent).

## Build your own agent

Write your own agent as an `AGENT.md` file or as a Python function with the `@run.agent` decorator. [Background agents](../agents/index.md) goes further, one task at a time: validation with `agent.py`, unit tests, `access`, skills and rules, structured input and output, platform entities, and the budget of a run.

The examples below define `workspace_report`, an agent that reads the status of every job in the workspace and writes a report.

In an `AGENT.md`, the YAML frontmatter declares the tools, access, and output, and the Markdown body is the system prompt:

```md
---
description: Reports the latest status of every job in the workspace. Read-only.
tools: [jobs]
access:
  context: [read]
output:
  type: object
  properties:
    jobs_total: { type: integer }
    failed_jobs: { type: array, items: { type: string } }
---
List every job in the workspace and read the status of its latest run. Report
how many jobs there are and which ones failed. In `summary`, write a Markdown
table with one row per job: name, last run status, and when it ran.
```

Save it as `agents/workspace_report/AGENT.md` and declare it in `__deployment__.py` by its folder:

```py notype
from dlt.hub import run
from dlt.hub.run import trigger

__all__ = [
    # ...,
    "workspace_report",
]

workspace_report = run.agent("agents/workspace_report", name="workspace_report")
```

In a Python function, the docstring is the system prompt, the parameters are the inputs, and the return type is the output schema:

```py notype
from typing import List

from dlt.hub import run
from dlt.hub.run import trigger


class WorkspaceReport(run.TAgentOutput):
    jobs_total: int
    failed_jobs: List[str]


@run.agent(
    tools=["jobs"],
    access={"context": ["read"]},
)
async def workspace_report(run_context: run.TJobRunContext = None) -> WorkspaceReport:
    """List every job in the workspace and read the status of its latest run.

    Report how many jobs there are and which ones failed. In `summary`, write a
    Markdown table with one row per job: name, last run status, and when it ran.
    """
    return await run_context["ai_loop"].run()
```
