> ## Documentation Index
> Fetch the complete documentation index at: https://docs.boxd.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Conversations

> Give an agent a task, send it more messages, and step in while it works.

You talk to an agent in a **session**: one conversation with one harness on one machine. You send it **messages**. Each message the agent works on is a **turn**: it takes the message, works, replies and stops.

`run` waits for the agent's reply, and `send` doesn't. That decides which one you use:

| You want to | Use |
| - | - |
| Do one task, and wait for the answer | `run` |
| Open a session for several messages | `start` |
| Send a message, and wait for the answer | `run` with `session` |
| Send a message, and not wait | `send` |
| Correct the agent while it works | `send` with `when: "now"` |
| Stop the agent | `interrupt` |

On the CLI, `send --watch` waits too.

In the examples, `agents` is `boxd.machines.agents`, as in the [overview](https://docs.boxd.sh/guides/agents).

> [!WARNING]
>
> An agent that boxd runs doesn't stop to ask for permission. It can do whatever the machine's user can. See [What the agent can do](https://docs.boxd.sh/guides/agents/sign-in.md#what-the-agent-can-do).

## One task

`run` does a whole task in one call. It starts a session, sends the task, waits until the agent is done, returns the reply, and closes the session.

```typescript TypeScript theme={"theme":"github-dark"}
const result = await agents.run("myapp", {
  harness: "claude-code",
  text: "Fix the failing test",
  cwd: "/home/boxd/app",   // where the agent works
  timeoutSecs: 600,        // stop it after 10 minutes
});

if (result.reason === "done") {
  console.log(result.reply);
} else {
  console.error(result.reason, result.error);
}
```

```python Python theme={"theme":"github-dark"}
result = agents.run(
    "myapp", "claude-code", "Fix the failing test",
    cwd="/home/boxd/app",   # where the agent works
    timeout_secs=600,       # stop it after 10 minutes
)

if result.reason == "done":
    print(result.reply)
else:
    print(result.reason, result.error)
```

```bash CLI theme={"theme":"github-dark"}
boxd agent run myapp claude-code "Fix the failing test" \
  --cwd /home/boxd/app --timeout 600
```

`reason` says how the turn ended:

| `reason` | Meaning |
| - | - |
| `done` | The agent finished normally. `reply` holds its answer. |
| `interrupted` | The turn was stopped, by you or by a restart of the machine. |
| `timeout` | The turn reached its time limit. |
| `max_steps` | The turn reached its step limit. |
| `failed` | The turn ended with an error. `error` says which. |

The CLI prints the reply to stdout and progress to stderr. It exits 0 when the turn ended `done`, and 1 otherwise.

If the agent leaves a long command running when it ends its turn, such as a build, `run` still returns and nothing is killed. The session closes by itself once the command is done.

## Several messages

For a conversation, start the session yourself. `run` with `session` then sends a message into it and waits for the reply. The session remembers what was said, so each message can build on the ones before it.

```typescript TypeScript theme={"theme":"github-dark"}
const session = await agents.start("myapp", { harness: "claude-code" });

const first = await agents.run("myapp", {
  harness: "claude-code",
  session: session.id,
  text: "Refactor the billing module",
});
console.log(first.reply);

const second = await agents.run("myapp", {
  harness: "claude-code",
  session: session.id,
  text: "Now update its tests",
});
console.log(second.reply);

await agents.close("myapp", session.id);
```

```python Python theme={"theme":"github-dark"}
session = agents.start("myapp", "claude-code")

first = agents.run(
    "myapp", "claude-code", "Refactor the billing module", session=session.id
)
print(first.reply)

second = agents.run(
    "myapp", "claude-code", "Now update its tests", session=session.id
)
print(second.reply)

agents.close("myapp", session.id)
```

```bash CLI theme={"theme":"github-dark"}
boxd agent start myapp claude-code
# prints the session's ID: put it in $SESSION

boxd agent send myapp $SESSION "Refactor the billing module" --watch
boxd agent send myapp $SESSION "Now update its tests" --watch

boxd agent close myapp $SESSION
```

[Sessions](https://docs.boxd.sh/guides/agents/sessions.md) covers a session's settings, its states and closing it.

## Send without waiting

`send` hands the agent a message and returns at once. The agent does the work in the machine, with or without you.

```typescript TypeScript theme={"theme":"github-dark"}
const sent = await agents.send("myapp", session.id, "Upgrade the dependencies");
console.log(sent.delivery, sent.turn);   // "started" 3
```

```python Python theme={"theme":"github-dark"}
sent = agents.send("myapp", session.id, "Upgrade the dependencies")
print(sent.delivery, sent.turn)   # started 3
```

```bash CLI theme={"theme":"github-dark"}
boxd agent send myapp $SESSION "Upgrade the dependencies"
```

To see the work, [follow the session's events](https://docs.boxd.sh/guides/agents/history.md#follow-a-session).

## Step in while the agent works

You don't have to wait until a turn is done. While it runs, you can correct the agent, line up more work, or stop it.

```typescript TypeScript theme={"theme":"github-dark"}
// Correct the agent now: the message joins the running turn.
await agents.send("myapp", session.id, "Skip the integration tests", {
  when: "now",
});

// Line up more work: the message waits, and becomes the next turn.
await agents.send("myapp", session.id, "Then update the README");

// Stop the running turn.
await agents.interrupt("myapp", session.id);
```

```python Python theme={"theme":"github-dark"}
# Correct the agent now: the message joins the running turn.
agents.send(
    "myapp", session.id, "Skip the integration tests", when="now"
)

# Line up more work: the message waits, and becomes the next turn.
agents.send("myapp", session.id, "Then update the README")

# Stop the running turn.
agents.interrupt("myapp", session.id)
```

```bash CLI theme={"theme":"github-dark"}
# Correct the agent now: the message joins the running turn.
boxd agent send myapp $SESSION "Skip the integration tests" --now

# Line up more work: the message waits, and becomes the next turn.
boxd agent send myapp $SESSION "Then update the README"

# Stop the running turn.
boxd agent interrupt myapp $SESSION
```

* **A message with `when: "now"`** is taken into account before the turn ends. Both Claude Code and Codex can do this. If no turn is running, it starts one.
* **A plain message** leaves the running turn alone. `send` returns a `delivery` that says what became of it: `started`, `queued` or `joined`.
* **An interrupt** ends the turn as `interrupted`. The session stays open, and a message that was waiting starts the next turn. An interrupt can also drop the waiting messages, or stop one turn by its number. See the [reference](https://docs.boxd.sh/guides/agents/reference.md#options).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.