# Connect an agent to CreationLoop

Version **2.2.0** of these instructions, for CreationLoop run reporting, version 1.
Any agent connects this one way. Nothing here asks or depends on what the agent is built with.

## How connecting works
The person does three things, one at a time.
- Open https://creationloop.ai/connect/setup, sign in, and press "Make a key".
- Press "Turn on Live".
- Press "Approve and publish".

The person's part of the key is one thing: they press "Make a key" and say it is done.
Their browser then saves the key file, `creationloop-key-….env`, in their download folder. Whoever sets up the agent moves that file into the agent's folder, which git ignores, and the agent reads `CREATIONLOOP_KEY` from it.
Nobody copies, types, pastes or exports the key, and nothing goes in a shell profile. The one exception, a browser that saves no key file, has its own heading below.
If the person is asked to copy, save or export a key, the answer is that the key file is in their download folder. Moving it is the setup's part.

Whoever sets up the agent, the person's assistant or a developer, also does the rest.
- Adds the four calls to the agent's own code.
- Sends one Test run, then the agent's real jobs.

There is no phase and no gate to choose. The setup page starts in Test with one gate, and the person turns on Live with one press.
The exact method is this page, at https://creationloop.ai/connect.md.

## The whole method, in seven lines
Each of the seven lines below is needed, so keep every one of them.
1. The key. The owner makes it at https://creationloop.ai/connect/setup with "Make a key", and their browser saves the key file in their download folder. Whoever sets up the agent moves that file into the agent's folder, which git ignores, and the agent reads `CREATIONLOOP_KEY` from it. Nobody copies, types, pastes or exports the key, except when a browser saves no key file, the one exception the method names. It starts with `clk_` and reports for one agent and one saved set of gates. It works from the first call: its reports are Test reports until the owner turns on Live, and Live reports after. Never put it in a prompt, a chat, a repository, a log or an address.
2. Two ways in, with the same fields and answers. One: `POST https://events.creationloop.ai/v1/runs/<call>` with the headers `Authorization: Bearer <key>` and `Content-Type: application/json`, where `<call>` is `describe`, `start`, `gate` or `end`. Two: the tool server `https://creationloop.ai/claim/mcp/report`, signed in with the same `Authorization` header or by `OAuth`, with the tools `report_describe`, `report_run_start`, `report_gate` and `report_run_end`.
3. Describe first. Before the first job, send `describe` with the body `{}`. It answers the `phase` and the `gates` the setup page saved, each with `id`, `name` and `required`. It records nothing.
4. The run ID. Make a new random `runId` for every job, 1 to 128 characters from `A-Z a-z 0-9 . _ : -`. Send it on every call and every resend of that job. Never use one twice: not for another job, not across Test and Live, not after the owner saves new gates.
5. Three reports for each job. `start` takes `runId` and one of `inputSha256` or `inputText`. `gate` takes `runId` and `gateId`, only for a gate the job really reached. `end` takes `runId`, `status` (`delivered` or `failed`) and, when delivered, one of `outputSha256`, `outputText` or `"outputNotFingerprinted": true`. A fingerprint is the SHA-256 of the exact bytes, as 64 lower case hex characters, made with a tool and never guessed. Optional fields: `agentVersion` on `start`, `artifactSha256` or `artifactText` on `gate`, `knownCostCents` on `end`.
6. Order and resends. Send the calls of one run one at a time, in order, each after the one before was answered. Wait up to 30 seconds for an answer. With no answer, or a 429 or a 503, send the exact same body again, after the seconds in `Retry-After` if given, else after 2, then 4, then 8 seconds. Make at most 4 tries in all. Never resend after any other 4xx.
7. Reporting never stops or changes the job. If a report still fails after those tries, go on with the work.

These seven lines are the whole method. If you read a summary, check it holds all seven. For the exact text: curl -s https://creationloop.ai/connect.md

## What this is

The agent tells CreationLoop three things about each job: it started, it reached a gate the owner chose, and it ended.
CreationLoop records each report, seals it and links it to the one before.
The owner approves a result, and publishes it to a public Trust Card, with their own passkey.
No report from an agent counts as the approval of the owner.

