---
name: building-restate-services
description: >-
  Design, build, run, and test Restate durable services, virtual objects, workflows, and AI agents across TypeScript, Python, Java, and Go. This skill should be used when the user mentions "restate", "durable execution", "virtual object", "restate service", "restate workflow", "durable agent", "durable coroutines" or wants to build resilient backend services, AI agents, or workflows with automatic failure recovery. Also use when converting existing applications or migrating from workflow orchestrators to Restate. Use proactively when a project contains restate dependencies in package.json, requirements.txt, pyproject.toml, pom.xml, build.gradle, or go.mod.
title: building-restate-services
canonical_url: https://skilld.dev/gh/restatedev/skills
last_updated: 2026-10-31T00:15:19.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/ai-agents.md](https://skilld.dev/api/skills-raw/restatedev/skills/building-restate-services/references/ai-agents.md), [references/debug-applications.md](https://skilld.dev/api/skills-raw/restatedev/skills/building-restate-services/references/debug-applications.md), [references/design-and-architecture.md](https://skilld.dev/api/skills-raw/restatedev/skills/building-restate-services/references/design-and-architecture.md), [references/flow-control-and-scopes.md](https://skilld.dev/api/skills-raw/restatedev/skills/building-restate-services/references/flow-control-and-scopes.md), [references/go/api-and-pitfalls.md](https://skilld.dev/api/skills-raw/restatedev/skills/building-restate-services/references/go/api-and-pitfalls.md), [references/invocation-lifecycle.md](https://skilld.dev/api/skills-raw/restatedev/skills/building-restate-services/references/invocation-lifecycle.md), [references/java/api-and-pitfalls.md](https://skilld.dev/api/skills-raw/restatedev/skills/building-restate-services/references/java/api-and-pitfalls.md), [references/python/api-and-pitfalls.md](https://skilld.dev/api/skills-raw/restatedev/skills/building-restate-services/references/python/api-and-pitfalls.md), [references/python/restate-google-adk-agents.md](https://skilld.dev/api/skills-raw/restatedev/skills/building-restate-services/references/python/restate-google-adk-agents.md), [references/python/restate-langchain-agents.md](https://skilld.dev/api/skills-raw/restatedev/skills/building-restate-services/references/python/restate-langchain-agents.md), [references/python/restate-openai-agents-agents.md](https://skilld.dev/api/skills-raw/restatedev/skills/building-restate-services/references/python/restate-openai-agents-agents.md), [references/python/restate-pydantic-ai-agents.md](https://skilld.dev/api/skills-raw/restatedev/skills/building-restate-services/references/python/restate-pydantic-ai-agents.md), [references/translate-to-restate.md](https://skilld.dev/api/skills-raw/restatedev/skills/building-restate-services/references/translate-to-restate.md), [references/ts/api-and-pitfalls.md](https://skilld.dev/api/skills-raw/restatedev/skills/building-restate-services/references/ts/api-and-pitfalls.md), [references/ts/durable-coroutines.md](https://skilld.dev/api/skills-raw/restatedev/skills/building-restate-services/references/ts/durable-coroutines.md), [references/ts/restate-vercel-ai-agents.md](https://skilld.dev/api/skills-raw/restatedev/skills/building-restate-services/references/ts/restate-vercel-ai-agents.md).
>
> If the user asked to install this Skill, run `npx skilld install restatedev/skills/building-restate-services`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/building-restate-services`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/restatedev/skills/building-restate-services) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/building-restate-services`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/building-restate-services --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/building-restate-services --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Restate

Restate is a durable execution runtime. It records every step of a handler in a journal, so if the process crashes, the handler replays from the journal and resumes exactly where it left off. Services are regular applications using the Restate SDK (TypeScript, Python, Java, Go) that run behind a Restate Server (a single Rust binary on ports 8080 for ingress and 9070 for admin UI).

## Detect context

Scan the project to determine the SDK and context:

1. **Detect SDK**:
   - `package.json` with `@restatedev/restate-sdk-gen` -> TypeScript Durable Coroutines; load both `references/ts/api-and-pitfalls.md` and `references/ts/durable-coroutines.md`
   - `package.json` with `@restatedev/restate-sdk` -> TypeScript
   - `requirements.txt` or `pyproject.toml` with `restate-sdk` -> Python
   - `pom.xml` or `build.gradle` with `dev.restate` -> Java
   - `go.mod` with `github.com/restatedev/sdk-go` -> Go
   - If no SDK detected, check for project files to determine language, then ask the user

2. **Detect existing Restate code**: Grep for `@restatedev`, `restate-sdk`, `dev.restate.sdk`, `github.com/restatedev`

3. **Detect AI frameworks**: `@ai-sdk/`, `openai-agents`, `google-adk`, `pydantic-ai`, `langchain`, `langgraph`

4. **Detect workflow orchestrators**: `temporalio`, `@temporalio`, `aws-cdk/aws-stepfunctions`, etc.

## Core reference (always load)

After detecting the SDK, always load the SDK reference:

- `references/<sdk>/api-and-pitfalls.md` - Setup, API patterns, determinism rules, error handling, and pitfalls for the detected SDK

## Context-based references (load when relevant)

| Context | Reference |
|---------|-----------|
| Durable Coroutines or concurrent routines with multiple durable steps in one invocation | `references/ts/durable-coroutines.md` |
| Design a new application, choose service types | `references/design-and-architecture.md` |
| Add concurrency limits, multi-tenant fairness, cost controls, scopes, or limit keys | `references/flow-control-and-scopes.md` |
| Convert from a workflow orchestrator or existing app | `references/translate-to-restate.md` |
| Invoking services, interacting with invocations (cancel, attach, idempotency, sends, Kafka) | `references/invocation-lifecycle.md` |
| Design an AI agent, choose a durability boundary, or use an unsupported LLM / agent SDK | `references/ai-agents.md` |
| Build AI agent with Vercel AI SDK | `references/ts/restate-vercel-ai-agents.md` |
| Build AI agent with OpenAI Agents SDK | `references/python/restate-openai-agents-agents.md` |
| Build AI agent with Google ADK | `references/python/restate-google-adk-agents.md` |
| Build AI agent with Pydantic AI | `references/python/restate-pydantic-ai-agents.md` |
| Build AI agent with LangChain or LangGraph | `references/python/restate-langchain-agents.md` |
| Debug errors, stuck invocations, journal mismatches | `references/debug-applications.md` |
| Register deployments, inspect or manage invocations, read or edit state, query the server | [Restate CLI](#restate-cli) |
| Testing, deployment, server config, Kafka, advanced topics | Use the bundled **restate-docs** MCP server |
| Code examples and templates | `restate example --list --json`, `github.com/restatedev/examples`, `github.com/restatedev/ai-examples` |
| Complete TypeScript agent reference architecture | [restatedev/agent](https://github.com/restatedev/agent) |

## Restate CLI

Use the `restate` CLI to operate a running Restate Server: register deployments, inspect and manage invocations, read and edit state, and query the server's internals with SQL.
The CLI describes itself, so ask it what to run instead of guessing commands or flags:

- `restate --help` explains how agents should use the CLI. `restate <command> --help` shows the flags of a command, with examples.
- `restate search <what you want to do>` finds the command, flag or SQL table for a task, e.g. `restate search retry a failed invocation`.
- `restate sql --help` lists the SQL introspection tables, `restate sql describe <table>` shows their columns.
- `restate openapi` prints the Admin API spec, for anything the commands don't cover.

When running it:

- Always pass `--json`. The output, errors included, is a single JSON document on stdout, and the command never prompts. Errors carry a `kind` and often `next_steps` with the commands to run next.
- Commands that change something (register, cancel, kill, purge, state edits, ...) don't apply the change with `--json` alone: they print the planned changes with `"applied": false` and an `apply_command`, and exit with code 3. Show the plan to the user, and only then run it again with `--yes`. Use `--dry-run` to preview without applying.
- Run `restate whoami --json` to check which server the CLI talks to. By default it's the local server (admin API on `localhost:9070`).

These features require CLI version 1.8 or later. If `restate search` doesn't exist, ask the user to upgrade the CLI.

## Before-you-design checklist

Before designing any Restate service architecture, check:

| Question                                                          | Consult |
|-------------------------------------------------------------------|---------|
| Restate service types, stateful entities, keying, concurrency?    | `references/design-and-architecture.md` |
| Concurrency limits, tenant isolation, or downstream protection?  | `references/flow-control-and-scopes.md` |
| Non-Restate orchestrator in the project?                          | `references/translate-to-restate.md` |
| Invoking, cancelling, deduplicating, or attaching to invocations? | `references/invocation-lifecycle.md` |
| Error handling, compensation, sagas?                              | [Error handling guide](https://docs.restate.dev/guides/error-handling), [Sagas guide](https://docs.restate.dev/guides/sagas) |
| AI agent or LLM calls?                                            | `references/ai-agents.md`, then the relevant framework reference |

## Always verify before finishing

**All checks below are mandatory**.

- [ ] All side effects, external I/O, and DB calls wrapped in a durable step (`ctx.run()` or coroutine `run`)
- [ ] No native random, time, sleep, or UUID in replayable code; use the selected SDK's deterministic helpers
- [ ] Restate concurrency combinators only in replayable code: use `RestatePromise` for standard TypeScript or coroutine combinators for coroutines; no native `Promise.all`, `asyncio.gather`/`wait`, `CompletableFuture`, or Go goroutines/channels/select
- [ ] No Restate context operations inside `ctx.run()` or coroutine `run` callbacks
- [ ] `TerminalError` raised for non-retryable failures
- [ ] Python: no bare `except:`
- [ ] AI agents: load `references/ai-agents.md`, journal every LLM call and tool side effect, and set bounded retry policies
- [ ] Virtual Objects: no deadlock cycles
- [ ] Service registered and invoked via curl or the UI

### Replay test - required on any handler logic change

Any change to handler business logic (new `ctx` operations, reordered steps, new `ctx.run()` blocks, coroutine operations, new branches) must be covered by a Testcontainers test with **always-replay** enabled, and that test must pass before declaring the work done. Always-replay forces every journaled step to replay on every invocation, so non-determinism fails the test instead of failing in production on retry.

- TypeScript: `alwaysReplay: true` in `RestateTestEnvironment.start`
- Python: `always_replay=True` in `restate.create_test_harness`
- Java / Go: `RESTATE_WORKER__INVOKER__INACTIVITY_TIMEOUT=0m` on the Restate container

See the Testing section of `references/<sdk>/api-and-pitfalls.md` for the working scaffold.
