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

# Restate Harness

> Build durable AI agents in TypeScript with Restate Harness.

Restate Harness (`@restatedev/harness`) is a TypeScript agent harness built on Restate's durable execution.
You define the model, instructions, and tools, then run the agent in a Restate service handler while Restate Harness manages the loop.
Your agents, tools, and workflows share one runtime. They call each other reliably and suspend while they wait for work or human input, and you can inspect their execution in the Restate UI.
Restate Harness is a thin layer over Durable Execution, [Durable Coroutines](https://docs.restate.dev/develop/ts/concurrent-tasks.md#durable-coroutines), [Virtual Objects](https://docs.restate.dev/foundations/services.md#virtual-object), and durable service calls, so you can customize it or use its source to build your own.

## How it works

You define an agent once, at module scope, with `agent()`, and a handler runs it with `yield* agent.run(input)`:

```typescript {"CODE_LOAD::harness/src/agents.ts#overview"}  theme={null}
const assistant = agent({
  model,
  instructions: "Answer support questions briefly.",
  maxSteps: 6,
});

export const support = restate.service({
  name: "Support",
  handlers: {
    *ask(question: string) {
      const result = yield* assistant.run(question);
      if (result.status !== "completed") return result.output ?? result.reason;
      return result.output;
    },
  },
});
```

Each request to `Support/ask` starts a run: a loop of model calls and the tool calls that the model requests.
The handler controls everything around the run, such as where the conversation is stored, who approves tool calls, and what happens with the result.

![HTTP clients, SDK clients, webhooks, and Kafka send requests to the Restate Server, which invokes the handler in your service that runs agent.run(). The handler calls the LLM, tools, and a sandbox.](https://mintcdn.com/restate-6d46e1dc/J41KHZrCBcNnDzQ6/img/harness/harness-architecture.svg?fit=max\&auto=format\&n=J41KHZrCBcNnDzQ6\&q=85\&s=e99963335c5ae7706b3d37ef0a4fe799)

If you interrupt the run or cancel the invocation, Restate Harness cancels the run's unfinished tool calls.

## Features

| Feature | Description |
| - | - |
| [Models](https://docs.restate.dev/harness/models.md) | OpenAI, Anthropic, Amazon Bedrock, Google, and other Vercel AI SDK providers, or your own client. Includes retries, prompt caching, reasoning, and token usage. |
| [Typed output](https://docs.restate.dev/harness/agents.md#typed-output) | Final answers validated against a Zod schema |
| [Tools](https://docs.restate.dev/harness/tools.md) | Async functions with journaled results, and generator functions that compose Restate operations |
| [Restate services as tools](https://docs.restate.dev/harness/service-tools.md) | Handlers of your Restate services that the model calls, each call as a durable invocation |
| [MCP servers](https://docs.restate.dev/harness/mcp.md) | The tools of an MCP server, loaded in a handler |
| [Tool search](https://docs.restate.dev/harness/code-mode.md#tool-search) | Tools that stay hidden until the model searches for them, for large tool catalogs |
| [Code mode](https://docs.restate.dev/harness/code-mode.md) | JavaScript programs that call several tools in a sandbox |
| [Background tools](https://docs.restate.dev/harness/tools.md#background-tools) | Tool calls that run while the model continues |
| [Skills](https://docs.restate.dev/harness/skills.md) | Instructions that the model loads when a task needs them, defined in code or loaded from files |
| [Sandboxes](https://docs.restate.dev/harness/sandboxes.md) | A pattern for tool calls that run in a provider's sandbox, with files that stay across the requests of a session |
| [Sessions](https://docs.restate.dev/harness/sessions.md) | Conversation history per Virtual Object key, stored in chunks |
| [Clients](https://docs.restate.dev/harness/clients.md) | Requests over HTTP or the TypeScript client, results of long runs, and errors |
| [Webhooks](https://docs.restate.dev/harness/webhooks.md) | A pattern for agent runs started by GitHub, Linear, Slack, and other systems that send webhooks |
| [Context and compaction](https://docs.restate.dev/harness/compaction.md) | Summaries, tool result previews, and truncation for long runs and conversations |
| [Human approval](https://docs.restate.dev/harness/human-approval.md) | Tool calls that wait for a person's decision, even days later |
| [Guardrails](https://docs.restate.dev/harness/guardrails.md) | Checks and redaction for input, tool calls, tool output, and answers |
| [Steering and interruption](https://docs.restate.dev/harness/steering.md) | New input for a running agent, or a stop with a summary |
| [Progress and streaming](https://docs.restate.dev/harness/progress-and-streaming.md) | Run events and model text for clients |
| [Agents in workflows](https://docs.restate.dev/harness/workflows.md) | Chains, parallel agents, worker services, routing, review loops, and races in your own code |
| [Sub-agents, handoffs, and forks](https://docs.restate.dev/harness/sub-agents.md) | Agents that the model delegates to, transfers the conversation to, or forks |
| [Limits](https://docs.restate.dev/harness/agents.md#limits) | Maximum steps and tool calls per run, nesting depth, and the size of each reply and output |
| [Error handling](https://docs.restate.dev/harness/error-handling.md) | Errors that the model receives, and errors that fail the run |
| [Testing](https://docs.restate.dev/harness/testing.md) | Fixture models and forced replay against a real Restate Server |

## Key concepts

| Term | Meaning |
| - | - |
| Agent definition | Reusable configuration of a model, instructions, tools, and policies. One definition serves many runs. |
| Run | One execution of an agent, from the input to a completed, stopped, or interrupted result, or to an error. |
| Step | One model call within a run, together with the tool calls that the model requested. |
| Tool call | A request from the model to execute one tool with a specific input. |
| Conversation | The messages accumulated across runs: user messages, assistant messages, and tool calls with their results. |
| Session | A group of runs that share a conversation, usually stored under a [Virtual Object](https://docs.restate.dev/foundations/services.md#virtual-object) key. |
| Invocation | One durable execution of a Restate handler. An invocation can contain several runs. |

## Build with a coding agent

The [Restate plugin](https://docs.restate.dev/develop/ai-assistant.md) adds skills for Restate Harness and the Restate SDKs to your coding agent, and connects the Restate documentation MCP server.

```shell Claude Code theme={null}
/plugin marketplace add restatedev/skills
/plugin install restatedev@restatedev-plugin
```

```shell Codex theme={null}
codex plugin marketplace add restatedev/skills
```

```shell Other agents theme={null}
npx skills add restatedev/skills
```

For Codex and other agents, finish the setup in [Develop with AI](https://docs.restate.dev/develop/ai-assistant.md).

## Next steps

> [card] [Quickstart](https://docs.restate.dev/ai-quickstart.md)
>
> Run a weather agent on a local Restate Server.

> [card] [Tutorial](https://github.com/restatedev/ai-examples/tree/main/restate-harness/examples)
>
> Follow the numbered lessons, from one agent to multi-agent workflows.

> [card] [Agent reference architecture](https://github.com/restatedev/ai-examples/tree/main/restate-harness/reference-architecture)
>
> Explore a complete TypeScript agent with human approvals, sandboxed tools, sub-agents, memory, and schedules.

> [card] [Production checklist](https://docs.restate.dev/harness/production-checklist.md)
>
> Review the settings to change before you run agents in production.


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