## How the setup is done

Whoever sets up the agent works in the agent's own folder. The person's request, such as "connect this agent", is their yes to the change.
The person presses three buttons, one at a time, each asked for in a message of its own.
Everything else is the setup's own work, and the person can see all of it on the setup page and in the agent's folder.
Each message to the person is in plain words, with no code and no command or file for them to run or edit.
Connecting means the agent itself reports every later job, with no new act by anyone. A script run around the agent does not connect it.

Some apps that run a setup stop a command it needs, such as one that uses the network, the download folder or the clipboard.
Then that app's own prompt allows the one command, and the person is told in one plain line why the prompt appears.
Nobody is asked to paste or type a command. That prompt is not one of the three asks.
The limit is that app's, not the agent's. The agent's normal run uses the network the agent already has.

The setup goes in this order.

1. The place for the calls: where the agent, or whatever runs it, can send an HTTPS POST with a header or use a tool server. The person is asked where only if there is none, and nothing about how the agent was built.
2. The calls of the seven lines go there, in the agent's own code, in the working folder only. Each call logs its answer code, never the key. The agent reads the key from the setting `CREATIONLOOP_KEY`, loaded from the key file once that file is in the agent's folder. If the repository does not ignore that file, it goes in the ignore file. Fingerprints are sent, not text. The result of the product stays as it is.
3. The jobs: a sample job for the Test run, and a real job for the first Live run, both from the working folder. If there is no sample, a short one is made up for the Test run. The real job is never made up. The check in part 12 needs a second real job; if there is only one, it runs again.
4. A real job is one the agent finishes by itself, that sends nothing to anyone and that changes nothing outside the folder. A job that needs the person's approval or answer is not used for these runs.
5. Nothing is committed, pushed or deployed. The person is told in at most three plain lines what was added, and that they can say "undo" to take it out.
6. In the same message, the first ask: open https://creationloop.ai/connect/setup, sign in, press "Make a key", and say "done".
7. After "done", the key file moves into the agent's folder, as the next part says.
8. `describe` with the key checks the change, and it records nothing. The gate IDs it answers go into the change, at the point of the work that reaches each gate. The setup page sets the gates. If a required gate fits nothing the job does, the person is told so in one line.
9. The sample job runs one time, the way the agent always runs, with the key. Its reports are Test reports, because Live is not on yet. That is the Test run. It is tagged Demo data and is never published.
10. The person is told in one line that the Test run was sent. In the same message, the second ask: on the page still open, press "Turn on Live", and say "done". The link is not sent again.
11. After "done", `describe` runs again, then the real job runs one time, the way the agent always runs, with the same key. The person is told which job it was. That is the first Live run.
12. The check that the agent stays connected. The calls are in the agent's own code, or in its tool server setting. The key is in the agent's own folder. A second real job, run the way the agent always runs, shows from the answer codes it logs that each report was recorded.
13. The third and last ask: open https://creationloop.ai/connect/setup, press "Approve and publish", and use the passkey. The Trust Card is then public, and the page shows its address.
14. After the third ask, the setup is done. If the person says something did not work, they are told in one line that the setup page shows what is left.

Two things can add an ask, each in a message of its own. They are no place for the calls, and no real job that meets part 4. Then the person is asked where the agent can make a call, or for a real job.

A first message to the person can read like this.
> I added reporting to your agent, beside its work. It sends CreationLoop a short report when a job starts, at each gate, and when it ends. Say "undo" and I take it out.
> Now open https://creationloop.ai/connect/setup, sign in, press "Make a key", and tell me "done". I take care of the key from there.

### The key

When the person presses "Make a key", their own browser saves the key file in their download folder.
The key file is as secret as the key.
After "done", the key file is found by its name and moves into the agent's folder.

