Skip to main content
The model needs more than run_script: it must be able to check, test, follow and steer its runs. The SDK ships the tool definitions and their handlers, so your harness does not write them.
The runs the model starts belong to the client’s end user: take the agent tools from rewind.namespace(user.id), or from a client holding the end user’s token.

The tools

Plug them into your model

agent/anthropic.ts
The complete programs are in examples/agent.

What the model gets back

Results are plain text written for the model, and bounded, because they go into its context:
  • Completed: the output, up to 256 KiB, with the call that reads the rest (get_run with offset), and the last log lines.
  • Waiting: the run’s id and what it waits for, such as a signal, an approval or a host tool.
  • Failed: the error with its line and code frame, the call that failed, and the trace up to the failure.
  • Refused: the type-checker’s diagnostics, with their code frames.
Mistakes the model can fix (a bad argument, a refused script, a run that has ended, a quota reached) come back as a result with isError. Faults of the platform or of your harness (an unreachable server, a 401, a 5xx, a key’s client that names no namespace) are thrown, for your code to handle. result.run holds the run the call started or read, for your harness: for example, rewind.approvals.pending(result.run) says which calls wait for your approval.

Idempotency

The model’s tool call id becomes the idempotency key of run_script, retry_run and signal_run: handling the same tool call twice (a retry of your harness, a replayed conversation) starts one run, or delivers one signal. The key is derived from the agent’s labels and the id, so agents with different labels never share one.

Labels scope the agent

labels are set on every run the model starts. They filter list_runs, and the tools that take a run id answer for a run without them as for a run that does not exist. Give your harness an API key limited to these labels, or a token carrying them, and the server enforces the scope too.

Options

Workflows the model saves

save_workflow saves a workflow with the agent’s toolset, then derives a toolset that pins it. The later calls of the same agent tools use the derived toolset: agentTools.toolset is its id. If your harness creates the agent tools for each turn, keep agentTools.toolset with the conversation and pass it as toolset the next time. The derived toolset has a new id: a worker started with toolset: <first id> does not claim the tasks of its runs (start it without toolset), and credentials set on the first toolset must be set on the derived one too.