# Agents

> What an agent is on Cere: a definition plus an image, harnesses, how a run drives one sandbox, and where its result, output and transcript are kept.

Source: https://docs.compute.dev.ddcdragon.com/concepts/agents/

An agent is a definition plus an image. A run is one sandbox that your client (the `cere` CLI, the Python SDK or the
Developer Console) creates and drives through six steps. The cluster knows nothing about agents: to it, a run is an
ordinary sandbox with labels.

## Definitions

A definition is a JSON document with the schema `cere.agent/v1`. It names the image and the harness, the model (its
base URL, model id and the secret that holds its key), the system prompt, tools and turn limit, the sandbox's
resources and timeout, its egress rules, and files to put in the sandbox. You keep it as a local file, or in your
bucket as `cere/agents/<name>.json`, which needs an S3 credential from Developer Console > Access tokens.

## Harnesses

| Harness | What runs |
| --- | --- |
| `claude-code` | Claude Code, in the agent runner image `cerebellumnetwork/ddc-agent-runner`, with the definition's system prompt, tools, policy (`read-only`, the default, or `read-write`), `deny` patterns and turn limit. |
| `container` | Your own image and the definition's `command`. The container reads `/workspace/input.txt` and `/workspace/agent.json` and writes `/workspace/output.json` (`output`, `turns`, `tool_calls`, `model_usage`, `error`). |

Either way the agent reaches its model through `ANTHROPIC_BASE_URL` with a placeholder key. The client adds a rule for
the model's host that names the model's secret, so the egress proxy adds the real key on the way out and the agent
never holds it.

## A run

The client:

1. creates a sandbox from the definition's image, resources and egress rules, plus the rule for the model's host,
   labelled `cere.kind=agent-run`, `cere.agent=<name>`, `cere.harness=<harness>` and `cere.run=<run id>`;
2. writes the definition, the definition's files and your input into `/workspace`;
3. runs the harness in the sandbox and streams what the agent does: its text, tool calls and their results, and any
   tool call its policy denied;
4. reads `/workspace/output.json`;
5. terminates the sandbox, keeping `output.json`, `output.md`, `transcript.jsonl`, `agent.json` and `input.txt`
   readable, with a reason that records the run's result;
6. with an S3 credential, also copies the output and the transcript to `cere/runs/<sandbox-id>/` in your bucket,
   before step 5.

Before step 1 the client checks that your bucket holds every secret the definition names, and stops with the
missing names and the command that stores each.

The run is billed like any sandbox, for what it reserves while it runs; its model calls through the inference API are
billed to the bucket of the model's key.

## Results

Each run's result is recorded on its sandbox, as its exit reason, so the CLI, the SDK and the Developer Console show
the same result for a run any of them started:

| Result | Meaning |
| --- | --- |
| `succeeded` | The agent finished without an error. |
| `failed` | The agent, the model, the harness or the time limit failed (the error is recorded), or the sandbox failed to start or ended under the run (`oom_killed`, `lost: ...`). |
| `stopped` | You stopped the run (Ctrl-C, or Stop in the Developer Console). |
| `running` | The run's sandbox is still running. |
| `ended` | The sandbox ended without its client recording a result, for example terminated from elsewhere. |
| `unknown` | The run's sandbox has status `unknown`, or its result can no longer be read. |

The retained output and transcript stay readable for 24 hours after the run, like any sandbox's retained files; with
an S3 credential, the copies in your bucket stay there.

## Limits of a client-side run

- A run lasts as long as its client drives it. If the client disconnects, the sandbox runs on until its timeout, and
  `cere agent runs` still lists it.
- There are no scheduled or unattended runs: something has to drive each run.

## Related

- [Next: Usage](https://docs.compute.dev.ddcdragon.com/concepts/usage/)
- [Guide: Agents](https://docs.compute.dev.ddcdragon.com/guides/agents/)
- [Quickstart: run an agent](https://docs.compute.dev.ddcdragon.com/quickstart/#run-an-agent)
- [Egress and credentials](https://docs.compute.dev.ddcdragon.com/concepts/egress-and-credentials/)
