examples/ai-generated-actor/README.md
Use an AI chat to generate and iterate on Rivet Actor code, then deploy and test it live.
git clone https://github.com/rivet-dev/rivet.git
cd rivet/examples/ai-generated-actor
pnpm install
pnpm dev
OPENAI_API_KEYsecure-exec package is present. This example uses the secure-exec package from pkg.pr.new.RIVETKIT_DYNAMIC_SECURE_EXEC_SPECIFIER to a resolvable secure-exec entry file URL.dynamicActor from rivetkit/dynamicThe project uses two actors defined in src/actors.ts:
codeAgent maintains chat history and generated code in actor state. It processes messages via a queue and streams AI responses using the Vercel AI SDK, extracting code blocks from the response to update the current actor source.dynamicRunner is a dynamic actor that loads its source code from the codeAgent with the matching key, executing the AI-generated code in a sandboxed isolate.The server in src/server.ts exposes proxy endpoints for calling actions on the dynamic actor by name.
The frontend in frontend/App.tsx provides a three-column interface for chatting with the AI, viewing generated code, and testing the deployed actor.
Read more about dynamic actors, queues, events, and state.
MIT