- The key file is the newest file in the person's download folder named `creationloop-key-`, then 8 characters from `0-9 a-f`, then `.env`. The download folder is usually the folder named Downloads in their home folder.
- Only names of that form are looked at: no other name in the folder is printed, and no other file there is opened. The key file holds one line, `CREATIONLOOP_KEY=<key>`.
- The key file itself moves into the agent's folder, and the repository ignores it. The agent's code loads `CREATIONLOOP_KEY` from that file.
- Moving the key file takes it out of the download folder. It is the one file outside the working folder that the setup changes. If it cannot be moved, it is copied, and the person is told in one line that they can delete the download.
- The key reaches the agent's folder even if the download cannot be moved or deleted.
- Each command that moves or writes the key holds none of it in its text, and prints nothing of it. It checks the form of what it read, with spaces and line breaks at the ends taken away.
- The form is `clk_` and then 43 characters from `A-Z a-z 0-9 _ -`, 47 characters in all. Only the form is checked. If what was read holds anything else, nothing is written or shown.
- The key works from the first call. Its reports are Test reports until the person turns on Live, and Live reports after.
- Nothing in the setup makes a Test key. Records and the tool server make it from the key, as the reference says.
- The agent reads the key only from the file in its own folder, never from the download folder or the clipboard.
- An agent that uses the tool server gets the key the same way, one time, in the header field of its settings. Those settings are in a file the repository ignores. It never changes after: the tool server uses the Test key by itself until "Turn on Live".

### The one exception: a browser that saves no key file

Nobody copies, types, pastes or exports the key, except in this case. The setup page also shows the key one time, with a button to copy it.
- If the browser saved no key file, the setup page asks the person to press "Copy". The key is then read from the clipboard, where the shell can read it, and the clipboard is cleared after, where the system allows it.
- Each system has its own way to read the clipboard, for example `pbpaste` on a Mac, `Get-Clipboard` on Windows, and `wl-paste` or `xclip` on Linux.
- A command that prints nothing writes the line `CREATIONLOOP_KEY=<key>` into a secret settings file in the agent's folder that the repository ignores.
- Only if the clipboard cannot be read either, that secret settings file is opened for the person in an editor, with the line `CREATIONLOOP_KEY=` ready. They paste the key after it and save. This is the one time they need a file.

### Limits

- The key is never asked for, and never read back, printed or logged. It moves only as the part above says.
- No setup script is downloaded or run, and no package from CreationLoop is installed. Nothing here needs one.
- No production branch is pushed or deployed.
- The result of the product stays as it is. Reporting is added beside the work and never changes it.

## The answers

- 201 means the report is recorded. The answer holds `runId`, `receiptId`, `messageId`, `recordedAt` and `next`.
- 200 means the same body was recorded before. The answer is the first answer again.
- 400 means a field is wrong, and the answer names it. Fix it. Do not resend the same body.
- 401 means the key is missing or not known. Stop reporting and tell the owner in one line. Ask them nothing about the key.
- 403 means the key is stopped or expired, or it does not fit the phase, the gates or the run. Stop reporting and tell the owner in one line.
- 409 means the run ID holds other content, or the run has not started, or the run has ended.
- 413 means the body is too large. Send a fingerprint in place of text.
- 429 and 503 mean too many reports, or busy. Wait, then send the same body again.

The reference lists each answer code and what to do after it.

## The same calls as tools

An agent that takes a tool server needs no code. Add the server below one time, with the key the person copied in its header field.
`https://creationloop.ai/claim/mcp/report`

That one add serves Test and Live. Before "Turn on Live", the tool server reports with the Test key it makes from that key, and after it with the key itself.
Never add the server a second time, and never put in a second key.
A run started before "Turn on Live" cannot end after it. Start a new run with a new run ID, as the tool's answer says.
For such an agent, the first job before "Turn on Live" is its Test run, and the next job is its first Live run.
Every later job reports the same way, with nothing more to do.

A tool client that cannot set a header signs in by `OAuth`. The owner then picks the workspace, the gate version and the phase, and approves with a passkey.
On that way one connection serves one phase, so such a client connects once for Test and once for Live. One connection for both phases comes in a later version.

