Skip to content

Latest commit

 

History

History
50 lines (37 loc) · 2.38 KB

File metadata and controls

50 lines (37 loc) · 2.38 KB

Restate + Vercel AI Example (non-NextJS)

This is template of a simple agent written with the Vercel AI SDK and using Restate for resilience and observability.

This example is for deployments where the agent is served directly, and not as part of a NextJS app. Use this template when deploying the agent on generic containers, FaaS (Lambda, Fly.io, etc.) or for simply experimenting locally.

Running the template example

Check out the AI Quickstart to run this example. s

  1. Export your OpenAI key as an environment variable. If you want to use another model (e.g., Anthrophic Claude, Google Gemini) you need to change the dependencies in package.json and the model in src/app.ts accordingly:

    export OPENAI_API_KEY=your_openai_api_key
  2. Start the Restate Server in a separate shell. The server is the durable orchstrator. It is queue, workflow engine, K/V store in one.

    npx @restatedev/restate-server@latest
  3. Start the agent.

    npm install
    npm run dev
  4. Register the services, to let Restate Server know about the agent. The Server can now proxy invocations to the agent, adding durable execution that way.

    npx @restatedev/restate -y deployments register localhost:9080
  5. All should be ready. Now send a request to your agent. Note that we target Restate Server's endpoint (8080) because the server proxies requests to the service, to make them durable.

    curl localhost:8080/agent/run --json '{"prompt": "What is the weather in San Francisco?"}'

    Returns: The weather in San Francisco is currently 23°C and sunny.

Check the Restate UI (localhost:9080) to see the journals of your invocations.

Using Agent SDK - journal

Limitations

Restate does not allow executing tools in parallel, to avoid non-deterministic behavior on retries/resume. We are working on a solution to this.

Using AI coding tools

If you use Claude Code or Codex, then the Restate plugin will automatically be installed. For Cursor, consult the skills repo README.

Plugin repo: https://github.com/restatedev/skills/tree/main