LLM prompt — bring your own brain
Use this prompt when you already have a 2wai avatar screen working (any SDK) and now want the avatar to say what YOUR LLM writes: OpenAI, Anthropic, your own fine-tune, a rules engine, anything with a text-in/text-out shape.
The prompt
Section titled “The prompt”Copy, paste, fill {PLACEHOLDERS}:
I've got a working 2wai avatar screen in my app. Now I want the avatar to say exactly what MY OWN LLM writes, instead of letting the avatar's 2wai brain reply.
CONTEXT
2wai calls this verbatim speech. The shape:1. My server creates the session with `"verbatim": true` in the `POST https://api.2wai.ai/v1/sessions` body. The response then has `"verbatim": true` and `chat.say_topic` (`lk.say`) and `chat.say_status_topic` (`lk.say.status`).2. The user types or speaks input. My client sends it to MY server.3. My server passes it to MY LLM and streams the reply back to my client, sentence by sentence.4. My client sends each sentence into the LiveKit room as its own TEXT STREAM on `lk.say`: `room.localParticipant.sendText(sentence, { topic: session.chat.say_topic })`. The avatar speaks each line, in order, with its own voice and lip-sync. There is no REST call per line; `POST /v1/sessions/{id}/speak` answers 409.5. The agent answers on the data topic `lk.say.status` with JSON `{"v":1,"id":"<stream id>","status":"accepted"|"refused"|"done", "reason"?: "...", "interrupted"?: bool}`.
Limits per session: a line is 1 to 2,000 characters; 20 lines a minute; at most 3 lines waiting or playing (more are refused `queue_full`, so wait for a `done`). Every line passes an automated moderation check first; a flagged line is refused `moderation`. 2wai keeps the text of checked lines for at least 30 days (deleted within about a day after) for abuse review.
MY INPUTS
- My LLM provider: {OPENAI / ANTHROPIC / GOOGLE / OPENROUTER / OWN_MODEL}- My LLM API key env var: {MY_LLM_KEY_ENV_NAME}- My existing mint-proxy server stack: {NODE / PYTHON / CLOUDFLARE_WORKER}- My system prompt / persona for the LLM: {ONE_SENTENCE_OR_PASTE_IT_ALL}- My client: {WEB_LIVEKIT_CLIENT / FLUTTER / IOS / ANDROID}
WHAT I NEED YOU TO DO
1. **Mint with verbatim.** In my mint proxy, add `"verbatim": true` to the `POST /v1/sessions` body, and pass `chat.say_topic` and `chat.say_status_topic` through to the client. Handle `403 verbatim_not_enabled` with a clear message (this avatar is not enabled for verbatim speech).
2. **Add a `POST /api/chat` route** to my server. It takes `{text}` from the client, calls my LLM with streaming, and streams the reply back to the client (server-sent events or chunked JSON lines), cut at sentence boundaries. Node example:
```ts import OpenAI from 'openai'; // or @anthropic-ai/sdk const llm = new OpenAI({ apiKey: process.env.{MY_LLM_KEY_ENV_NAME} });
app.post('/api/chat', async (req, res) => { res.setHeader('Content-Type', 'text/event-stream'); const stream = await llm.chat.completions.create({ model: '<your-model>', messages: [ { role: 'system', content: `{MY_SYSTEM_PROMPT}` }, { role: 'user', content: req.body.text }, ], stream: true, }); let buffer = ''; for await (const chunk of stream) { buffer += chunk.choices[0]?.delta?.content ?? ''; const sentences = buffer.match(/[^.!?]+[.!?]+/g) || []; for (const s of sentences) { res.write(`data: ${JSON.stringify({ line: s.trim() })}\n\n`); buffer = buffer.slice(s.length).trimStart(); } } if (buffer.trim()) res.write(`data: ${JSON.stringify({ line: buffer.trim() })}\n\n`); res.end(); }); ```
3. **On the client**, read each `line` from `/api/chat` and send it on the room:
```ts await room.localParticipant.sendText(line, { topic: session.chat.say_topic }); ```
Listen for `RoomEvent.DataReceived` on `session.chat.say_status_topic`. Keep at most 3 lines outstanding: after a third `accepted`, wait for a `done` before sending the next. Show a gentle error for `refused` (`moderation`, `rate_limited`, `queue_full`, ...).
4. **Verify**: - The avatar screen loads and the agent appears. Wait for it before sending the first line. - Ask a long question (a short poem). The avatar starts speaking within about 2 s, not after the LLM finishes. - Each line arrives back as `accepted`, then `done`, and its text appears on `lk.transcription`. - A refused line shows the reason and doesn't break the conversation.
GOTCHAS TO HONOR
- **One text stream per line.** Don't send each token; send whole sentences (roughly 5 to 40 words). Lines are spoken in the order sent.- **The 2wai brain never sees these lines.** If I also send turns on `lk.chat` in the same session, the avatar's own brain replies to those and will not remember my `lk.say` lines; a turn on `lk.chat` also interrupts the avatar. For a pure bring-your-own-brain app, don't use `lk.chat`.- **One session per conversation.** Don't call `/v1/sessions` on each user turn. End it with `DELETE /v1/sessions/{id}` when the user leaves.- **TWAI_SECRET_KEY stays server-side.** The client only ever holds the LiveKit `participant_token`.
DELIVERABLE
- `verbatim: true` in the mint proxy, with the say topics passed to the client.- One new server route (`/api/chat`) streaming sentences.- Client code that sends each sentence on `lk.say` and handles `lk.say.status`.- One-line README note on which LLM provider and model I'm using.
If you need anything (which LLM I'm actually using, my system prompt, whether I want the reply shown as text alongside the avatar), ASK.
Reference docs:- https://developers.2wai.ai/guides/bring-your-own-brain/- https://developers.2wai.ai/guides/latency/