The four tools take the same fields as the four calls and give the same answers. No tool takes the key as an argument.
The tool server sends a call again by itself when the reporting service gives no answer, for up to 45 seconds.
So the agent sends a tool call again only when the tool answers with the code below, and then with exactly the same arguments.
`reporting_unavailable`

### Only for an agent that takes tools and has no code of its own

Such an agent carries six lines in its own instructions, and the setup adds them there. An agent with code of its own needs none of them.
Add the next six lines to the instructions of the agent, word for word.
```text
Report each job with the CreationLoop tools. Call report_describe one time before the first job.
For each job, make one new random run ID and send it with every tool call of that job.
Call report_run_start before the work. Call report_gate at each gate the job really reaches.
Call report_run_end when the job is done or has failed. Report the jobs you are given, and ask for none.
If a reporting tool fails, say so in one line and go on with the job. Reporting never changes your result.
Never ask the person to change the tool server, its key or its settings, or to look at the setup page.
```

## Check that it works

1. `describe` answers with the key from the first call, with the phase `test` before "Turn on Live" and `live` after. It records nothing.
2. The Test run shows on the setup page with each report that arrived, tagged **Demo data**. It is never published.
3. The setup check passes when the run has reported its start, each required gate and its end. The person can press "Turn on Live" after that.
4. The first Live run is a real job of the agent. It shows on the setup page with each report that arrived.
5. The setup page shows the person what arrived, so they do not need to trust what anyone says. Nobody asks them to check it.
6. Nothing is public until the person presses "Approve and publish" and uses their passkey.
7. A second real job, run the way the agent always runs, is recorded too. So every later job reports with nothing more to do.

## Stop a key, and remove the connection

The owner can stop any key, or all keys of an agent, on the setup page with a passkey.
CreationLoop then refuses each new report made with that key, with the status 403.
Receipts that were recorded before are not changed.

1. Remove the tool server or the calls.
2. The key file comes out of the agent's folder, by a command that prints nothing of it.
3. The person is told they can stop the key on the setup page.

If the person asks to undo the change, all three are done.

## Kinds of agent this method cannot serve

1. An agent with no way to reach the internet, whose host has none either. Only a person could forward its reports for each run.
2. An agent that can only fetch a page for reading. A page fetch never writes.
3. A tool client that accepts only tool servers with no sign in. A key in an address or in the arguments of a model is refused.
4. An agent behind a network that blocks the two CreationLoop hosts, until its administrator allows them.
5. An agent that lives only in a browser and cannot hold a secret. A person would have to type the key for every run.

Served at a weaker level, which the receipt says: an agent whose output is a file it cannot fingerprint. No file is tied to that run.

## More, for the one who builds it

- The reference (https://creationloop.ai/connect/reference.md) has every field, every answer and a worked example of each call and each tool.
- A description of the four calls (https://creationloop.ai/connect/openapi.json) is in plain `OpenAPI`, for tools that build actions from a description.
- The signed format (https://creationloop.ai/connect/signed.md) is the optional stronger level, for an owner whose systems can make Ed25519 signatures.
- The security page (https://creationloop.ai/security) says what CreationLoop keeps and what it does not check.

## Versions

This page is version 2.2.0. Its permanent copy and the checksums of this version are at the two addresses below.
- `https://creationloop.ai/connect/v2.2.0/connect.md`
- `https://creationloop.ai/connect/v2.2.0/SHA256SUMS`

Version 2.1.0 changes what an assistant does for the person, and adds the rule that makes the Test key from the key the person copies. The seven lines and the calls are the same as in version 2.0.0.
Version 2.2.0 opens with how connecting works and describes the setup as a method for whoever does it. It says that the person's browser saves the key in a key file, and asks for no Copy.
Versions 2.1.0, 2.0.0 and 1.0.0 stay at their own addresses, unchanged, for the setups that use them.
Version 1.0.0 says that a reporting key is revoked in a dashboard. That is wrong. The owner stops a key on the setup page, at https://creationloop.ai/connect/setup.
