Build your own agent loop
Use Outpost’s built-in harness with a model provider, tools and explicit limits.
Choose the built-in loop
Section titled “Choose the built-in loop”Choose the built-in harness when you want to control the agent’s model API, tools and execution rules yourself. The loop runs in your Node.js process, while its tools act in the task’s sandbox.
| CLI agent | Built-in harness | |
|---|---|---|
| Loop runs | In the sandbox, as the CLI process | In your Node.js process |
| Tools | The CLI’s own | Only those you pass to tools |
| Model access | Account login or API key | An API key on a model provider |
| Sandbox image | Contains the CLI, or installs it at startup | No agent CLI to install |
| Control | CLI settings | Permissions, hooks and limits per call, and subagents |
| Usage reporting | Depends on the CLI | After each model response |
Choose an agent compares every capability.
Run a task
Section titled “Run a task”createHarness() configures the loop; createAgent() pairs it with a model. The agent then goes to dispatch() like any other.
Set ANTHROPIC_API_KEY, then run node harness-review.ts. result.text holds the model’s final answer. These tools only read files, so the agent cannot edit the repository.
The loop at a glance
Section titled “The loop at a glance”Outpost checks the limits before every step and after each model response. The first one reached ends the turn with an OutpostError.
Limit a model turn
Section titled “Limit a model turn”limits bounds the loop; toolExecution sets how tool calls run.
API reference: HarnessLimits and HarnessToolExecution.
With the default onError, a failed or expired call goes back to the model as an error result, and the loop continues. usage counts subagents and context summaries, and requires a model provider that reports usage completely.
Dispatch deadlines
Section titled “Dispatch deadlines”deadlineMs and idleMs on dispatch() also bound each harness turn: its total duration, and the silence between loop events. A running tool call pauses the idle timer; toolExecution.deadlineMs bounds it instead. See Limits and cancellation.
Observe the loop
Section titled “Observe the loop”API reference: AgentObservation.
Watch tool calls and model requests while the harness runs. This example enables verbose observation so the callback can inspect the full model request.
tool-output streams command output, correlated with its call by callId. Full model-request and model-response payloads exist only with a verbose observation hub. They hold the whole conversation, and the normal journal leaves them out.
Go further
Section titled “Go further”- Model providersConnect an OpenAI-compatible or Anthropic API.
- ToolsGive the model files, search, edits, Git, a shell or your own tools.
- Permissions and hooksAllow, deny or rewrite tool calls before they run.
- SubagentsDelegate part of a turn to a child agent in the same sandbox.
- Context and skillsKeep the history in bounds and load instructions on demand.
- MCP serversAdd the tools of Model Context Protocol servers.
Limits
Section titled “Limits”- Model access needs an API key, or a keyless local server. CLI account logins do not apply.
- Tool code runs in your process with your permissions. Only what it does through
context.sandboxruns in the sandbox. - Model requests leave from your process, so the sandbox’s network restrictions do not apply to them.
API: createHarness · HarnessOptions · HarnessLimits · HarnessToolExecution · createAgent · createObservationHub.
Route each model step
Section titled “Route each model step”Add an optional routing declaration to select among models of this harness model provider after compaction and before model hooks. Tools and hooks see the selected model while the sandbox and history remain available. See model routing for candidate validation, state, fallback and usage behavior.